Search in sources :

Example 51 with Messages

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

the class IndexCreatingDatabaseOperation method insert.

@Override
public void insert(InputStream dataScript) {
    waitForGreenStatus();
    final IndicesAdminClient indicesAdminClient = client.admin().indices();
    for (String index : indexes) {
        final IndicesExistsResponse indicesExistsResponse = indicesAdminClient.prepareExists(index).execute().actionGet();
        if (indicesExistsResponse.isExists()) {
            client.admin().indices().prepareDelete(index).execute().actionGet();
        }
        final Messages messages = new Messages(client, new MetricRegistry());
        final Indices indices = new Indices(client, new IndexMapping(), messages, mock(NodeId.class), new NullAuditEventSender());
        if (!indices.create(index, indexSet)) {
            throw new IllegalStateException("Couldn't create index " + index);
        }
    }
    databaseOperation.insert(dataScript);
}
Also used : NullAuditEventSender(org.graylog2.audit.NullAuditEventSender) IndexMapping(org.graylog2.indexer.IndexMapping) Messages(org.graylog2.indexer.messages.Messages) MetricRegistry(com.codahale.metrics.MetricRegistry) IndicesExistsResponse(org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse) NodeId(org.graylog2.plugin.system.NodeId) Indices(org.graylog2.indexer.indices.Indices) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient)

Example 52 with Messages

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

the class DroolsEngineTest method addedRuleIsVisibleInSession.

@Test
public void addedRuleIsVisibleInSession() {
    final DroolsEngine engine = new DroolsEngine(Collections.<URI>emptySet());
    String rule1 = "declare Message\n" + "    @role( event )\n" + "end\n" + "\n" + "rule \"filter out all messages\"\n" + "when\n" + "    $m : Message( filterOut == false )\n" + "then\n" + "    modify($m) { setFilterOut(true) };\n" + "    log.info(\"filtering out message from \" + $m.getSource());\n" + "end\n";
    String rule2 = "declare Message\n" + "    @role( event )\n" + "end\n" + "\n" + "rule \"print filtered out message source\"\n" + "when\n" + "    $m : Message( filterOut == true )\n" + "then\n" + "    log.info(\"message from \" + $m.getSource() + \" filtered out\");\n" + "end\n";
    final boolean valid1 = engine.addRule(rule1);
    assertTrue("Rule should compile without errors", valid1);
    final boolean valid2 = engine.addRule(rule2);
    assertTrue("Rule should compile without errors", valid2);
    final Message msg = new Message("test message", "test source", Tools.nowUTC());
    final int fired = engine.evaluateInSharedSession(msg);
    assertTrue("msg is filtered out", msg.getFilterOut());
    assertEquals("both rules should have fired", fired, 2);
    engine.stop();
}
Also used : Message(org.graylog2.plugin.Message) Test(org.junit.Test)

Example 53 with Messages

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

the class MessageFilterChainProcessorTest method testMessagesCanBeDropped.

@Test
public void testMessagesCanBeDropped() {
    final MessageFilter first = new DummyFilter(10);
    final MessageFilter second = new RemovingMessageFilter();
    final Set<MessageFilter> filters = ImmutableSet.of(first, second);
    final MessageFilterChainProcessor processor = new MessageFilterChainProcessor(new MetricRegistry(), filters, acknowledger, serverStatus);
    final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
    final Messages result = processor.process(message);
    assertThat(result).isEmpty();
}
Also used : Messages(org.graylog2.plugin.Messages) Message(org.graylog2.plugin.Message) MetricRegistry(com.codahale.metrics.MetricRegistry) MessageFilter(org.graylog2.plugin.filters.MessageFilter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 54 with Messages

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

the class MessageFilterChainProcessorTest method testMessagesRecordProcessingFailures.

@Test
public void testMessagesRecordProcessingFailures() {
    final MessageFilter first = new ExceptingMessageFilter();
    final Set<MessageFilter> filters = ImmutableSet.of(first);
    final MessageFilterChainProcessor processor = new MessageFilterChainProcessor(new MetricRegistry(), filters, acknowledger, serverStatus);
    final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
    final Messages result = processor.process(message);
    assertThat(result).hasSize(1);
    // passed message is mutated, so we can assert on that
    assertThat(message.processingErrors()).hasSize(1);
    assertThat(message.processingErrors().get(0)).satisfies(pe -> {
        assertThat(pe.getCause()).isEqualTo(ProcessingFailureCause.MessageFilterException);
        assertThat(pe.getMessage()).startsWith("Could not apply filter [Excepting filter] on message <");
        assertThat(pe.getDetails()).isEqualTo("BOOM!");
    });
}
Also used : Messages(org.graylog2.plugin.Messages) Message(org.graylog2.plugin.Message) MetricRegistry(com.codahale.metrics.MetricRegistry) MessageFilter(org.graylog2.plugin.filters.MessageFilter) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 55 with Messages

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

the class MessageFilterChainProcessorTest method testHandleMessage.

@Test
public void testHandleMessage() {
    MessageFilter filterOnlyFirst = new MessageFilter() {

        private boolean filterOut = true;

        @Override
        public boolean filter(Message msg) {
            if (filterOut) {
                msg.setFilterOut(true);
                filterOut = false;
                return true;
            }
            return false;
        }

        @Override
        public String getName() {
            return "first filtered out, subsequent pass";
        }

        @Override
        public int getPriority() {
            return 0;
        }
    };
    final MessageFilterChainProcessor filterTest = new MessageFilterChainProcessor(new MetricRegistry(), Collections.singleton(filterOnlyFirst), acknowledger, serverStatus);
    Message filteredoutMessage = new Message("filtered out", "source", Tools.nowUTC());
    filteredoutMessage.setJournalOffset(1);
    Message unfilteredMessage = new Message("filtered out", "source", Tools.nowUTC());
    final Messages messages1 = filterTest.process(filteredoutMessage);
    final Messages messages2 = filterTest.process(unfilteredMessage);
    Assert.assertTrue(filteredoutMessage.getFilterOut());
    Assert.assertFalse(unfilteredMessage.getFilterOut());
    Assert.assertEquals(0, Iterables.size(messages1));
    Assert.assertEquals(1, Iterables.size(messages2));
}
Also used : Messages(org.graylog2.plugin.Messages) Message(org.graylog2.plugin.Message) MetricRegistry(com.codahale.metrics.MetricRegistry) MessageFilter(org.graylog2.plugin.filters.MessageFilter) Test(org.junit.Test)

Aggregations

Message (org.graylog2.plugin.Message)41 Test (org.junit.Test)31 DateTime (org.joda.time.DateTime)17 Map (java.util.Map)15 ApiOperation (io.swagger.annotations.ApiOperation)14 Produces (javax.ws.rs.Produces)14 Timed (com.codahale.metrics.annotation.Timed)13 ApiResponses (io.swagger.annotations.ApiResponses)12 Messages (org.graylog2.plugin.Messages)12 List (java.util.List)11 GET (javax.ws.rs.GET)11 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)11 ResultMessage (org.graylog2.indexer.results.ResultMessage)10 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)10 ArrayList (java.util.ArrayList)9 Collectors (java.util.stream.Collectors)9 ResultMessageSummary (org.graylog2.rest.models.messages.responses.ResultMessageSummary)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 IOException (java.io.IOException)8 Inject (javax.inject.Inject)8