Search in sources :

Example 16 with EnrichmentKey

use of org.apache.metron.enrichment.converter.EnrichmentKey in project metron by apache.

the class SimpleHBaseEnrichmentFunctionsTest method setup.

@Before
public void setup() throws Exception {
    final MockHTable hbaseTable = (MockHTable) MockHBaseTableProvider.addToCache(hbaseTableName, cf);
    EnrichmentHelper.INSTANCE.load(hbaseTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {

        {
            for (int i = 0; i < 5; ++i) {
                add(new LookupKV<>(new EnrichmentKey(ENRICHMENT_TYPE, "indicator" + i), new EnrichmentValue(ImmutableMap.of("key" + i, "value" + i))));
            }
        }
    });
    context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> ImmutableMap.of(SimpleHBaseEnrichmentFunctions.TABLE_PROVIDER_TYPE_CONF, MockHBaseTableProvider.class.getName())).build();
}
Also used : Context(org.apache.metron.stellar.dsl.Context) LookupKV(org.apache.metron.enrichment.lookup.LookupKV) MockHTable(org.apache.metron.hbase.mock.MockHTable) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Before(org.junit.Before)

Example 17 with EnrichmentKey

use of org.apache.metron.enrichment.converter.EnrichmentKey in project metron by apache.

the class HostnameHandler method extract.

@Override
public Iterable<LookupKV> extract(final Hostname type, Map<String, Object> config) throws IOException {
    StringObjectPropertyType value = type.getHostnameValue();
    String typeStr = getType();
    if (config != null) {
        Object o = config.get(TYPE_CONFIG);
        if (o != null) {
            typeStr = o.toString();
        }
    }
    List<LookupKV> ret = new ArrayList<>();
    for (String token : StixExtractor.split(value)) {
        final String indicatorType = typeStr;
        LookupKV results = new LookupKV(new EnrichmentKey(indicatorType, token), new EnrichmentValue(new HashMap<String, Object>() {

            {
                put("source-type", "STIX");
                put("indicator-type", indicatorType);
                put("source", type.toXMLString());
            }
        }));
        ret.add(results);
    }
    return ret;
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StringObjectPropertyType(org.mitre.cybox.common_2.StringObjectPropertyType) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue)

Example 18 with EnrichmentKey

use of org.apache.metron.enrichment.converter.EnrichmentKey in project metron by apache.

the class TransformFilterExtractorDecoratorTest method filters_indicators.

@Test
public void filters_indicators() throws Exception {
    EnrichmentKey lookupKey = new EnrichmentKey("testenrichment", "");
    EnrichmentValue lookupValue = new EnrichmentValue(new HashMap<String, Object>() {

        {
            put("foo", "val1");
            put("bar", "");
            put("baz", "val3");
        }
    });
    LookupKV lkv = new LookupKV<>(lookupKey, lookupValue);
    List<LookupKV> extractedLkvs = new ArrayList<>();
    extractedLkvs.add(lkv);
    Mockito.when(extractor.extract("val1,,val3")).thenReturn(extractedLkvs);
    Iterable<LookupKV> extracted = decorator.extract("val1,,val3");
    Assert.assertThat(extracted, CoreMatchers.equalTo(new ArrayList<>()));
}
Also used : LookupKV(org.apache.metron.enrichment.lookup.LookupKV) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Test(org.junit.Test)

Example 19 with EnrichmentKey

use of org.apache.metron.enrichment.converter.EnrichmentKey in project metron by apache.

the class HBaseEnrichmentConverterTest method testResult.

@Test
public void testResult() throws IOException {
    HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
    Result r = converter.toResult("cf", key, value);
    LookupKV<EnrichmentKey, EnrichmentValue> converted = converter.fromResult(r, "cf");
    Assert.assertEquals(results, converted);
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 20 with EnrichmentKey

use of org.apache.metron.enrichment.converter.EnrichmentKey in project metron by apache.

the class HBaseEnrichmentConverterTest method testGet.

@Test
public void testGet() throws Exception {
    HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
    Get get = converter.toGet("cf", key);
    Assert.assertArrayEquals(key.toBytes(), get.getRow());
}
Also used : EnrichmentConverter(org.apache.metron.enrichment.converter.EnrichmentConverter) Get(org.apache.hadoop.hbase.client.Get) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue) Test(org.junit.Test)

Aggregations

EnrichmentKey (org.apache.metron.enrichment.converter.EnrichmentKey)25 EnrichmentValue (org.apache.metron.enrichment.converter.EnrichmentValue)22 LookupKV (org.apache.metron.enrichment.lookup.LookupKV)16 Test (org.junit.Test)13 EnrichmentConverter (org.apache.metron.enrichment.converter.EnrichmentConverter)7 HashMap (java.util.HashMap)6 Put (org.apache.hadoop.hbase.client.Put)5 MockHTable (org.apache.metron.hbase.mock.MockHTable)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 EnrichmentLookup (org.apache.metron.enrichment.lookup.EnrichmentLookup)3 BloomAccessTracker (org.apache.metron.enrichment.lookup.accesstracker.BloomAccessTracker)3 PersistentAccessTracker (org.apache.metron.enrichment.lookup.accesstracker.PersistentAccessTracker)3 Before (org.junit.Before)3 StringObjectPropertyType (org.mitre.cybox.common_2.StringObjectPropertyType)3 Map (java.util.Map)2 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)2 Result (org.apache.hadoop.hbase.client.Result)2 ConfigUploadComponent (org.apache.metron.enrichment.integration.components.ConfigUploadComponent)2 KafkaComponent (org.apache.metron.integration.components.KafkaComponent)2