Search in sources :

Example 21 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorFactoryTests method testSetIgnoreMissing.

public void testSetIgnoreMissing() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders, new GeoIpCache(1000));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("ignore_missing", true);
    String processorTag = randomAlphaOfLength(10);
    GeoIpProcessor processor = factory.create(null, processorTag, null, config);
    assertThat(processor.getTag(), equalTo(processorTag));
    assertThat(processor.getField(), equalTo("_field"));
    assertThat(processor.getTargetField(), equalTo("geoip"));
    assertThat(processor.getDatabaseType(), equalTo("GeoLite2-City"));
    assertThat(processor.getProperties(), sameInstance(GeoIpProcessor.Factory.DEFAULT_CITY_PROPERTIES));
    assertTrue(processor.isIgnoreMissing());
}
Also used : HashMap(java.util.HashMap) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Example 22 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorFactoryTests method testBuildDbFile.

public void testBuildDbFile() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders, new GeoIpCache(1000));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-Country.mmdb");
    GeoIpProcessor processor = factory.create(null, null, null, config);
    assertThat(processor.getField(), equalTo("_field"));
    assertThat(processor.getTargetField(), equalTo("geoip"));
    assertThat(processor.getDatabaseType(), equalTo("GeoLite2-Country"));
    assertThat(processor.getProperties(), sameInstance(GeoIpProcessor.Factory.DEFAULT_COUNTRY_PROPERTIES));
    assertFalse(processor.isIgnoreMissing());
}
Also used : HashMap(java.util.HashMap) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Example 23 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorFactoryTests method testBuildNonExistingDbFile.

public void testBuildNonExistingDbFile() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders, new GeoIpCache(1000));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "does-not-exist.mmdb");
    Exception e = expectThrows(OpenSearchParseException.class, () -> factory.create(null, null, null, config));
    assertThat(e.getMessage(), equalTo("[database_file] database file [does-not-exist.mmdb] doesn't exist"));
}
Also used : HashMap(java.util.HashMap) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache) OpenSearchParseException(org.opensearch.OpenSearchParseException) IOException(java.io.IOException)

Example 24 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorFactoryTests method testAsnBuildDefaults.

public void testAsnBuildDefaults() throws Exception {
    GeoIpProcessor.Factory factory = new GeoIpProcessor.Factory(databaseReaders, new GeoIpCache(1000));
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("database_file", "GeoLite2-ASN.mmdb");
    String processorTag = randomAlphaOfLength(10);
    GeoIpProcessor processor = factory.create(null, processorTag, null, config);
    assertThat(processor.getTag(), equalTo(processorTag));
    assertThat(processor.getField(), equalTo("_field"));
    assertThat(processor.getTargetField(), equalTo("geoip"));
    assertThat(processor.getDatabaseType(), equalTo("GeoLite2-ASN"));
    assertThat(processor.getProperties(), sameInstance(GeoIpProcessor.Factory.DEFAULT_ASN_PROPERTIES));
    assertFalse(processor.isIgnoreMissing());
}
Also used : HashMap(java.util.HashMap) Matchers.hasToString(org.hamcrest.Matchers.hasToString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Example 25 with GeoIpCache

use of org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache in project OpenSearch by opensearch-project.

the class GeoIpProcessorTests method testListFirstOnlyNoMatches.

public void testListFirstOnlyNoMatches() throws Exception {
    GeoIpProcessor processor = new GeoIpProcessor(randomAlphaOfLength(10), null, "source_field", loader("/GeoLite2-City.mmdb"), "target_field", EnumSet.allOf(GeoIpProcessor.Property.class), false, new GeoIpCache(1000), true);
    Map<String, Object> document = new HashMap<>();
    document.put("source_field", Arrays.asList("127.0.0.1", "127.0.0.2"));
    IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
    processor.execute(ingestDocument);
    assertThat(ingestDocument.getSourceAndMetadata().containsKey("target_field"), is(false));
}
Also used : HashMap(java.util.HashMap) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoIpCache(org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)

Aggregations

GeoIpCache (org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)33 HashMap (java.util.HashMap)26 Matchers.containsString (org.hamcrest.Matchers.containsString)26 IngestDocument (org.opensearch.ingest.IngestDocument)19 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)17 Matchers.hasToString (org.hamcrest.Matchers.hasToString)13 Map (java.util.Map)9 IOException (java.io.IOException)7 OpenSearchParseException (org.opensearch.OpenSearchParseException)4 AbstractResponse (com.maxmind.geoip2.model.AbstractResponse)2 Path (java.nio.file.Path)2 List (java.util.List)2 Mockito.mock (org.mockito.Mockito.mock)2 InetAddresses (org.opensearch.common.network.InetAddresses)2 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)2 ArrayList (java.util.ArrayList)1