|
17 | 17 | import com.maxmind.geoip2.record.Country;
|
18 | 18 | import com.maxmind.geoip2.record.Location;
|
19 | 19 | import com.maxmind.geoip2.record.Subdivision;
|
| 20 | + |
20 | 21 | import org.elasticsearch.ElasticsearchParseException;
|
21 | 22 | import org.elasticsearch.ResourceNotFoundException;
|
22 | 23 | import org.elasticsearch.cluster.ClusterState;
|
23 | 24 | import org.elasticsearch.cluster.service.ClusterService;
|
24 | 25 | import org.elasticsearch.common.CheckedSupplier;
|
| 26 | +import org.elasticsearch.common.logging.HeaderWarning; |
25 | 27 | import org.elasticsearch.common.network.InetAddresses;
|
26 | 28 | import org.elasticsearch.common.network.NetworkAddress;
|
27 | 29 | import org.elasticsearch.ingest.AbstractProcessor;
|
@@ -65,10 +67,11 @@ public final class GeoIpProcessor extends AbstractProcessor {
|
65 | 67 |
|
66 | 68 | /**
|
67 | 69 | * Construct a geo-IP processor.
|
| 70 | + * |
68 | 71 | * @param tag the processor tag
|
69 | 72 | * @param description the processor description
|
70 | 73 | * @param field the source field to geo-IP map
|
71 |
| - * @param supplier a supplier of a geo-IP database reader; ideally this is lazily-loaded once on first use |
| 74 | + * @param supplier a supplier of a geo-IP database reader; ideally this is lazily-loaded once on first use |
72 | 75 | * @param isValid
|
73 | 76 | * @param targetField the target field
|
74 | 77 | * @param properties the properties; ideally this is lazily-loaded once on first use
|
@@ -104,7 +107,7 @@ public IngestDocument execute(IngestDocument ingestDocument) throws IOException
|
104 | 107 | Object ip = ingestDocument.getFieldValue(field, Object.class, ignoreMissing);
|
105 | 108 |
|
106 | 109 | if (isValid.get() == false) {
|
107 |
| - ingestDocument.appendFieldValue("tags","_geoip_expired_database", false); |
| 110 | + ingestDocument.appendFieldValue("tags", "_geoip_expired_database", false); |
108 | 111 | return ingestDocument;
|
109 | 112 | } else if (ip == null && ignoreMissing) {
|
110 | 113 | return ingestDocument;
|
@@ -367,9 +370,9 @@ public Factory(DatabaseRegistry databaseRegistry, ClusterService clusterService)
|
367 | 370 |
|
368 | 371 | @Override
|
369 | 372 | public GeoIpProcessor create(
|
370 |
| - final Map<String, Processor.Factory> registry, |
371 |
| - final String processorTag, |
372 |
| - final String description, final Map<String, Object> config) throws IOException { |
| 373 | + final Map<String, Processor.Factory> registry, |
| 374 | + final String processorTag, |
| 375 | + final String description, final Map<String, Object> config) throws IOException { |
373 | 376 | String ipField = readStringProperty(TYPE, processorTag, config, "field");
|
374 | 377 | String targetField = readStringProperty(TYPE, processorTag, config, "target_field", "geoip");
|
375 | 378 | String databaseFile = readStringProperty(TYPE, processorTag, config, "database_file", "GeoLite2-City.mmdb");
|
@@ -438,7 +441,17 @@ public GeoIpProcessor create(
|
438 | 441 | GeoIpTaskState state = (GeoIpTaskState) task.getState();
|
439 | 442 | GeoIpTaskState.Metadata metadata = state.getDatabases().get(databaseFile);
|
440 | 443 | // we never remove metadata from cluster state, if metadata is null we deal with built-in database, which is always valid
|
441 |
| - return metadata == null || metadata.isValid(currentState.metadata().settings()); |
| 444 | + if (metadata == null) { |
| 445 | + return true; |
| 446 | + } |
| 447 | + |
| 448 | + boolean valid = metadata.isValid(currentState.metadata().settings()); |
| 449 | + if (valid && metadata.isCloseToExpiration()) { |
| 450 | + HeaderWarning.addWarning("database [{}] was not updated for over 25 days, geoip processor will stop working if there " + |
| 451 | + "is no update for 30 days", databaseFile); |
| 452 | + } |
| 453 | + |
| 454 | + return valid; |
442 | 455 | };
|
443 | 456 | return new GeoIpProcessor(processorTag, description, ipField, supplier, isValid, targetField, properties, ignoreMissing,
|
444 | 457 | firstOnly);
|
|
0 commit comments