Search in sources :

Example 36 with MessageInput

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

the class InputFacadeTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
    final MetricRegistry metricRegistry = new MetricRegistry();
    final ClusterEventBus clusterEventBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
    final GrokPatternService grokPatternService = new InMemoryGrokPatternService(clusterEventBus);
    grokPatternService.save(GrokPattern.create("GREEDY", ".*"));
    final EventBus clusterBus = new EventBus();
    final GrokPatternRegistry grokPatternRegistry = new GrokPatternRegistry(clusterBus, grokPatternService, Executors.newScheduledThreadPool(1));
    final ExtractorFactory extractorFactory = new ExtractorFactory(metricRegistry, grokPatternRegistry, lookupTableService);
    final ConverterFactory converterFactory = new ConverterFactory(lookupTableService);
    inputService = new InputServiceImpl(mongodb.mongoConnection(), extractorFactory, converterFactory, messageInputFactory, clusterEventBus);
    final InputRegistry inputRegistry = new InputRegistry();
    Set<PluginMetaData> pluginMetaData = new HashSet<>();
    Map<String, MessageInput.Factory<? extends MessageInput>> inputFactories = new HashMap<>();
    final FakeHttpMessageInput.Factory fakeHttpMessageInputFactory = mock(FakeHttpMessageInput.Factory.class);
    final FakeHttpMessageInput.Descriptor fakeHttpMessageInputDescriptor = mock(FakeHttpMessageInput.Descriptor.class);
    when(fakeHttpMessageInputFactory.getDescriptor()).thenReturn(fakeHttpMessageInputDescriptor);
    final RawUDPInput.Factory rawUDPInputFactory = mock(RawUDPInput.Factory.class);
    final RawUDPInput.Descriptor rawUDPInputDescriptor = mock(RawUDPInput.Descriptor.class);
    when(rawUDPInputFactory.getDescriptor()).thenReturn(rawUDPInputDescriptor);
    inputFactories.put("org.graylog2.inputs.random.FakeHttpMessageInput", fakeHttpMessageInputFactory);
    inputFactories.put("org.graylog2.inputs.raw.udp.RawUDPInput", rawUDPInputFactory);
    facade = new InputFacade(objectMapper, inputService, inputRegistry, dbLookupTableService, grokPatternService, messageInputFactory, extractorFactory, converterFactory, serverStatus, pluginMetaData, inputFactories);
}
Also used : HashMap(java.util.HashMap) InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) PluginMetaData(org.graylog2.plugin.PluginMetaData) MessageInputFactory(org.graylog2.shared.inputs.MessageInputFactory) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ClusterEventBus(org.graylog2.events.ClusterEventBus) EventBus(com.google.common.eventbus.EventBus) InputRegistry(org.graylog2.shared.inputs.InputRegistry) InputServiceImpl(org.graylog2.inputs.InputServiceImpl) GrokPatternService(org.graylog2.grok.GrokPatternService) InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) GrokPatternRegistry(org.graylog2.grok.GrokPatternRegistry) HashSet(java.util.HashSet) MetricRegistry(com.codahale.metrics.MetricRegistry) ClusterEventBus(org.graylog2.events.ClusterEventBus) FakeHttpMessageInput(org.graylog2.inputs.random.FakeHttpMessageInput) RawUDPInput(org.graylog2.inputs.raw.udp.RawUDPInput) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 37 with MessageInput

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

the class UdpTransportTest method launchTransportForBootStrapTest.

private UdpTransport launchTransportForBootStrapTest(final ChannelInboundHandler channelHandler) throws MisfireException {
    final UdpTransport transport = new UdpTransport(CONFIGURATION, eventLoopGroupFactory, nettyTransportConfiguration, throughputCounter, new LocalMetricRegistry()) {

        @Override
        protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getChannelHandlers(MessageInput input) {
            final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
            handlers.put("logging", () -> new LoggingHandler(LogLevel.INFO));
            handlers.put("counter", () -> channelHandler);
            handlers.putAll(super.getChannelHandlers(input));
            return handlers;
        }
    };
    final MessageInput messageInput = mock(MessageInput.class);
    when(messageInput.getId()).thenReturn("TEST");
    when(messageInput.getName()).thenReturn("TEST");
    transport.launch(messageInput);
    return transport;
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) MessageInput(org.graylog2.plugin.inputs.MessageInput) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with MessageInput

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

the class InputEventListenerTest method inputUpdatedStopsInputIfItIsRunning.

@Test
public void inputUpdatedStopsInputIfItIsRunning() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    @SuppressWarnings("unchecked") final IOState<MessageInput> inputState = mock(IOState.class);
    when(inputService.find(inputId)).thenReturn(input);
    when(inputRegistry.getInputState(inputId)).thenReturn(inputState);
    listener.inputUpdated(InputUpdated.create(inputId));
    verify(inputRegistry, times(1)).remove(inputState);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Example 39 with MessageInput

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

the class InputEventListenerTest method inputCreatedDoesNotStartLocalInputOnAnyNode.

@Test
public void inputCreatedDoesNotStartLocalInputOnAnyNode() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    when(inputService.find(inputId)).thenReturn(input);
    when(nodeId.toString()).thenReturn("node-id");
    when(input.getNodeId()).thenReturn("other-node-id");
    when(input.isGlobal()).thenReturn(false);
    final MessageInput messageInput = mock(MessageInput.class);
    when(inputService.getMessageInput(input)).thenReturn(messageInput);
    listener.inputCreated(InputCreated.create(inputId));
    verify(inputLauncher, never()).launch(messageInput);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Example 40 with MessageInput

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

the class InputEventListenerTest method inputUpdatedDoesNotStartLocalInputOnLocalNodeIfItWasNotRunning.

@Test
public void inputUpdatedDoesNotStartLocalInputOnLocalNodeIfItWasNotRunning() throws Exception {
    final String inputId = "input-id";
    final Input input = mock(Input.class);
    @SuppressWarnings("unchecked") final IOState<MessageInput> inputState = mock(IOState.class);
    when(inputState.getState()).thenReturn(IOState.Type.STOPPED);
    when(inputService.find(inputId)).thenReturn(input);
    when(inputRegistry.getInputState(inputId)).thenReturn(inputState);
    when(nodeId.toString()).thenReturn("node-id");
    when(input.getNodeId()).thenReturn("node-id");
    when(input.isGlobal()).thenReturn(false);
    final MessageInput messageInput = mock(MessageInput.class);
    when(inputService.getMessageInput(input)).thenReturn(messageInput);
    listener.inputUpdated(InputUpdated.create(inputId));
    verify(inputLauncher, never()).launch(messageInput);
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput) Test(org.junit.Test)

Aggregations

MessageInput (org.graylog2.plugin.inputs.MessageInput)47 Test (org.junit.Test)18 Callable (java.util.concurrent.Callable)17 NotFoundException (org.graylog2.database.NotFoundException)10 Configuration (org.graylog2.plugin.configuration.Configuration)9 ChannelHandler (io.netty.channel.ChannelHandler)8 LinkedHashMap (java.util.LinkedHashMap)8 Input (org.graylog2.inputs.Input)8 MisfireException (org.graylog2.plugin.inputs.MisfireException)7 ChannelHandler (org.jboss.netty.channel.ChannelHandler)7 Timed (com.codahale.metrics.annotation.Timed)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 EventBus (com.google.common.eventbus.EventBus)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 Subscribe (com.google.common.eventbus.Subscribe)4 Produces (javax.ws.rs.Produces)4 IOState (org.graylog2.plugin.IOState)4 LocalMetricRegistry (org.graylog2.plugin.LocalMetricRegistry)4 Extractor (org.graylog2.plugin.inputs.Extractor)4