Search in sources :

Example 1 with ParseMessageRequest

use of org.apache.metron.rest.model.ParseMessageRequest in project metron by apache.

the class SensorParserConfigServiceImplTest method invalidParserClassShouldThrowRestException.

@Test
public void invalidParserClassShouldThrowRestException() throws Exception {
    exception.expect(RestException.class);
    final SensorParserConfig sensorParserConfig = new SensorParserConfig();
    sensorParserConfig.setSensorTopic("squid");
    sensorParserConfig.setParserClassName("bad.class.package.BadClassName");
    ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
    parseMessageRequest.setSensorParserConfig(sensorParserConfig);
    sensorParserConfigService.parseMessage(parseMessageRequest);
}
Also used : ParseMessageRequest(org.apache.metron.rest.model.ParseMessageRequest) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 2 with ParseMessageRequest

use of org.apache.metron.rest.model.ParseMessageRequest in project metron by apache.

the class SensorParserConfigServiceImplTest method missingSensorParserConfigShouldThrowRestException.

@Test
public void missingSensorParserConfigShouldThrowRestException() throws Exception {
    exception.expect(RestException.class);
    ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
    sensorParserConfigService.parseMessage(parseMessageRequest);
}
Also used : ParseMessageRequest(org.apache.metron.rest.model.ParseMessageRequest) Test(org.junit.Test)

Example 3 with ParseMessageRequest

use of org.apache.metron.rest.model.ParseMessageRequest in project metron by apache.

the class SensorParserConfigServiceImplTest method missingParserClassShouldThrowRestException.

@Test
public void missingParserClassShouldThrowRestException() throws Exception {
    exception.expect(RestException.class);
    final SensorParserConfig sensorParserConfig = new SensorParserConfig();
    sensorParserConfig.setSensorTopic("squid");
    ParseMessageRequest parseMessageRequest = new ParseMessageRequest();
    parseMessageRequest.setSensorParserConfig(sensorParserConfig);
    sensorParserConfigService.parseMessage(parseMessageRequest);
}
Also used : ParseMessageRequest(org.apache.metron.rest.model.ParseMessageRequest) SensorParserConfig(org.apache.metron.common.configuration.SensorParserConfig) Test(org.junit.Test)

Example 4 with ParseMessageRequest

use of org.apache.metron.rest.model.ParseMessageRequest 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)

Aggregations

ParseMessageRequest (org.apache.metron.rest.model.ParseMessageRequest)4 Test (org.junit.Test)4 SensorParserConfig (org.apache.metron.common.configuration.SensorParserConfig)3 File (java.io.File)1 FileWriter (java.io.FileWriter)1 HashMap (java.util.HashMap)1