I’m trying to create a pipeline rule to have the following information
src_ip_geo_country_code from a postfix log coming from an udp syslog, where I already applied an extractor for the ip field, but the rule does not work and does not create this field, would anyone help me?
Log example:
Server postfix/smtpd[125]: lost connection after AUTH from PC25[192.168.40.12]
Rule Pipeline:
rule “GeoIP lookup: src_ip”
when
has_field(“message”)
then
let geo = lookup(“geoip-lookup”, to_string($message.ip));
set_field(“src_ip_geo_location”, geo[“coordinates”]);
set_field(“src_ip_geo_country_code”, geo[“country”].iso_code);
set_field(“src_ip_geo_country”, geo[“country”].iso_code);
end
Extractor configuration
Source field: client
Store as field: ip
Regular expression: ((?:\d{1,3}.){3}\d{1,3})
First don’t try to use GeoIP for local (LAN) IP addresses, it can’t work. GeoIP works only for Internet IP addresses.
Better condition is to use field with ip and not message. has_field("ip")
You use same function geo[“country”].iso_code in 2 fields, it’s probably a typo.
Try to debug, if condition works by putting debug function in body:
let debug_message = concat("GeoIP from IP ", to_string($message.ip));
debug(debug_message);
Thank you very much for the feedback, I made the change to search by ip that you suggested and called the debug, however this error came back, you know what could be?
" 2020-07-10T10:47:12.558-03:00 WARN [MaxmindDataAdapter] Unable to look up country data for IP address /189.14.204.248, returning empty result.
java.lang.UnsupportedOperationException: Invalid attempt to open a GeoLite2-City database using the country method
bash: 2020-07-10T10:47:12.558-03:00: command not found…"
The pipeline configuration looks like this
rule “GeoIP lookup: src_ip”
when
has_field(“ip”)
then
let geo = lookup(“geoip-lookup”, to_string($message.ip));
let debug_message = concat("GeoIP from IP ", to_string($message.ip));
set_field(“src_ip_geo_location”, geo[“coordinates”]);
set_field(“src_ip_geo_country_code”, geo[“country”].iso_code);
set_field(“src_ip_geo_city”, geo[“city”].names.en);
end