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);
}
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();
}
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();
}
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!");
});
}
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));
}
Aggregations