Search in sources :

Example 1 with EnrichmentConfig

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

the class SensorEnrichmentConfigServiceImplTest method getTestSensorEnrichmentConfig.

private SensorEnrichmentConfig getTestSensorEnrichmentConfig() {
    SensorEnrichmentConfig sensorEnrichmentConfig = new SensorEnrichmentConfig();
    EnrichmentConfig enrichmentConfig = new EnrichmentConfig();
    enrichmentConfig.setFieldMap(new HashMap() {

        {
            put("geo", Arrays.asList("ip_dst_addr"));
        }
    });
    sensorEnrichmentConfig.setEnrichment(enrichmentConfig);
    ThreatIntelConfig threatIntelConfig = new ThreatIntelConfig();
    threatIntelConfig.setFieldMap(new HashMap() {

        {
            put("hbaseThreatIntel", Arrays.asList("ip_src_addr"));
        }
    });
    threatIntelConfig.setFieldToTypeMap(new HashMap() {

        {
            put("ip_src_addr", Arrays.asList("malicious_ip"));
        }
    });
    sensorEnrichmentConfig.setThreatIntel(threatIntelConfig);
    return sensorEnrichmentConfig;
}
Also used : ThreatIntelConfig(org.apache.metron.common.configuration.enrichment.threatintel.ThreatIntelConfig) HashMap(java.util.HashMap) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig) EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) SensorEnrichmentConfig(org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)

Example 2 with EnrichmentConfig

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

the class StellarEnrichmentConfigTest method testGetSubgroups_grouped.

@Test
public void testGetSubgroups_grouped() throws IOException {
    for (String c : GROUPED_CONFIGS) {
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, EnrichmentConfig.class);
        Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
        ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
        List<String> subgroups = Configs.STELLAR.getSubgroups(handler);
        Assert.assertEquals("group1", subgroups.get(0));
        Assert.assertEquals("group2", subgroups.get(1));
        Assert.assertEquals(2, subgroups.size());
    }
}
Also used : EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 3 with EnrichmentConfig

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

the class StellarEnrichmentConfigTest method testSplitter_grouped.

@Test
public void testSplitter_grouped() throws IOException {
    JSONObject message = getMessage();
    for (String c : GROUPED_CONFIGS) {
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, EnrichmentConfig.class);
        Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
        ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
        List<JSONObject> splits = Configs.STELLAR.splitByFields(message, null, x -> null, handler);
        Assert.assertEquals(2, splits.size());
        {
            Map<String, Object> split = (Map<String, Object>) splits.get(0).get("group1");
            Assert.assertEquals(2, split.size());
            Assert.assertEquals("stellar_test", split.get("source.type"));
            Assert.assertNull(split.get("stmt1"));
        }
        {
            Map<String, Object> split = (Map<String, Object>) splits.get(1).get("group2");
            Assert.assertEquals(1, split.size());
            Assert.assertEquals("foo", split.get("string"));
        }
    }
}
Also used : JSONObject(org.json.simple.JSONObject) EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) JSONObject(org.json.simple.JSONObject) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 4 with EnrichmentConfig

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

the class StellarEnrichmentConfigTest method testGetSubgroups_default.

@Test
public void testGetSubgroups_default() throws IOException {
    for (String c : DEFAULT_CONFIGS) {
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, EnrichmentConfig.class);
        Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
        ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
        List<String> subgroups = Configs.STELLAR.getSubgroups(handler);
        Assert.assertEquals("", subgroups.get(0));
        Assert.assertEquals(1, subgroups.size());
    }
}
Also used : EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 5 with EnrichmentConfig

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

the class StellarAdapterTest method test_tempVariable.

@Test
public void test_tempVariable() throws Exception {
    JSONObject message = getMessage();
    EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(tempVarStellarConfig_list, EnrichmentConfig.class);
    Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
    ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
    {
        JSONObject enriched = enrich(message, "group1", handler);
        Assert.assertEquals("stellar_test", enriched.get("stmt2"));
        Assert.assertEquals(1, enriched.size());
    }
    {
        JSONObject enriched = enrich(message, "group2", handler);
        Assert.assertEquals("foo", enriched.get("stmt3"));
        Assert.assertEquals(1, enriched.size());
    }
    {
        JSONObject enriched = enrich(message, "", handler);
        Assert.assertEquals(2, enriched.get("stmt4"));
        Assert.assertEquals("stellar_test", enriched.get("stmt5"));
        Assert.assertEquals(2, enriched.size());
    }
}
Also used : JSONObject(org.json.simple.JSONObject) EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) StellarEnrichmentTest(org.apache.metron.common.configuration.StellarEnrichmentTest) Test(org.junit.Test)

Aggregations

EnrichmentConfig (org.apache.metron.common.configuration.enrichment.EnrichmentConfig)14 ConfigHandler (org.apache.metron.common.configuration.enrichment.handler.ConfigHandler)13 Test (org.junit.Test)12 JSONObject (org.json.simple.JSONObject)9 Map (java.util.Map)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 StellarEnrichmentTest (org.apache.metron.common.configuration.StellarEnrichmentTest)4 HashMap (java.util.HashMap)1 SensorEnrichmentConfig (org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig)1 ThreatIntelConfig (org.apache.metron.common.configuration.enrichment.threatintel.ThreatIntelConfig)1