-
Notifications
You must be signed in to change notification settings - Fork 80
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
Add support for GeoIP2 anonymous database #141
Open
mdevreugd
wants to merge
4
commits into
logstash-plugins:main
Choose a base branch
from
mdevreugd:master
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import com.maxmind.geoip2.model.CityResponse; | ||
import com.maxmind.geoip2.model.CountryResponse; | ||
import com.maxmind.geoip2.model.IspResponse; | ||
import com.maxmind.geoip2.model.AnonymousIpResponse; | ||
import com.maxmind.geoip2.record.*; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
@@ -56,6 +57,7 @@ public class GeoIPFilter { | |
private static final String CITY_SOUTH_AMERICA_DB_TYPE = "GeoIP2-City-South-America"; | ||
private static final String COUNTRY_DB_TYPE = "GeoIP2-Country"; | ||
private static final String ISP_DB_TYPE = "GeoIP2-ISP"; | ||
private static final String ANONYMOUS_DB_TYPE = "GeoIP2-Anonymous-IP"; | ||
|
||
private final String sourceField; | ||
private final String targetField; | ||
|
@@ -99,6 +101,9 @@ private Set<Fields> createDesiredFields(List<String> fields) { | |
case ASN_LITE_DB_TYPE: | ||
desiredFields = Fields.DEFAULT_ASN_LITE_FIELDS; | ||
break; | ||
case ANONYMOUS_DB_TYPE: | ||
desiredFields = Fields.DEFAULT_ANONYMOUS_FIELDS; | ||
break; | ||
} | ||
} else { | ||
for (String fieldName : fields) { | ||
|
@@ -153,6 +158,8 @@ public boolean handleEvent(RubyEvent rubyEvent) { | |
case ISP_DB_TYPE: | ||
geoData = retrieveIspGeoData(ipAddress); | ||
break; | ||
case ANONYMOUS_DB_TYPE: | ||
geoData = retrieveAnonymousData(ipAddress); | ||
default: | ||
throw new IllegalStateException("Unsupported database type " + databaseReader.getMetadata().getDatabaseType() + ""); | ||
} | ||
|
@@ -401,4 +408,48 @@ private Map<String, Object> retrieveAsnGeoData(InetAddress ipAddress) throws Geo | |
|
||
return geoData; | ||
} | ||
|
||
private Map<String, Object> retrieveAnonymousData(InetAddress ipAddress) throws GeoIp2Exception, IOException { | ||
AnonymousIpResponse response = databaseReader.anonymousIp(ipAddress); | ||
Map<String, Object> geoData = new HashMap<>(); | ||
for (Fields desiredField : this.desiredFields) { | ||
switch (desiredField) { | ||
case IP: | ||
geoData.put(Fields.IP.fieldName(), ipAddress.getHostAddress()); | ||
break; | ||
case ANONYMOUS_IS_ANONYMOUS: | ||
Boolean is_anonoymous = response.isAnonymous(); | ||
if (is_anonoymous != null) { | ||
geoData.put(Fields.ANONYMOUS_IS_ANONYMOUS.fieldName(), is_anonoymous); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think there is a typo on "is_anonymous" . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
break; | ||
case ANONYMOUS_IS_VPN: | ||
Boolean is_vpn = response.isAnonymousVpn(); | ||
if (is_vpn != null) { | ||
geoData.put(Fields.ANONYMOUS_IS_VPN.fieldName(), is_vpn); | ||
} | ||
break; | ||
case ANONYMOUS_IS_HOSTING_PROVIDER: | ||
Boolean is_hosting_provider = response.isHostingProvider(); | ||
if (is_hosting_provider != null) { | ||
geoData.put(Fields.ANONYMOUS_IS_HOSTING_PROVIDER.fieldName(), is_hosting_provider); | ||
} | ||
break; | ||
case ANONYMOUS_IS_PUBLIC_PROXY: | ||
Boolean is_public_proxy = response.isPublicProxy(); | ||
if (is_public_proxy != null) { | ||
geoData.put(Fields.ANONYMOUS_IS_PUBLIC_PROXY.fieldName(), is_public_proxy); | ||
} | ||
break; | ||
case ANONYMOUS_IS_TOR_EXIT_NODE: | ||
Boolean is_tor_exit_node = response.isTorExitNode(); | ||
if (is_tor_exit_node != null) { | ||
geoData.put(Fields.ANONYMOUS_IS_TOR_EXIT_NODE.fieldName(), is_tor_exit_node); | ||
} | ||
break; | ||
} | ||
} | ||
|
||
return geoData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think there is a typo on "is_anonymous" .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍