Search in sources :

Example 6 with FunctionArgs

use of org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs in project graylog2-server by Graylog2.

the class CEFParserFunctionTest method evaluate_returns_result_for_valid_CEF_string_with_full_names.

@Test
public void evaluate_returns_result_for_valid_CEF_string_with_full_names() throws Exception {
    final CEFParserFunction function = new CEFParserFunction(new MetricRegistry());
    final Map<String, Expression> arguments = ImmutableMap.of(CEFParserFunction.VALUE, new StringExpression(new CommonToken(0), "CEF:0|vendor|product|1.0|id|name|low|dvc=example.com msg=Foobar"), CEFParserFunction.USE_FULL_NAMES, new BooleanExpression(new CommonToken(0), true));
    final FunctionArgs functionArgs = new FunctionArgs(function, arguments);
    final Message message = new Message("__dummy", "__dummy", DateTime.parse("2010-07-30T16:03:25Z"));
    final EvaluationContext evaluationContext = new EvaluationContext(message);
    final CEFParserResult result = function.evaluate(functionArgs, evaluationContext);
    assertNotNull(result);
    assertEquals(0, result.get("cef_version"));
    assertEquals("vendor", result.get("device_vendor"));
    assertEquals("product", result.get("device_product"));
    assertEquals("1.0", result.get("device_version"));
    assertEquals("id", result.get("device_event_class_id"));
    assertEquals("low", result.get("severity"));
    assertEquals("example.com", result.get("deviceAddress"));
    assertEquals("Foobar", result.get("message"));
}
Also used : BooleanExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.BooleanExpression) Message(org.graylog2.plugin.Message) BooleanExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.BooleanExpression) StringExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.StringExpression) Expression(org.graylog.plugins.pipelineprocessor.ast.expressions.Expression) MetricRegistry(com.codahale.metrics.MetricRegistry) StringExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.StringExpression) FunctionArgs(org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs) EvaluationContext(org.graylog.plugins.pipelineprocessor.EvaluationContext) CommonToken(org.antlr.v4.runtime.CommonToken) Test(org.junit.Test)

Example 7 with FunctionArgs

use of org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs in project graylog2-server by Graylog2.

the class CEFParserFunctionTest method evaluate_returns_null_for_empty_CEF_string.

@Test
public void evaluate_returns_null_for_empty_CEF_string() throws Exception {
    final Map<String, Expression> arguments = Collections.singletonMap(CEFParserFunction.VALUE, new StringExpression(new CommonToken(0), ""));
    final FunctionArgs functionArgs = new FunctionArgs(function, arguments);
    final Message message = new Message("__dummy", "__dummy", DateTime.parse("2010-07-30T16:03:25Z"));
    final EvaluationContext evaluationContext = new EvaluationContext(message);
    final CEFParserResult result = function.evaluate(functionArgs, evaluationContext);
    assertNull(result);
}
Also used : Message(org.graylog2.plugin.Message) BooleanExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.BooleanExpression) StringExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.StringExpression) Expression(org.graylog.plugins.pipelineprocessor.ast.expressions.Expression) StringExpression(org.graylog.plugins.pipelineprocessor.ast.expressions.StringExpression) FunctionArgs(org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs) EvaluationContext(org.graylog.plugins.pipelineprocessor.EvaluationContext) CommonToken(org.antlr.v4.runtime.CommonToken) Test(org.junit.Test)

Example 8 with FunctionArgs

use of org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs in project graylog2-server by Graylog2.

the class CEFParserFunctionTest method evaluate_returns_null_for_missing_CEF_string.

@Test
public void evaluate_returns_null_for_missing_CEF_string() throws Exception {
    final FunctionArgs functionArgs = new FunctionArgs(function, Collections.emptyMap());
    final Message message = new Message("__dummy", "__dummy", DateTime.parse("2010-07-30T16:03:25Z"));
    final EvaluationContext evaluationContext = new EvaluationContext(message);
    final CEFParserResult result = function.evaluate(functionArgs, evaluationContext);
    assertNull(result);
}
Also used : Message(org.graylog2.plugin.Message) FunctionArgs(org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs) EvaluationContext(org.graylog.plugins.pipelineprocessor.EvaluationContext) Test(org.junit.Test)

Aggregations

EvaluationContext (org.graylog.plugins.pipelineprocessor.EvaluationContext)8 FunctionArgs (org.graylog.plugins.pipelineprocessor.ast.functions.FunctionArgs)8 Message (org.graylog2.plugin.Message)7 Test (org.junit.Test)7 CommonToken (org.antlr.v4.runtime.CommonToken)6 BooleanExpression (org.graylog.plugins.pipelineprocessor.ast.expressions.BooleanExpression)6 Expression (org.graylog.plugins.pipelineprocessor.ast.expressions.Expression)6 StringExpression (org.graylog.plugins.pipelineprocessor.ast.expressions.StringExpression)6 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ImmutableList (com.google.common.collect.ImmutableList)1 Ints (com.google.common.primitives.Ints)1 TypeToken (com.google.common.reflect.TypeToken)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AbstractFunction (org.graylog.plugins.pipelineprocessor.ast.functions.AbstractFunction)1 FunctionDescriptor (org.graylog.plugins.pipelineprocessor.ast.functions.FunctionDescriptor)1 ParameterDescriptor (org.graylog.plugins.pipelineprocessor.ast.functions.ParameterDescriptor)1