Search in sources :

Example 36 with SensorParserConfig

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

the class SensorParserConfigServiceImplTest method getTestSquidSensorParserConfig.

private SensorParserConfig getTestSquidSensorParserConfig() {
    SensorParserConfig sensorParserConfig = new SensorParserConfig();
    sensorParserConfig.setSensorTopic("squid");
    sensorParserConfig.setParserClassName("org.apache.metron.parsers.GrokParser");
    sensorParserConfig.setParserConfig(new HashMap() {

        {
            put("grokPath", "/patterns/squid");
            put("patternLabel", "SQUID_DELIMITED");
            put("timestampField", "timestamp");
        }
    });
    return sensorParserConfig;
}
Also used : HashMap(java.util.HashMap) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig)

Example 37 with SensorParserConfig

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

the class SensorParserConfigServiceImplTest method parseMessageShouldProperlyReturnParsedResults.

@Test
public void parseMessageShouldProperlyReturnParsedResults() throws Exception {
    final SensorParserConfig sensorParserConfig = getTestSquidSensorParserConfig();
    String grokStatement = "SQUID_DELIMITED %{NUMBER:timestamp}[^0-9]*%{INT:elapsed} %{IP:ip_src_addr} %{WORD:action}/%{NUMBER:code} %{NUMBER:bytes} %{WORD:method} %{NOTSPACE:url}[^0-9]*(%{IP:ip_dst_addr})?";
    String sampleData = "1461576382.642    161 127.0.0.1 TCP_MISS/200 103701 GET http://www.cnn.com/ - DIRECT/199.27.79.73 text/html";
    ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
    parseMessageRequest.setSensorParserConfig(sensorParserConfig);
    parseMessageRequest.setGrokStatement(grokStatement);
    parseMessageRequest.setSampleData(sampleData);
    File grokRoot = new File("./target", user);
    grokRoot.mkdir();
    File patternFile = new File(grokRoot, "squid");
    FileWriter writer = new FileWriter(patternFile);
    writer.write(grokStatement);
    writer.close();
    assertEquals(new HashMap() {

        {
            put("elapsed", 161);
            put("code", 200);
            put("ip_dst_addr", "199.27.79.73");
            put("ip_src_addr", "127.0.0.1");
            put("action", "TCP_MISS");
            put("bytes", 103701);
            put("method", "GET");
            put("url", "http://www.cnn.com/");
            put("timestamp", 1461576382642L);
            put("original_string", "1461576382.642    161 127.0.0.1 TCP_MISS/200 103701 GET http://www.cnn.com/ - DIRECT/199.27.79.73 text/html");
        }
    }, sensorParserConfigService.parseMessage(parseMessageRequest));
}
Also used : HashMap(java.util.HashMap) ParseMessageRequest(org.apache.metron.rest.model.ParseMessageRequest) FileWriter(java.io.FileWriter) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) File(java.io.File) Test(org.junit.Test)

Example 38 with SensorParserConfig

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

the class StellarServiceImplTest method applyTransformationsShouldProperlyTransformData.

@Test
public void applyTransformationsShouldProperlyTransformData() {
    SensorParserConfig sensorParserConfig = new SensorParserConfig();
    FieldTransformer fieldTransformater = new FieldTransformer();
    fieldTransformater.setOutput("url_host");
    fieldTransformater.setTransformation("STELLAR");
    fieldTransformater.setConfig(new LinkedHashMap<String, Object>() {

        {
            put("url_host", "TO_LOWER(URL_TO_HOST(url))");
        }
    });
    sensorParserConfig.setFieldTransformations(ImmutableList.of(fieldTransformater));
    SensorParserContext sensorParserContext = new SensorParserContext();
    sensorParserContext.setSensorParserConfig(sensorParserConfig);
    sensorParserContext.setSampleData(new HashMap<String, Object>() {

        {
            put("url", "https://caseystella.com/blog");
        }
    });
    Map<String, Object> results = stellarService.applyTransformations(sensorParserContext);
    assertEquals(2, results.size());
    assertEquals("https://caseystella.com/blog", results.get("url"));
    assertEquals("caseystella.com", results.get("url_host"));
}
Also used : SensorParserContext(org.apache.metron.rest.model.SensorParserContext) FieldTransformer(org.apache.metron.common.configuration.FieldTransformer) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 39 with SensorParserConfig

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

the class StormAdminServiceImplTest method startParserTopologyShouldProperlyReturnSuccessTopologyResponse.

@Test
public void startParserTopologyShouldProperlyReturnSuccessTopologyResponse() throws Exception {
    when(stormCLIClientWrapper.startParserTopology("bro")).thenReturn(0);
    when(globalConfigService.get()).thenReturn(new HashMap<String, Object>());
    when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
    TopologyResponse expected = new TopologyResponse();
    expected.setSuccessMessage(TopologyStatusCode.STARTED.toString());
    TopologyResponse actual = stormAdminService.startParserTopology("bro");
    assertEquals(expected, actual);
    assertEquals(expected.hashCode(), actual.hashCode());
}
Also used : TopologyResponse(org.apache.metron.rest.model.TopologyResponse) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 40 with SensorParserConfig

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

the class StormAdminServiceImplTest method stopParserTopologyShouldProperlyReturnErrorTopologyResponse.

@Test
public void stopParserTopologyShouldProperlyReturnErrorTopologyResponse() throws Exception {
    when(stormCLIClientWrapper.stopParserTopology("bro", false)).thenReturn(1);
    when(globalConfigService.get()).thenReturn(new HashMap<String, Object>());
    when(sensorParserConfigService.findOne("bro")).thenReturn(new SensorParserConfig());
    TopologyResponse expected = new TopologyResponse();
    expected.setErrorMessage(TopologyStatusCode.STOP_ERROR.toString());
    assertEquals(expected, stormAdminService.stopParserTopology("bro", false));
}
Also used : TopologyResponse(org.apache.metron.rest.model.TopologyResponse) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Aggregations

SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)49 Test (org.junit.Test)39 JSONObject (org.json.simple.JSONObject)18 FieldTransformer (org.apache.metron.common.configuration.FieldTransformer)17 HashMap (java.util.HashMap)9 ParserConfigurations (org.apache.metron.common.configuration.ParserConfigurations)5 Config (org.apache.storm.Config)5 File (java.io.File)4 IOException (java.io.IOException)3 JSONUtils (org.apache.metron.common.utils.JSONUtils)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Reference (java.lang.ref.Reference)2 java.util (java.util)2 List (java.util.List)2 Map (java.util.Map)2 Predicate (java.util.function.Predicate)2 Supplier (java.util.function.Supplier)2 Multiline (org.adrianwalker.multilinestring.Multiline)2 CommandLine (org.apache.commons.cli.CommandLine)2