Skip to content

fix: missing network field in output (city, isp, anonymous) #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.3.1
7.3.2
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ group "org.logstash.filters"
version "${new File("VERSION").text.trim()}"

String junitVersion = '5.11.2' // at least 5.11 is needed to use @FieldSource with @ParameterizedTest
String maxmindGeoip2Version = '2.17.0'
String maxmindDbVersion = '2.1.0'
String maxmindGeoip2Version = '4.2.0'
String maxmindDbVersion = '3.1.1'
String log4jVersion = '2.17.1'
String jrubyCompleteVersion = '9.1.13.0'
String mockitoVersion = '4.11.0'
Expand Down
2 changes: 1 addition & 1 deletion logstash-filter-geoip.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib", "vendor/jar-dependencies"]

# Files
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*', 'vendor/jar-dependencies/**/*.jar', '*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT', 'maxmind-db-NOTICE.txt', 'docs/**/*']
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*', 'vendor/jar-dependencies/**/*.jar', '*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT', 'maxmind-db-NOTICE.txt', 'docs/**/*', 'VERSION']

# Tests
s.test_files = s.files.grep(%r{^(test|spec|features)/})
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/logstash/filters/geoip/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ enum Database {
Field.TIMEZONE,
Field.LOCATION,
Field.LATITUDE,
Field.LONGITUDE
Field.LONGITUDE,
Field.NETWORK
)
),
COUNTRY(
Expand All @@ -31,7 +32,8 @@ enum Database {
Field.IP,
Field.COUNTRY_CODE2,
Field.COUNTRY_NAME,
Field.CONTINENT_NAME
Field.CONTINENT_NAME,
Field.NETWORK
)
),
DOMAIN(
Expand All @@ -55,7 +57,8 @@ enum Database {
Field.AUTONOMOUS_SYSTEM_NUMBER,
Field.AUTONOMOUS_SYSTEM_ORGANIZATION,
Field.ISP,
Field.ORGANIZATION
Field.ORGANIZATION,
Field.NETWORK
)
),
ANONYMOUS_IP(
Expand All @@ -66,7 +69,8 @@ enum Database {
Field.ANONYMOUS_VPN,
Field.ANONYMOUS,
Field.PUBLIC_PROXY,
Field.RESIDENTIAL_PROXY
Field.RESIDENTIAL_PROXY,
Field.NETWORK
)
),
ENTERPRISE(
Expand Down Expand Up @@ -122,4 +126,4 @@ public static Database fromDatabaseType(final String type) {
// database type.
return Database.UNKNOWN;
}
}
}
24 changes: 21 additions & 3 deletions src/main/java/org/logstash/filters/geoip/GeoIPFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private Map<Field,Object> retrieveCityGeoData(InetAddress ipAddress) throws GeoI
Postal postal = response.getPostal();
Subdivision subdivision = response.getMostSpecificSubdivision();
Map<Field, Object> geoData = new EnumMap<>(Field.class);
Network network = response.getTraits().getNetwork();

// if location is empty, there is no point populating geo data
// and most likely all other fields are empty as well
Expand Down Expand Up @@ -344,6 +345,11 @@ private Map<Field,Object> retrieveCityGeoData(InetAddress ipAddress) throws GeoI
geoData.put(Field.LONGITUDE, lon);
}
break;
case NETWORK:
if (network != null) {
geoData.put(Field.NETWORK, network.toString());
}
break;
}
}

Expand Down Expand Up @@ -397,6 +403,7 @@ private Map<Field, Object> retrieveIspGeoData(InetAddress ipAddress) throws GeoI
} catch (NullPointerException e) {
throw new GeoIp2InvalidCustomFieldException(e);
}
Network network = response.getNetwork();

Map<Field, Object> geoData = new EnumMap<>(Field.class);
for (Field desiredField : this.desiredFields) {
Expand All @@ -405,7 +412,7 @@ private Map<Field, Object> retrieveIspGeoData(InetAddress ipAddress) throws GeoI
geoData.put(Field.IP, ipAddress.getHostAddress());
break;
case AUTONOMOUS_SYSTEM_NUMBER:
Integer asn = response.getAutonomousSystemNumber();
Long asn = response.getAutonomousSystemNumber();
if (asn != null) {
geoData.put(desiredField, asn);
}
Expand All @@ -428,6 +435,11 @@ private Map<Field, Object> retrieveIspGeoData(InetAddress ipAddress) throws GeoI
geoData.put(Field.ORGANIZATION, org);
}
break;
case NETWORK:
if (network != null) {
geoData.put(Field.NETWORK, network.toString());
}
break;
}
}

Expand All @@ -450,7 +462,7 @@ private Map<Field, Object> retrieveAsnGeoData(InetAddress ipAddress) throws GeoI
geoData.put(Field.IP, ipAddress.getHostAddress());
break;
case AUTONOMOUS_SYSTEM_NUMBER:
Integer asn = response.getAutonomousSystemNumber();
Long asn = response.getAutonomousSystemNumber();
if (asn != null) {
geoData.put(Field.AUTONOMOUS_SYSTEM_NUMBER, asn);
}
Expand Down Expand Up @@ -507,7 +519,7 @@ private Map<Field, Object> retrieveEnterpriseGeoData(InetAddress ipAddress) thro
Continent continent = response.getContinent();
Subdivision subdivision = response.getMostSpecificSubdivision();

Integer asn = response.getTraits().getAutonomousSystemNumber();
Long asn = response.getTraits().getAutonomousSystemNumber();
String organizationName = response.getTraits().getAutonomousSystemOrganization();
Network network = response.getTraits().getNetwork();

Expand Down Expand Up @@ -620,6 +632,7 @@ private Map<Field, Object> retrieveAnonymousIpGeoData(final InetAddress ipAddres
boolean isAnonymous = response.isAnonymous();
boolean isPublicProxy = response.isPublicProxy();
boolean isResidentialProxy = response.isResidentialProxy();
Network network = response.getNetwork();

for (Field desiredField : this.desiredFields) {
switch (desiredField) {
Expand All @@ -644,6 +657,11 @@ private Map<Field, Object> retrieveAnonymousIpGeoData(final InetAddress ipAddres
case RESIDENTIAL_PROXY:
geoData.put(desiredField, isResidentialProxy);
break;
case NETWORK:
if (network != null) {
geoData.put(Field.NETWORK, network.toString());
}
break;
}
}
return geoData;
Expand Down