mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 09:28:27 +00:00
Port support for commercial GeoIP2 databases from Logstash. (#24889)
* Port support for commercial GeoIP2 databases from Logstash. * Match GeoIP databases according to the database name suffix. * Rename CITY/COUNTRY_DB_TYPE, since they are suffixes now.
This commit is contained in:
parent
d181761aeb
commit
82897e2636
@ -57,8 +57,8 @@ import static org.elasticsearch.ingest.ConfigurationUtils.readStringProperty;
|
||||
public final class GeoIpProcessor extends AbstractProcessor {
|
||||
|
||||
public static final String TYPE = "geoip";
|
||||
private static final String CITY_DB_TYPE = "GeoLite2-City";
|
||||
private static final String COUNTRY_DB_TYPE = "GeoLite2-Country";
|
||||
private static final String CITY_DB_SUFFIX = "-City";
|
||||
private static final String COUNTRY_DB_SUFFIX = "-Country";
|
||||
|
||||
private final String field;
|
||||
private final String targetField;
|
||||
@ -93,24 +93,23 @@ public final class GeoIpProcessor extends AbstractProcessor {
|
||||
final InetAddress ipAddress = InetAddresses.forString(ip);
|
||||
|
||||
Map<String, Object> geoData;
|
||||
switch (dbReader.getMetadata().getDatabaseType()) {
|
||||
case CITY_DB_TYPE:
|
||||
try {
|
||||
geoData = retrieveCityGeoData(ipAddress);
|
||||
} catch (AddressNotFoundRuntimeException e) {
|
||||
geoData = Collections.emptyMap();
|
||||
}
|
||||
break;
|
||||
case COUNTRY_DB_TYPE:
|
||||
try {
|
||||
geoData = retrieveCountryGeoData(ipAddress);
|
||||
} catch (AddressNotFoundRuntimeException e) {
|
||||
geoData = Collections.emptyMap();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new ElasticsearchParseException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType()
|
||||
+ "]", new IllegalStateException());
|
||||
String databaseType = dbReader.getMetadata().getDatabaseType();
|
||||
|
||||
if (databaseType.endsWith(CITY_DB_SUFFIX)) {
|
||||
try {
|
||||
geoData = retrieveCityGeoData(ipAddress);
|
||||
} catch (AddressNotFoundRuntimeException e) {
|
||||
geoData = Collections.emptyMap();
|
||||
}
|
||||
} else if (databaseType.endsWith(COUNTRY_DB_SUFFIX)) {
|
||||
try {
|
||||
geoData = retrieveCountryGeoData(ipAddress);
|
||||
} catch (AddressNotFoundRuntimeException e) {
|
||||
geoData = Collections.emptyMap();
|
||||
}
|
||||
} else {
|
||||
throw new ElasticsearchParseException("Unsupported database type [" + dbReader.getMetadata().getDatabaseType()
|
||||
+ "]", new IllegalStateException());
|
||||
}
|
||||
if (geoData.isEmpty() == false) {
|
||||
ingestDocument.setFieldValue(targetField, geoData);
|
||||
@ -299,9 +298,9 @@ public final class GeoIpProcessor extends AbstractProcessor {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (CITY_DB_TYPE.equals(databaseType)) {
|
||||
if (databaseType.endsWith(CITY_DB_SUFFIX)) {
|
||||
properties = DEFAULT_CITY_PROPERTIES;
|
||||
} else if (COUNTRY_DB_TYPE.equals(databaseType)) {
|
||||
} else if (databaseType.endsWith(COUNTRY_DB_SUFFIX)) {
|
||||
properties = DEFAULT_COUNTRY_PROPERTIES;
|
||||
} else {
|
||||
throw newConfigurationException(TYPE, processorTag, "database_file", "Unsupported database type ["
|
||||
@ -340,9 +339,9 @@ public final class GeoIpProcessor extends AbstractProcessor {
|
||||
|
||||
public static Property parseProperty(String databaseType, String value) {
|
||||
Set<Property> validProperties = EnumSet.noneOf(Property.class);
|
||||
if (CITY_DB_TYPE.equals(databaseType)) {
|
||||
if (databaseType.endsWith(CITY_DB_SUFFIX)) {
|
||||
validProperties = ALL_CITY_PROPERTIES;
|
||||
} else if (COUNTRY_DB_TYPE.equals(databaseType)) {
|
||||
} else if (databaseType.endsWith(COUNTRY_DB_SUFFIX)) {
|
||||
validProperties = ALL_COUNTRY_PROPERTIES;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user