Search in sources :

Example 16 with EnrichmentValue

use of org.apache.metron.enrichment.converter.EnrichmentValue 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 17 with EnrichmentValue

use of org.apache.metron.enrichment.converter.EnrichmentValue 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 18 with EnrichmentValue

use of org.apache.metron.enrichment.converter.EnrichmentValue 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 19 with EnrichmentValue

use of org.apache.metron.enrichment.converter.EnrichmentValue 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)

Example 20 with EnrichmentValue

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

the class HBaseEnrichmentConverterTest method testPut.

@Test
public void testPut() throws IOException {
    HbaseConverter<EnrichmentKey, EnrichmentValue> converter = new EnrichmentConverter();
    Put put = converter.toPut("cf", key, value);
    LookupKV<EnrichmentKey, EnrichmentValue> converted = converter.fromPut(put, "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) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Aggregations

EnrichmentKey (org.apache.metron.enrichment.converter.EnrichmentKey)22 EnrichmentValue (org.apache.metron.enrichment.converter.EnrichmentValue)22 LookupKV (org.apache.metron.enrichment.lookup.LookupKV)14 Test (org.junit.Test)10 EnrichmentConverter (org.apache.metron.enrichment.converter.EnrichmentConverter)6 HashMap (java.util.HashMap)5 MockHTable (org.apache.metron.hbase.mock.MockHTable)5 IOException (java.io.IOException)4 Put (org.apache.hadoop.hbase.client.Put)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