I am trying to create my own database for the internal network using PerM Writer from MaxMind, which still works. Then I will try to bind these IP ranges using the geoid filter plugin in logstash. I can verify that the created database contains my data correctly using a perl script that uses MaxMind Reader.
use strict;
use warnings;
use feature qw( say );
use local::lib 'local';
use MaxMind::DB::Writer::Tree;
use Net::Works::Network;
my $filename = 'test.mmdb';
my %types = (
geoname_id => 'uint32',
locale_code => 'utf8_string',
continent_code => 'utf8_string',
continent_name => 'utf8_string',
country_iso_code => 'utf8_string',
country_name => 'utf8_string',
subdivision_1_iso_code => 'utf8_string',
subdivision_1_name => 'utf8_string',
city_name => 'utf8_string',
metro_code => 'uint32',
time_zone => 'utf8_string',
postal_code => 'utf8_string',
latitude => 'double',
longitude => 'double',
);
my $tree = MaxMind::DB::Writer::Tree->new(
database_type => 'GeoIP2-City',
description => { en => 'IP-Ranges', de => q{IP-Bereiche}, },
ip_version => 4,
map_key_type_callback => sub { $types{ $_[0] } },
record_size => 24,
remove_reserved_networks => 0,
);
my %address_for_employee = (
'xx.xx.xx.xx/24' => {
geoname_id => 3164699,
locale_code => 'de',
continent_code => 'EU',
continent_name => 'Europa',
country_iso_code => 'IT',
country_name => 'Italien',
subdivision_1_iso_code => '09',
city_name => 'Varese',
time_zone => 'Europe/Rome',
postal_code => '21100',
latitude => 45.7908,
longitude => 8.8515,
},
'xx.xx.xx.xx/24' => {
geoname_id => 3164699,
locale_code => 'de',
continent_code => 'EU',
continent_name => 'Europa',
country_iso_code => 'IT',
country_name => 'Italien',
subdivision_1_iso_code => '09',
city_name => 'Varese',
time_zone => 'Europe/Rome',
postal_code => '21100',
latitude => 45.7908,
longitude => 8.8515,
},
);
for my $address ( keys %address_for_employee ) {
my $network = Net::Works::Network->new_from_string( string => $address );
$tree->insert_network( $network, $address_for_employee{$address} );
say "Created Subnet from ___ $network ===> $address ___";
}
open my $fh, '>:raw', $filename;
$tree->write_tree( $fh );
close $fh;
say "$filename has now been created";
Logstash Filter Configuration:
filter {
geoip {
source => "src_ip"
target => "src_ip_geo"
database => "test.mmdb"
add_field => [ "[src_ip_geo][coordinates]", "%{[src_ip_geo][longitude]}" ]
add_field => [ "[src_ip_geo][coordinates]", "%{[src_ip_geo][latitude]}" ]
}
mutate {
convert => [ "[geoip][coordinates]", "float"]
}
}
MaxMind GeoLiteCity.dat, , , IP-, .
, elasticsearch, , : _geoip_lookup_failure
, .
output { stdout{ codec => "json" } }
, json, elasticsearch. ?