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);
}
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);
}
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);
}
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));
}
Aggregations