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