Search in sources :

Example 6 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class Lookup method evaluate.

@Override
public Map<Object, Object> evaluate(FunctionArgs args, EvaluationContext context) {
    Object key = keyParam.required(args, context);
    if (key == null) {
        return Collections.singletonMap(SINGLE_VALUE_KEY, defaultParam.optional(args, context).orElse(null));
    }
    LookupTableService.Function table = lookupTableParam.required(args, context);
    if (table == null) {
        return Collections.singletonMap(SINGLE_VALUE_KEY, defaultParam.optional(args, context).orElse(null));
    }
    LookupResult result = table.lookup(key);
    if (result == null || result.isEmpty()) {
        return Collections.singletonMap(SINGLE_VALUE_KEY, defaultParam.optional(args, context).orElse(null));
    }
    return result.multiValue();
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) LookupTableService(org.graylog2.lookup.LookupTableService)

Example 7 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class LookupStringList method evaluate.

@Override
public List<String> evaluate(FunctionArgs args, EvaluationContext context) {
    Object key = keyParam.required(args, context);
    if (key == null) {
        // noinspection unchecked
        return defaultParam.optional(args, context).orElse(ImmutableList.of());
    }
    LookupTableService.Function table = lookupTableParam.required(args, context);
    if (table == null) {
        // noinspection unchecked
        return defaultParam.optional(args, context).orElse(ImmutableList.of());
    }
    LookupResult result = table.lookup(key);
    if (result == null || result.isEmpty()) {
        // noinspection unchecked
        return defaultParam.optional(args, context).orElse(ImmutableList.of());
    }
    return result.stringListValue();
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) LookupTableService(org.graylog2.lookup.LookupTableService)

Example 8 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class LookupValue method evaluate.

@Override
public Object evaluate(FunctionArgs args, EvaluationContext context) {
    Object key = keyParam.required(args, context);
    if (key == null) {
        return defaultParam.optional(args, context).orElse(null);
    }
    LookupTableService.Function table = lookupTableParam.required(args, context);
    if (table == null) {
        return defaultParam.optional(args, context).orElse(null);
    }
    LookupResult result = table.lookup(key);
    if (result == null || result.isEmpty()) {
        return defaultParam.optional(args, context).orElse(null);
    }
    return result.singleValue();
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) LookupTableService(org.graylog2.lookup.LookupTableService)

Example 9 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class LookupStringListContains method evaluate.

@Override
public Boolean evaluate(FunctionArgs args, EvaluationContext context) {
    Object value = valueParam.required(args, context);
    if (value == null) {
        return false;
    }
    Object key = keyParam.required(args, context);
    if (key == null) {
        return false;
    }
    LookupTableService.Function table = lookupTableParam.required(args, context);
    if (table == null) {
        return false;
    }
    LookupResult result = table.lookup(key);
    if (result == null || result.isEmpty()) {
        return false;
    }
    return result.stringListValue().contains(value);
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) LookupTableService(org.graylog2.lookup.LookupTableService)

Example 10 with LookupResult

use of org.graylog2.plugin.lookup.LookupResult in project graylog2-server by Graylog2.

the class LookupTableExtractor method run.

@Override
@Nullable
protected Result[] run(String sourceFieldValue) {
    final LookupResult result = lookupTable.lookup(sourceFieldValue);
    if (result == null || result.isEmpty()) {
        return null;
    }
    final Object value = result.singleValue();
    if (value == null) {
        return null;
    }
    return new Result[] { new Result(value, targetField, -1, -1) };
}
Also used : LookupResult(org.graylog2.plugin.lookup.LookupResult) LookupResult(org.graylog2.plugin.lookup.LookupResult) Nullable(javax.annotation.Nullable)

Aggregations

LookupResult (org.graylog2.plugin.lookup.LookupResult)17 LookupTableService (org.graylog2.lookup.LookupTableService)5 JsonPath (com.jayway.jsonpath.JsonPath)3 Test (org.junit.Test)3 Timer (com.codahale.metrics.Timer)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DocumentContext (com.jayway.jsonpath.DocumentContext)1 InvalidJsonException (com.jayway.jsonpath.InvalidJsonException)1 InvalidPathException (com.jayway.jsonpath.InvalidPathException)1 PathNotFoundException (com.jayway.jsonpath.PathNotFoundException)1 UnknownHostException (java.net.UnknownHostException)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Nullable (javax.annotation.Nullable)1 HttpUrl (okhttp3.HttpUrl)1