Search in sources :

Example 11 with SensorEnrichmentConfig

use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.

the class SimpleHBaseAdapterTest method testMultiColumnFamiliesWrongCF.

@Test
public void testMultiColumnFamiliesWrongCF() throws Exception {
    SimpleHBaseAdapter sha = new SimpleHBaseAdapter();
    sha.lookup = lookup;
    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
    JSONObject actualMessage = sha.enrich(new CacheKey("test", "test", broSc));
    Assert.assertEquals(actualMessage, new JSONObject());
    actualMessage = sha.enrich(new CacheKey("ip_dst_addr", "10.0.2.4", broSc));
    Assert.assertNotNull(actualMessage);
    Assert.assertEquals(new JSONObject(new HashMap<String, Object>()), actualMessage);
}
Also used : JSONObject(org.json.simple.JSONObject) HashMap(java.util.HashMap) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) CacheKey(org.apache.metron.enrichment.bolt.CacheKey) Test(org.junit.Test)

Example 12 with SensorEnrichmentConfig

use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.

the class SimpleHBaseAdapterTest method testEnrich.

@Test
public void testEnrich() throws Exception {
    SimpleHBaseAdapter sha = new SimpleHBaseAdapter();
    sha.lookup = lookup;
    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
    JSONObject actualMessage = sha.enrich(new CacheKey("test", "test", broSc));
    Assert.assertEquals(actualMessage, new JSONObject());
    actualMessage = sha.enrich(new CacheKey("ip_dst_addr", "10.0.2.3", broSc));
    Assert.assertNotNull(actualMessage);
    Assert.assertEquals(expectedMessage, actualMessage);
}
Also used : JSONObject(org.json.simple.JSONObject) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) CacheKey(org.apache.metron.enrichment.bolt.CacheKey) Test(org.junit.Test)

Example 13 with SensorEnrichmentConfig

use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.

the class ThreatIntelAdapterTest method testEnrich.

@Test
public void testEnrich() throws Exception {
    ThreatIntelAdapter tia = new ThreatIntelAdapter();
    tia.lookup = lookup;
    SensorEnrichmentConfig broSc = JSONUtils.INSTANCE.load(sourceConfigStr, SensorEnrichmentConfig.class);
    JSONObject actualMessage = tia.enrich(new CacheKey("ip_dst_addr", "10.0.2.3", broSc));
    Assert.assertNotNull(actualMessage);
    Assert.assertEquals(expectedMessage, actualMessage);
}
Also used : JSONObject(org.json.simple.JSONObject) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) CacheKey(org.apache.metron.enrichment.bolt.CacheKey) Test(org.junit.Test)

Example 14 with SensorEnrichmentConfig

use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.

the class ParallelEnricherTest method testCacheHit.

@Test
public void testCacheHit() throws Exception {
    numAccesses.set(0);
    JSONObject message = new JSONObject() {

        {
            put(Constants.SENSOR_TYPE, "test");
        }
    };
    for (int i = 0; i < 10; ++i) {
        SensorEnrichmentConfig config = JSONUtils.INSTANCE.load(goodConfig, SensorEnrichmentConfig.class);
        config.getConfiguration().putIfAbsent("stellarContext", stellarContext);
        ParallelEnricher.EnrichmentResult result = enricher.apply(message, EnrichmentStrategies.ENRICHMENT, config, null);
    }
    // we only want 2 actual instances of the adapter.enrich being run due to the cache.
    Assert.assertTrue(2 >= numAccesses.get());
}
Also used : JSONObject(org.json.simple.JSONObject) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) Test(org.junit.Test)

Example 15 with SensorEnrichmentConfig

use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.

the class ParallelEnricherTest method testBadConfig.

@Test
public void testBadConfig() throws Exception {
    SensorEnrichmentConfig config = JSONUtils.INSTANCE.load(badConfig, SensorEnrichmentConfig.class);
    config.getConfiguration().putIfAbsent("stellarContext", stellarContext);
    JSONObject message = new JSONObject() {

        {
            put(Constants.SENSOR_TYPE, "test");
        }
    };
    ParallelEnricher.EnrichmentResult result = enricher.apply(message, EnrichmentStrategies.ENRICHMENT, config, null);
    JSONObject ret = result.getResult();
    Assert.assertEquals(ret + " is not what I expected", 8, ret.size());
    Assert.assertEquals(1, ret.get("map.blah"));
    Assert.assertEquals("test", ret.get("source.type"));
    Assert.assertEquals(1, ret.get("one"));
    Assert.assertEquals(2, ret.get("foo"));
    Assert.assertEquals("TEST", ret.get("ALL_CAPS"));
    Assert.assertEquals(1, result.getEnrichmentErrors().size());
}
Also used : JSONObject(org.json.simple.JSONObject) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) Test(org.junit.Test)

Aggregations

SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)30 Test (org.junit.Test)22 JSONObject (org.json.simple.JSONObject)15 HashMap (java.util.HashMap)11 CacheKey (org.apache.metron.enrichment.bolt.CacheKey)6 File (java.io.File)4 MetronError (org.apache.metron.common.error.MetronError)3 FileInputStream (java.io.FileInputStream)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 SetDataBuilder (org.apache.curator.framework.api.SetDataBuilder)2 EnrichmentConfigurations (org.apache.metron.common.configuration.EnrichmentConfigurations)2 SensorEnrichmentUpdateConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentUpdateConfig)2 ThreatTriageProcessor (org.apache.metron.threatintel.triage.ThreatTriageProcessor)2 Values (org.apache.storm.tuple.Values)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 EnrichmentConfig (org.apache.metron.common.configuration.enrichment.EnrichmentConfig)1