use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class TransformFilterExtractorDecoratorTest method filters_values.
@Test
public void filters_values() throws Exception {
final String indicatorVal = "val2";
EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", indicatorVal);
EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {
{
put("foo", "val1");
put("bar", indicatorVal);
put("baz", "");
}
});
LookupKV lkv = new LookupKV<>(lookupKey, lookupValue);
List<LookupKV> extractedLkvs = new ArrayList<>();
extractedLkvs.add(lkv);
Mockito.when(extractor.extract("val1,val2,")).thenReturn(extractedLkvs);
Iterable<LookupKV> extracted = decorator.extract("val1,val2,");
Assert.assertThat(extracted, CoreMatchers.equalTo(new ArrayList<>()));
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class URIHandlerTest method testURIHandler.
@Test
public void testURIHandler() throws Exception {
StixExtractor extractor = new StixExtractor();
extractor.initialize(new HashMap<>());
Iterable<LookupKV> kvs = extractor.extract(uriHandlerObject);
Assert.assertEquals(1, Iterables.size(kvs));
LookupKV kv = Iterables.getFirst(kvs, null);
EnrichmentKey key = (EnrichmentKey) kv.getKey();
Assert.assertEquals("http://www.kotimi.com/alpha/gtex/", key.getIndicator());
Assert.assertEquals("uriobjecttype", key.type);
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class SimpleEnrichmentFlatFileLoaderIntegrationTest method testLocalLineByLine.
@Test
public void testLocalLineByLine() throws Exception {
String[] argv = { "-c cf", "-t enrichment", "-e " + lineByLineExtractorConfigFile.getPath(), "-i " + multilineFile.getPath(), "-p 2", "-b 128", "-q" };
SimpleEnrichmentFlatFileLoader.main(config, argv);
EnrichmentConverter converter = new EnrichmentConverter();
ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
for (Result r : scanner) {
results.add(converter.fromResult(r, cf));
testTable.delete(new Delete(r.getRow()));
}
Assert.assertEquals(NUM_LINES, results.size());
Assert.assertTrue(results.get(0).getKey().indicator.startsWith("google"));
Assert.assertEquals(results.get(0).getKey().type, "enrichment");
Assert.assertEquals(results.get(0).getValue().getMetadata().size(), 2);
Assert.assertTrue(results.get(0).getValue().getMetadata().get("meta").toString().startsWith("foo"));
Assert.assertTrue(results.get(0).getValue().getMetadata().get("host").toString().startsWith("google"));
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class SimpleEnrichmentFlatFileLoaderIntegrationTest method custom_extractor_transforms_and_filters_indicators_and_value_metadata.
@Test
public void custom_extractor_transforms_and_filters_indicators_and_value_metadata() throws Exception {
String[] argv = { "-c cf", "-t enrichment", "-e " + customLineByLineExtractorConfigFile.getPath(), "-i " + multilineFile.getPath(), "-p 2", "-b 128", "-q" };
SimpleEnrichmentFlatFileLoader.main(config, argv);
EnrichmentConverter converter = new EnrichmentConverter();
ResultScanner scanner = testTable.getScanner(Bytes.toBytes(cf));
List<LookupKV<EnrichmentKey, EnrichmentValue>> results = new ArrayList<>();
for (Result r : scanner) {
results.add(converter.fromResult(r, cf));
testTable.delete(new Delete(r.getRow()));
}
Assert.assertEquals(NUM_LINES, results.size());
Assert.assertThat(results.get(0).getKey().getIndicator(), startsWith("GOOGLE"));
Assert.assertThat(results.get(0).getKey().type, equalTo("enrichment"));
Assert.assertThat(results.get(0).getValue().getMetadata().size(), equalTo(2));
Assert.assertThat(results.get(0).getValue().getMetadata().get("meta").toString(), startsWith("foo"));
Assert.assertThat(results.get(0).getValue().getMetadata().get("host").toString(), startsWith("GOOGLE"));
}
use of org.apache.metron.enrichment.lookup.LookupKV in project metron by apache.
the class ThreatIntelAdapterTest method setup.
@Before
public void setup() throws Exception {
final MockHTable trackerTable = (MockHTable) MockHBaseTableProvider.addToCache(atTableName, cf);
final MockHTable threatIntelTable = (MockHTable) MockHBaseTableProvider.addToCache(threatIntelTableName, cf);
EnrichmentHelper.INSTANCE.load(threatIntelTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {
{
add(new LookupKV<>(new EnrichmentKey("10.0.2.3", "10.0.2.3"), new EnrichmentValue(new HashMap<>())));
}
});
BloomAccessTracker bat = new BloomAccessTracker(threatIntelTableName, 100, 0.03);
PersistentAccessTracker pat = new PersistentAccessTracker(threatIntelTableName, "0", trackerTable, cf, bat, 0L);
lookup = new EnrichmentLookup(threatIntelTable, cf, pat);
JSONParser jsonParser = new JSONParser();
expectedMessage = (JSONObject) jsonParser.parse(expectedMessageString);
}
Aggregations