Search in sources :

Example 71 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class RenameTransformationTest method renameMissingField.

@Test
public void renameMissingField() throws Exception {
    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(renameMissingField));
    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
    JSONObject input = new JSONObject(new HashMap<String, Object>() {

        {
            for (int i = 2; i <= 10; ++i) {
                put("old_field" + i, "f" + i);
            }
        }
    });
    handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
    assertFalse(input.containsKey("new_field1"));
    for (int i = 2; i <= 10; ++i) {
        assertEquals("f" + i, input.get("old_field" + i));
    }
    assertEquals(9, input.size());
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) JSONObject(org.json.simple.JSONObject) Test(org.junit.jupiter.api.Test)

Example 72 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class RenameTransformationTest method smokeTest.

@Test
public void smokeTest() throws Exception {
    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(smoketestConfig));
    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
    JSONObject input = new JSONObject(new HashMap<String, Object>() {

        {
            for (int i = 1; i <= 10; ++i) {
                put("old_field" + i, "f" + i);
            }
        }
    });
    handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
    assertEquals("f1", input.get("new_field1"));
    assertEquals("f2", input.get("new_field2"));
    for (int i = 3; i <= 10; ++i) {
        assertEquals("f" + i, input.get("old_field" + i));
    }
    assertFalse(input.containsKey("old_field1"));
    assertFalse(input.containsKey("old_field2"));
    assertEquals(10, input.size());
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) JSONObject(org.json.simple.JSONObject) Test(org.junit.jupiter.api.Test)

Example 73 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class StellarTransformationTest method testStellarNumericDomain.

@Test
public void testStellarNumericDomain() throws Exception {
    /*
    Despite the domain being weird, URL_TO_HOST should allow it to pass through.
    However, because it does NOT form a proper domain (no TLD), DOMAIN_REMOVE_SUBDOMAINS returns
    null indicating that the input is semantically incorrect.
     */
    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(configNumericDomain));
    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
    JSONObject input = new JSONObject();
    handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
    assertTrue(input.containsKey("full_hostname"));
    assertEquals("1234567890123456789012345678901234567890123456789012345678901234567890", input.get("full_hostname"));
    assertFalse(input.containsKey("domain_without_subdomains"));
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Example 74 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class StellarTransformationTest method testStellarSpecialCharacters.

@Test
public void testStellarSpecialCharacters() throws Exception {
    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(stellarConfigEspecial));
    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
    JSONObject input = new JSONObject(new HashMap<String, Object>() {

        {
            put("timestamp", "2016-01-05 17:02:30");
        }
    });
    handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
    long expected = 1452013350000L;
    assertEquals(expected, input.get("utc_timestamp"));
    assertTrue(input.containsKey("timestamp"));
    assertTrue(input.containsKey("newStellarField"));
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) JSONObject(org.json.simple.JSONObject) Test(org.junit.jupiter.api.Test)

Example 75 with SensorParserConfig

use of org.apache.metron.common.configuration.SensorParserConfig in project metron by apache.

the class StellarTransformationTest method testStellarBadConfig.

@Test
public void testStellarBadConfig() throws Exception {
    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(badConfig));
    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
    JSONObject input = new JSONObject();
    IllegalStateException ex = assertThrows(IllegalStateException.class, () -> handler.transformAndUpdate(input, Context.EMPTY_CONTEXT()));
    assertTrue(ex.getMessage().contains("URL_TO_HOST"));
    assertTrue(ex.getMessage().contains("123"));
}
Also used : JSONObject(org.json.simple.JSONObject) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.jupiter.api.Test)

Aggregations

SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)97 Test (org.junit.jupiter.api.Test)74 JSONObject (org.json.simple.JSONObject)40 FieldTransformer (org.apache.metron.common.configuration.FieldTransformer)20 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)19 HashMap (java.util.HashMap)15 Config (org.apache.storm.Config)7 BaseBoltTest (org.apache.metron.test.bolt.BaseBoltTest)6 File (java.io.File)5 Map (java.util.Map)5 CuratorFramework (org.apache.curator.framework.CuratorFramework)5 WriterHandler (org.apache.metron.parsers.bolt.WriterHandler)5 IOException (java.io.IOException)4 SensorParserGroup (org.apache.metron.common.configuration.SensorParserGroup)4 MetronError (org.apache.metron.common.error.MetronError)4 ImmutableList (com.google.common.collect.ImmutableList)3 List (java.util.List)3 CommandLine (org.apache.commons.cli.CommandLine)3 ParseException (org.apache.commons.cli.ParseException)3 PosixParser (org.apache.commons.cli.PosixParser)3