Search in sources :

Example 6 with EnrichmentConfig

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

the class StellarAdapterTest method test_mixed.

@Test
public void test_mixed() throws Exception {
    for (String c : MIXED_CONFIGS) {
        JSONObject message = getMessage();
        EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(c, 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("stmt1"));
            Assert.assertEquals("stellar_test", enriched.get("stmt2"));
            Assert.assertEquals(2, 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)

Example 7 with EnrichmentConfig

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

the class StellarAdapterTest method testMapEnrichment.

private void testMapEnrichment(String config, String field) throws Exception {
    JSONObject message = getMessage();
    EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(config, EnrichmentConfig.class);
    Assert.assertNotNull(enrichmentConfig.getEnrichmentConfigs().get("stellar"));
    ConfigHandler handler = enrichmentConfig.getEnrichmentConfigs().get("stellar");
    JSONObject enriched = enrich(message, field, handler);
    Assert.assertEquals(2, enriched.size());
    Assert.assertEquals("stellar_test", enriched.get("stmt2.foo"));
    Assert.assertEquals("stellar_test".toUpperCase(), enriched.get("stmt1"));
}
Also used : JSONObject(org.json.simple.JSONObject) EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler)

Example 8 with EnrichmentConfig

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

the class EnrichmentConfigTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    EnrichmentConfig config = JSONUtils.INSTANCE.load(sourceConfigStr, EnrichmentConfig.class);
    Assert.assertTrue(config.getFieldMap().get("stellar") instanceof Map);
    Assert.assertTrue(config.getEnrichmentConfigs().get("stellar") instanceof ConfigHandler);
    Assert.assertEquals(Configs.STELLAR, ((ConfigHandler) config.getEnrichmentConfigs().get("stellar")).getType());
}
Also used : EnrichmentConfig(org.apache.metron.common.configuration.enrichment.EnrichmentConfig) Map(java.util.Map) ConfigHandler(org.apache.metron.common.configuration.enrichment.handler.ConfigHandler) Test(org.junit.Test)

Example 9 with EnrichmentConfig

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

the class StellarEnrichmentConfigTest method testSplitter_default.

@Test
public void testSplitter_default() throws IOException {
    JSONObject message = getMessage();
    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<JSONObject> splits = Configs.STELLAR.splitByFields(message, null, x -> null, handler);
        Assert.assertEquals(1, splits.size());
        Map<String, Object> split = (Map<String, Object>) splits.get(0).get("");
        Assert.assertEquals(3, split.size());
        Assert.assertEquals("stellar_test", split.get("source.type"));
        Assert.assertEquals("foo", split.get("string"));
        Assert.assertNull(split.get("stmt1"));
    }
}
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 10 with EnrichmentConfig

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

the class StellarEnrichmentConfigTest method testSplitter_listWithTemporaryVariables.

@Test
public void testSplitter_listWithTemporaryVariables() throws IOException {
    JSONObject message = new JSONObject(ImmutableMap.of("domain_without_subdomains", "yahoo.com"));
    EnrichmentConfig enrichmentConfig = JSONUtils.INSTANCE.load(conf, 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(1, splits.size());
    Map<String, Object> split = (Map<String, Object>) (splits.get(0)).get("");
    Assert.assertEquals("yahoo.com", split.get("domain_without_subdomains"));
    Assert.assertTrue(split.containsKey("dga_result"));
    Assert.assertTrue(split.containsKey("dga_model_endpoint"));
    Assert.assertTrue(split.containsKey("dga_result_map"));
}
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)

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