Search in sources :

Example 51 with Message

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

the class FunctionsSnippetsTest method stringConcat.

@Test
public void stringConcat() {
    final Rule rule = parser.parseRule(ruleForTest(), false);
    final Message message = evaluateRule(rule, new Message("Dummy Message", "test", Tools.nowUTC()));
    assertThat(message.hasField("result")).isTrue();
    assertThat(message.getField("result")).isEqualTo("aabbcc");
}
Also used : CreateMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage) CloneMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage) DropMessage(org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage) Message(org.graylog2.plugin.Message) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Example 52 with Message

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

the class FunctionsSnippetsTest method lookupSetStringList.

@Test
public void lookupSetStringList() {
    final ImmutableList<String> testList = ImmutableList.of("foo", "bar");
    doReturn(LookupResult.withoutTTL().stringListValue(testList).build()).when(lookupTable).setStringList(any(), any());
    final Rule rule = parser.parseRule(ruleForTest(), true);
    final Message message = evaluateRule(rule);
    verify(lookupTable).setStringList("key", testList);
    verifyNoMoreInteractions(lookupTable);
    assertThat(message.getField("new_value")).isEqualTo(testList);
}
Also used : CreateMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage) CloneMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage) DropMessage(org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage) Message(org.graylog2.plugin.Message) IsString(org.graylog.plugins.pipelineprocessor.functions.conversion.IsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Example 53 with Message

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

the class FunctionsSnippetsTest method newlyCreatedMessage.

@Test
public void newlyCreatedMessage() {
    final Message message = new Message("test", "test", Tools.nowUTC());
    message.addField("foo", "bar");
    message.addStream(mock(Stream.class));
    final Rule rule = parser.parseRule(ruleForTest(), false);
    final EvaluationContext context = contextForRuleEval(rule, message);
    final Message origMessage = context.currentMessage();
    final Message newMessage = Iterables.getOnlyElement(context.createdMessages());
    assertThat(origMessage).isNotSameAs(newMessage);
    assertThat(newMessage.getMessage()).isEqualTo("new");
    assertThat(newMessage.getSource()).isEqualTo("synthetic");
    assertThat(newMessage.getStreams()).isEmpty();
    assertThat(newMessage.hasField("removed_again")).isFalse();
    assertThat(newMessage.getFieldAs(Boolean.class, "has_source")).isTrue();
    assertThat(newMessage.getFieldAs(String.class, "only_in")).isEqualTo("new message");
    assertThat(newMessage.getFieldAs(String.class, "multi")).isEqualTo("new message");
    assertThat(newMessage.getFieldAs(String.class, "foo")).isNull();
}
Also used : CreateMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage) CloneMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage) DropMessage(org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage) Message(org.graylog2.plugin.Message) RouteToStream(org.graylog.plugins.pipelineprocessor.functions.messages.RouteToStream) Stream(org.graylog2.plugin.streams.Stream) RemoveFromStream(org.graylog.plugins.pipelineprocessor.functions.messages.RemoveFromStream) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) EvaluationContext(org.graylog.plugins.pipelineprocessor.EvaluationContext) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Example 54 with Message

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

the class FunctionsSnippetsTest method notExpressionTypeCheck.

@Test
public void notExpressionTypeCheck() {
    try {
        Rule rule = parser.parseRule(ruleForTest(), true);
        Message in = new Message("test", "source", Tools.nowUTC());
        in.addField("facility", "mail");
        evaluateRule(rule, in);
        fail("missing type check for non-boolean type in unary NOT");
    } catch (Exception e) {
        assertThat(e).isInstanceOf(ParseException.class).hasMessageContaining("Expected type Boolean but found String");
    }
}
Also used : CreateMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage) CloneMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage) DropMessage(org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage) Message(org.graylog2.plugin.Message) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) ParseException(org.graylog.plugins.pipelineprocessor.parser.ParseException) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Example 55 with Message

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

the class FunctionsSnippetsTest method lookupAddStringList.

@Test
public void lookupAddStringList() {
    final ImmutableList<String> testList = ImmutableList.of("foo", "bar");
    doReturn(LookupResult.withoutTTL().stringListValue(testList).build()).when(lookupTable).addStringList(any(), any(), anyBoolean());
    final Rule rule = parser.parseRule(ruleForTest(), true);
    final Message message = evaluateRule(rule);
    verify(lookupTable).addStringList("key", testList, false);
    verifyNoMoreInteractions(lookupTable);
    assertThat(message.getField("new_value")).isEqualTo(testList);
}
Also used : CreateMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage) CloneMessage(org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage) DropMessage(org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage) Message(org.graylog2.plugin.Message) IsString(org.graylog.plugins.pipelineprocessor.functions.conversion.IsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockitoRule(org.mockito.junit.MockitoRule) Rule(org.graylog.plugins.pipelineprocessor.ast.Rule) BaseParserTest(org.graylog.plugins.pipelineprocessor.BaseParserTest) Test(org.junit.Test)

Aggregations

Message (org.graylog2.plugin.Message)420 Test (org.junit.Test)391 ApiOperation (io.swagger.annotations.ApiOperation)120 ApiResponses (io.swagger.annotations.ApiResponses)107 Timed (com.codahale.metrics.annotation.Timed)105 RawMessage (org.graylog2.plugin.journal.RawMessage)103 DateTime (org.joda.time.DateTime)102 Path (javax.ws.rs.Path)87 StreamRule (org.graylog2.plugin.streams.StreamRule)77 AuditEvent (org.graylog2.audit.jersey.AuditEvent)69 Produces (javax.ws.rs.Produces)57 Stream (org.graylog2.plugin.streams.Stream)55 CreateMessage (org.graylog.plugins.pipelineprocessor.functions.messages.CreateMessage)46 DropMessage (org.graylog.plugins.pipelineprocessor.functions.messages.DropMessage)46 BaseParserTest (org.graylog.plugins.pipelineprocessor.BaseParserTest)45 Rule (org.graylog.plugins.pipelineprocessor.ast.Rule)45 POST (javax.ws.rs.POST)41 GET (javax.ws.rs.GET)40 CloneMessage (org.graylog.plugins.pipelineprocessor.functions.messages.CloneMessage)36 MockitoRule (org.mockito.junit.MockitoRule)35