Search in sources :

Example 1 with MessageOutput

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

the class MessageOutputFactory method getAvailableOutputs.

public Map<String, AvailableOutputSummary> getAvailableOutputs() {
    final Map<String, AvailableOutputSummary> result = new HashMap<>(availableOutputs.size());
    for (Map.Entry<String, MessageOutput.Factory<? extends MessageOutput>> messageOutputEntry : this.availableOutputs.entrySet()) {
        final MessageOutput.Factory messageOutputFactoryClass = messageOutputEntry.getValue();
        final MessageOutput.Descriptor descriptor = messageOutputFactoryClass.getDescriptor();
        final AvailableOutputSummary availableOutputSummary = AvailableOutputSummary.create(descriptor.getName(), messageOutputEntry.getKey(), descriptor.getHumanName(), descriptor.getLinkToDocs(), messageOutputFactoryClass.getConfig().getRequestedConfiguration());
        result.put(messageOutputEntry.getKey(), availableOutputSummary);
    }
    return result;
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) HashMap(java.util.HashMap) AvailableOutputSummary(org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with MessageOutput

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

the class OutputRouterTest method testGetOutputsFromTwoStreams.

@Test
public void testGetOutputsFromTwoStreams() throws Exception {
    final Stream stream1 = mock(Stream.class);
    final Stream stream2 = mock(Stream.class);
    final MessageOutput messageOutput1 = mock(MessageOutput.class);
    final Set<MessageOutput> messageOutputSet1 = ImmutableSet.of(messageOutput1);
    final MessageOutput messageOutput2 = mock(MessageOutput.class);
    final Set<MessageOutput> messageOutputSet2 = ImmutableSet.of(messageOutput2);
    final Message message = mock(Message.class);
    when(message.getStreams()).thenReturn(ImmutableSet.of(stream1, stream2));
    OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
    doReturn(messageOutputSet1).when(outputRouter).getMessageOutputsForStream(eq(stream1));
    doReturn(messageOutputSet2).when(outputRouter).getMessageOutputsForStream(eq(stream2));
    final Collection<MessageOutput> result = outputRouter.getOutputsForMessage(message);
    assertEquals(result.size(), 3);
    assertTrue(result.contains(defaultMessageOutput));
    assertTrue(result.contains(messageOutput1));
    assertTrue(result.contains(messageOutput2));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Message(org.graylog2.plugin.Message) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 3 with MessageOutput

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

the class OutputRouterTest method testGetOutputFromSingleStreams.

@Test
public void testGetOutputFromSingleStreams() throws Exception {
    final Stream stream = mock(Stream.class);
    final Message message = mock(Message.class);
    when(message.getStreams()).thenReturn(ImmutableSet.of(stream));
    final MessageOutput messageOutput = mock(MessageOutput.class);
    final Set<MessageOutput> messageOutputList = ImmutableSet.of(messageOutput);
    final OutputRouter outputRouter = Mockito.spy(new OutputRouter(defaultMessageOutput, outputRegistry));
    doReturn(messageOutputList).when(outputRouter).getMessageOutputsForStream(eq(stream));
    // Call to test
    final Collection<MessageOutput> messageOutputs = outputRouter.getOutputsForMessage(message);
    // Verification
    assertEquals(messageOutputs.size(), 2);
    assertTrue(messageOutputs.contains(defaultMessageOutput));
    assertTrue(messageOutputs.contains(messageOutput));
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Message(org.graylog2.plugin.Message) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 4 with MessageOutput

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

the class OutputRegistryTest method testNonExistingInput.

@Test
public void testNonExistingInput() throws Exception {
    final String outputId = "foobar";
    final Stream stream = mock(Stream.class);
    when(outputService.load(eq(outputId))).thenThrow(NotFoundException.class);
    final OutputRegistry outputRegistry = new OutputRegistry(null, outputService, null, null, null, FAULT_COUNT_THRESHOLD, FAULT_PENALTY_SECONDS);
    MessageOutput messageOutput = outputRegistry.getOutputForIdAndStream(outputId, stream);
    assertNull(messageOutput);
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 5 with MessageOutput

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

the class OutputRegistryTest method testInvalidOutputConfiguration.

@Test
public void testInvalidOutputConfiguration() throws Exception {
    final String outputId = "foobar";
    final Stream stream = mock(Stream.class);
    when(messageOutputFactory.fromStreamOutput(eq(output), any(Stream.class), any(Configuration.class))).thenThrow(new MessageOutputConfigurationException());
    when(outputService.load(eq(outputId))).thenReturn(output);
    final OutputRegistry outputRegistry = new OutputRegistry(null, outputService, messageOutputFactory, null, null, FAULT_COUNT_THRESHOLD, FAULT_PENALTY_SECONDS);
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
    MessageOutput result = outputRegistry.getOutputForIdAndStream(outputId, stream);
    assertNull(result);
    assertEquals(outputRegistry.getRunningMessageOutputs().size(), 0);
}
Also used : MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Configuration(org.graylog2.plugin.configuration.Configuration) MessageOutputConfigurationException(org.graylog2.plugin.outputs.MessageOutputConfigurationException) Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Aggregations

MessageOutput (org.graylog2.plugin.outputs.MessageOutput)15 Test (org.junit.Test)10 Stream (org.graylog2.plugin.streams.Stream)9 Message (org.graylog2.plugin.Message)5 Configuration (org.graylog2.plugin.configuration.Configuration)2 Output (org.graylog2.plugin.streams.Output)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BlockingBatchedESOutput (org.graylog2.outputs.BlockingBatchedESOutput)1 DefaultMessageOutput (org.graylog2.outputs.DefaultMessageOutput)1 MessageOutputConfigurationException (org.graylog2.plugin.outputs.MessageOutputConfigurationException)1 AvailableOutputSummary (org.graylog2.rest.resources.streams.outputs.AvailableOutputSummary)1