use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.
the class SensorEnrichmentConfigServiceImpl method getAll.
@Override
public Map<String, SensorEnrichmentConfig> getAll() throws RestException {
Map<String, SensorEnrichmentConfig> sensorEnrichmentConfigs = new HashMap<>();
List<String> sensorNames = getAllTypes();
for (String name : sensorNames) {
SensorEnrichmentConfig config = findOne(name);
if (config != null) {
sensorEnrichmentConfigs.put(name, config);
}
}
return sensorEnrichmentConfigs;
}
use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.
the class SensorEnrichmentConfigServiceImplTest method getAllShouldProperlyReturnSensorEnrichmentConfigs.
@Test
public void getAllShouldProperlyReturnSensorEnrichmentConfigs() throws Exception {
final SensorEnrichmentConfig sensorEnrichmentConfig = getTestSensorEnrichmentConfig();
EnrichmentConfigurations configs = new EnrichmentConfigurations() {
@Override
public Map<String, Object> getConfigurations() {
return ImmutableMap.of(EnrichmentConfigurations.getKey("bro"), sensorEnrichmentConfig);
}
};
when(cache.get(eq(EnrichmentConfigurations.class))).thenReturn(configs);
assertEquals(new HashMap() {
{
put("bro", sensorEnrichmentConfig);
}
}, sensorEnrichmentConfigService.getAll());
}
use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.
the class SensorEnrichmentConfigServiceImplTest method saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave.
@Test
public void saveShouldReturnSameConfigThatIsPassedOnSuccessfulSave() throws Exception {
final SensorEnrichmentConfig sensorEnrichmentConfig = getTestSensorEnrichmentConfig();
when(objectMapper.writeValueAsString(sensorEnrichmentConfig)).thenReturn(broJson);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro", broJson.getBytes())).thenReturn(new Stat());
when(curatorFramework.setData()).thenReturn(setDataBuilder);
assertEquals(sensorEnrichmentConfig, sensorEnrichmentConfigService.save("bro", sensorEnrichmentConfig));
verify(setDataBuilder).forPath(eq(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro"), eq(broJson.getBytes()));
}
use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.
the class SensorEnrichmentConfigServiceImplTest method saveShouldWrapExceptionInRestException.
@Test
public void saveShouldWrapExceptionInRestException() throws Exception {
exception.expect(RestException.class);
SetDataBuilder setDataBuilder = mock(SetDataBuilder.class);
when(setDataBuilder.forPath(ConfigurationType.ENRICHMENT.getZookeeperRoot() + "/bro", broJson.getBytes())).thenThrow(Exception.class);
when(curatorFramework.setData()).thenReturn(setDataBuilder);
sensorEnrichmentConfigService.save("bro", new SensorEnrichmentConfig());
}
use of org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig in project metron by apache.
the class SensorEnrichmentConfigServiceImplTest method getTestSensorEnrichmentConfig.
private SensorEnrichmentConfig getTestSensorEnrichmentConfig() {
SensorEnrichmentConfig sensorEnrichmentConfig = new SensorEnrichmentConfig();
EnrichmentConfig enrichmentConfig = new EnrichmentConfig();
enrichmentConfig.setFieldMap(new HashMap() {
{
put("geo", Arrays.asList("ip_dst_addr"));
}
});
sensorEnrichmentConfig.setEnrichment(enrichmentConfig);
ThreatIntelConfig threatIntelConfig = new ThreatIntelConfig();
threatIntelConfig.setFieldMap(new HashMap() {
{
put("hbaseThreatIntel", Arrays.asList("ip_src_addr"));
}
});
threatIntelConfig.setFieldToTypeMap(new HashMap() {
{
put("ip_src_addr", Arrays.asList("malicious_ip"));
}
});
sensorEnrichmentConfig.setThreatIntel(threatIntelConfig);
return sensorEnrichmentConfig;
}
Aggregations