-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11854 from Graylog2/geoip-processor-update
Geoip processor update
- Loading branch information
Showing
29 changed files
with
1,534 additions
and
211 deletions.
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
39 changes: 39 additions & 0 deletions
39
graylog2-server/src/main/java/org/graylog/plugins/map/config/DatabaseVendorType.java
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
|
||
package org.graylog.plugins.map.config; | ||
|
||
public enum DatabaseVendorType { | ||
MAXMIND(DatabaseType.MAXMIND_CITY, DatabaseType.MAXMIND_ASN), | ||
IPINFO(DatabaseType.IPINFO_STANDARD_LOCATION, DatabaseType.IPINFO_ASN); | ||
|
||
private final DatabaseType cityDbType; | ||
private final DatabaseType asnDbType; | ||
|
||
DatabaseVendorType(DatabaseType cityDbType, DatabaseType asnDbType) { | ||
this.cityDbType = cityDbType; | ||
this.asnDbType = asnDbType; | ||
} | ||
|
||
public DatabaseType getCityDbType() { | ||
return cityDbType; | ||
} | ||
|
||
public DatabaseType getAsnDbType() { | ||
return asnDbType; | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
graylog2-server/src/main/java/org/graylog/plugins/map/geoip/GeoAsnInformation.java
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
|
||
package org.graylog.plugins.map.geoip; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
@AutoValue | ||
public abstract class GeoAsnInformation { | ||
|
||
public abstract String organization(); | ||
|
||
public abstract String type(); | ||
|
||
public abstract String asn(); | ||
|
||
public static GeoAsnInformation create(String organization, String type, String asn) { | ||
return new AutoValue_GeoAsnInformation(organization, type, asn); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
graylog2-server/src/main/java/org/graylog/plugins/map/geoip/GeoIpResolver.java
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
|
||
package org.graylog.plugins.map.geoip; | ||
|
||
import com.codahale.metrics.Timer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.net.InetAddress; | ||
import java.nio.file.Files; | ||
import java.util.Optional; | ||
|
||
public abstract class GeoIpResolver<V> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(GeoIpResolver.class); | ||
|
||
protected String lastError = null; | ||
protected final Timer resolveTime; | ||
private final boolean enabled; | ||
|
||
GeoIpResolver(Timer resolveTime, String configPath, boolean enabled) { | ||
|
||
this.resolveTime = resolveTime; | ||
if (enabled) { | ||
final File configFile = new File(configPath); | ||
if (Files.exists(configFile.toPath())) { | ||
this.enabled = createDataProvider(configFile); | ||
} else { | ||
LOG.warn("'{}' database file does not exist: {}", getClass().getName(), configPath); | ||
this.enabled = false; | ||
} | ||
} else { | ||
this.enabled = false; | ||
} | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
abstract boolean createDataProvider(File configFile); | ||
|
||
public Optional<V> getGeoIpData(InetAddress address) { | ||
lastError = null; | ||
if (!enabled || address == null) { | ||
return Optional.empty(); | ||
} | ||
return doGetGeoIpData(address); | ||
} | ||
|
||
/** | ||
* Get the last error, if any, produced after having called {@link #getGeoIpData(InetAddress)}. | ||
* | ||
* @return optional error message | ||
*/ | ||
public Optional<String> getLastError() { | ||
return Optional.ofNullable(lastError); | ||
} | ||
|
||
protected abstract Optional<V> doGetGeoIpData(InetAddress address); | ||
} |
Oops, something went wrong.