Search in sources :

Example 1 with InputService

use of org.graylog2.inputs.InputService 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 2 with InputService

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

the class ExtractorFilterTest method testFailureHandling.

@Test
void testFailureHandling() throws NotFoundException {
    final Input input = mock(Input.class);
    when(input.getId()).thenReturn("123");
    when(inputService.all()).thenReturn(ImmutableList.of(input));
    final Extractor extractor = buildExceptionalExtractor();
    when(extractor.getTitle()).thenReturn("failing extractor");
    when(extractor.getId()).thenReturn("888");
    when(inputService.getExtractors(any())).thenReturn(ImmutableList.of(extractor));
    // extractors are initialized within constructor
    dut = new ExtractorFilter(inputService, eventBus, executorService);
    final Message message = new Message("message", "source", new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC));
    message.setSourceInputId("123");
    dut.filter(message);
    assertThat(message.processingErrors()).hasSize(1);
    assertThat(message.processingErrors().get(0)).satisfies(pe -> {
        assertThat(pe.getCause()).isEqualTo(ProcessingFailureCause.ExtractorException);
        assertThat(pe.getMessage()).isEqualTo("Could not apply extractor <failing extractor(888)>");
        assertThat(pe.getDetails()).isEqualTo("EIEIO!");
    });
}
Also used : Input(org.graylog2.inputs.Input) Message(org.graylog2.plugin.Message) Extractor(org.graylog2.plugin.inputs.Extractor) DateTime(org.joda.time.DateTime) Test(org.junit.jupiter.api.Test)

Example 3 with InputService

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

the class StaticFieldFilterTest method testFilter.

@Test
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void testFilter() throws Exception {
    Message msg = new Message("hello", "junit", Tools.nowUTC());
    msg.setSourceInputId("someid");
    when(input.getId()).thenReturn("someid");
    when(inputService.all()).thenReturn(Collections.singletonList(input));
    when(inputService.find(eq("someid"))).thenReturn(input);
    when(inputService.getStaticFields(eq(input))).thenReturn(Collections.singletonList(Maps.immutableEntry("foo", "bar")));
    final StaticFieldFilter filter = new StaticFieldFilter(inputService, new EventBus(), Executors.newSingleThreadScheduledExecutor());
    filter.filter(msg);
    assertEquals("hello", msg.getMessage());
    assertEquals("junit", msg.getSource());
    assertEquals("bar", msg.getField("foo"));
}
Also used : Message(org.graylog2.plugin.Message) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 4 with InputService

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

the class MongoInputStatusServiceTest method setUp.

@Before
public void setUp() {
    final ObjectMapper objectMapper = new ObjectMapperProvider().get();
    final MongoJackObjectMapperProvider mapperProvider = new MongoJackObjectMapperProvider(objectMapper);
    cut = new MongoInputStatusService(mongodb.mongoConnection(), mapperProvider, inputService, mockEventBus);
    db = JacksonDBCollection.wrap(mongodb.mongoConnection().getDatabase().getCollection(MongoInputStatusService.COLLECTION_NAME), InputStatusRecord.class, ObjectId.class, mapperProvider.get());
}
Also used : ObjectId(org.bson.types.ObjectId) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ObjectMapperProvider(org.graylog2.shared.bindings.providers.ObjectMapperProvider) Before(org.junit.Before)

Example 5 with InputService

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

the class InputServiceImplTest method setUp.

@Before
@SuppressForbidden("Executors#newSingleThreadExecutor() is okay for tests")
public void setUp() throws Exception {
    clusterEventBus = new ClusterEventBus("inputs-test", Executors.newSingleThreadExecutor());
    inputService = new InputServiceImpl(mongodb.mongoConnection(), extractorFactory, converterFactory, messageInputFactory, clusterEventBus);
}
Also used : ClusterEventBus(org.graylog2.events.ClusterEventBus) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Aggregations

SuppressForbidden (org.graylog2.shared.SuppressForbidden)4 EventBus (com.google.common.eventbus.EventBus)3 Message (org.graylog2.plugin.Message)3 Before (org.junit.Before)3 ClusterEventBus (org.graylog2.events.ClusterEventBus)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ObjectId (org.bson.types.ObjectId)1 MongoJackObjectMapperProvider (org.graylog2.bindings.providers.MongoJackObjectMapperProvider)1 GrokPatternRegistry (org.graylog2.grok.GrokPatternRegistry)1 GrokPatternService (org.graylog2.grok.GrokPatternService)1 InMemoryGrokPatternService (org.graylog2.grok.InMemoryGrokPatternService)1 Input (org.graylog2.inputs.Input)1 InputServiceImpl (org.graylog2.inputs.InputServiceImpl)1 ConverterFactory (org.graylog2.inputs.converters.ConverterFactory)1 ExtractorFactory (org.graylog2.inputs.extractors.ExtractorFactory)1 FakeHttpMessageInput (org.graylog2.inputs.random.FakeHttpMessageInput)1