Skip to content

Commit 6985f18

Browse files
author
Mincheol Kim
committed
fix: missing network field in output (city, isp, anonymous)
1 parent c2f432f commit 6985f18

File tree

5 files changed

+34
-12
lines changed

5 files changed

+34
-12
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.3.1
1+
7.3.2

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ group "org.logstash.filters"
4141
version "${new File("VERSION").text.trim()}"
4242

4343
String junitVersion = '5.11.2' // at least 5.11 is needed to use @FieldSource with @ParameterizedTest
44-
String maxmindGeoip2Version = '2.17.0'
45-
String maxmindDbVersion = '2.1.0'
44+
String maxmindGeoip2Version = '4.2.0'
45+
String maxmindDbVersion = '3.1.1'
4646
String log4jVersion = '2.17.1'
4747
String jrubyCompleteVersion = '9.1.13.0'
4848
String mockitoVersion = '4.11.0'

logstash-filter-geoip.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
1414
s.require_paths = ["lib", "vendor/jar-dependencies"]
1515

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

1919
# Tests
2020
s.test_files = s.files.grep(%r{^(test|spec|features)/})

src/main/java/org/logstash/filters/geoip/Database.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ enum Database {
2222
Field.TIMEZONE,
2323
Field.LOCATION,
2424
Field.LATITUDE,
25-
Field.LONGITUDE
25+
Field.LONGITUDE,
26+
Field.NETWORK
2627
)
2728
),
2829
COUNTRY(
@@ -31,7 +32,8 @@ enum Database {
3132
Field.IP,
3233
Field.COUNTRY_CODE2,
3334
Field.COUNTRY_NAME,
34-
Field.CONTINENT_NAME
35+
Field.CONTINENT_NAME,
36+
Field.NETWORK
3537
)
3638
),
3739
DOMAIN(
@@ -55,7 +57,8 @@ enum Database {
5557
Field.AUTONOMOUS_SYSTEM_NUMBER,
5658
Field.AUTONOMOUS_SYSTEM_ORGANIZATION,
5759
Field.ISP,
58-
Field.ORGANIZATION
60+
Field.ORGANIZATION,
61+
Field.NETWORK
5962
)
6063
),
6164
ANONYMOUS_IP(
@@ -66,7 +69,8 @@ enum Database {
6669
Field.ANONYMOUS_VPN,
6770
Field.ANONYMOUS,
6871
Field.PUBLIC_PROXY,
69-
Field.RESIDENTIAL_PROXY
72+
Field.RESIDENTIAL_PROXY,
73+
Field.NETWORK
7074
)
7175
),
7276
ENTERPRISE(
@@ -122,4 +126,4 @@ public static Database fromDatabaseType(final String type) {
122126
// database type.
123127
return Database.UNKNOWN;
124128
}
125-
}
129+
}

src/main/java/org/logstash/filters/geoip/GeoIPFilter.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ private Map<Field,Object> retrieveCityGeoData(InetAddress ipAddress) throws GeoI
246246
Postal postal = response.getPostal();
247247
Subdivision subdivision = response.getMostSpecificSubdivision();
248248
Map<Field, Object> geoData = new EnumMap<>(Field.class);
249+
Network network = response.getTraits().getNetwork();
249250

250251
// if location is empty, there is no point populating geo data
251252
// and most likely all other fields are empty as well
@@ -344,6 +345,11 @@ private Map<Field,Object> retrieveCityGeoData(InetAddress ipAddress) throws GeoI
344345
geoData.put(Field.LONGITUDE, lon);
345346
}
346347
break;
348+
case NETWORK:
349+
if (network != null) {
350+
geoData.put(Field.NETWORK, network.toString());
351+
}
352+
break;
347353
}
348354
}
349355

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

401408
Map<Field, Object> geoData = new EnumMap<>(Field.class);
402409
for (Field desiredField : this.desiredFields) {
@@ -405,7 +412,7 @@ private Map<Field, Object> retrieveIspGeoData(InetAddress ipAddress) throws GeoI
405412
geoData.put(Field.IP, ipAddress.getHostAddress());
406413
break;
407414
case AUTONOMOUS_SYSTEM_NUMBER:
408-
Integer asn = response.getAutonomousSystemNumber();
415+
Long asn = response.getAutonomousSystemNumber();
409416
if (asn != null) {
410417
geoData.put(desiredField, asn);
411418
}
@@ -428,6 +435,11 @@ private Map<Field, Object> retrieveIspGeoData(InetAddress ipAddress) throws GeoI
428435
geoData.put(Field.ORGANIZATION, org);
429436
}
430437
break;
438+
case NETWORK:
439+
if (network != null) {
440+
geoData.put(Field.NETWORK, network.toString());
441+
}
442+
break;
431443
}
432444
}
433445

@@ -450,7 +462,7 @@ private Map<Field, Object> retrieveAsnGeoData(InetAddress ipAddress) throws GeoI
450462
geoData.put(Field.IP, ipAddress.getHostAddress());
451463
break;
452464
case AUTONOMOUS_SYSTEM_NUMBER:
453-
Integer asn = response.getAutonomousSystemNumber();
465+
Long asn = response.getAutonomousSystemNumber();
454466
if (asn != null) {
455467
geoData.put(Field.AUTONOMOUS_SYSTEM_NUMBER, asn);
456468
}
@@ -507,7 +519,7 @@ private Map<Field, Object> retrieveEnterpriseGeoData(InetAddress ipAddress) thro
507519
Continent continent = response.getContinent();
508520
Subdivision subdivision = response.getMostSpecificSubdivision();
509521

510-
Integer asn = response.getTraits().getAutonomousSystemNumber();
522+
Long asn = response.getTraits().getAutonomousSystemNumber();
511523
String organizationName = response.getTraits().getAutonomousSystemOrganization();
512524
Network network = response.getTraits().getNetwork();
513525

@@ -620,6 +632,7 @@ private Map<Field, Object> retrieveAnonymousIpGeoData(final InetAddress ipAddres
620632
boolean isAnonymous = response.isAnonymous();
621633
boolean isPublicProxy = response.isPublicProxy();
622634
boolean isResidentialProxy = response.isResidentialProxy();
635+
Network network = response.getNetwork();
623636

624637
for (Field desiredField : this.desiredFields) {
625638
switch (desiredField) {
@@ -644,6 +657,11 @@ private Map<Field, Object> retrieveAnonymousIpGeoData(final InetAddress ipAddres
644657
case RESIDENTIAL_PROXY:
645658
geoData.put(desiredField, isResidentialProxy);
646659
break;
660+
case NETWORK:
661+
if (network != null) {
662+
geoData.put(Field.NETWORK, network.toString());
663+
}
664+
break;
647665
}
648666
}
649667
return geoData;

0 commit comments

Comments
 (0)