Search in sources :

Example 6 with GrokPatternService

use of org.graylog2.grok.GrokPatternService in project graylog2-server by Graylog2.

the class GrokResourceTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() {
    paginatedGrokPatternService = mock(PaginatedGrokPatternService.class);
    final ClusterEventBus clusterBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
    grokPatternService = new InMemoryGrokPatternService(clusterBus);
    subscriber = new GrokPatternsChangedEventSubscriber();
    clusterBus.registerClusterEventSubscriber(subscriber);
    grokResource = new PermittedTestResource(grokPatternService, paginatedGrokPatternService);
}
Also used : InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) PaginatedGrokPatternService(org.graylog2.grok.PaginatedGrokPatternService) ClusterEventBus(org.graylog2.events.ClusterEventBus) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 7 with GrokPatternService

use of org.graylog2.grok.GrokPatternService in project graylog2-server by Graylog2.

the class GrokExtractorTest method makeExtractor.

@SuppressForbidden("Allow using default thread factory")
private GrokExtractor makeExtractor(String pattern, Map<String, Object> config) {
    config.put("grok_pattern", pattern);
    final ClusterEventBus clusterEventBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
    final EventBus clusterBus = new EventBus();
    final GrokPatternService grokPatternService = new InMemoryGrokPatternService(clusterEventBus);
    try {
        grokPatternService.saveAll(patternSet, DROP_ALL_EXISTING);
    } catch (Exception e) {
        fail("Could not save grok patter: " + e.getMessage());
    }
    final GrokPatternRegistry grokPatternRegistry = new GrokPatternRegistry(clusterBus, grokPatternService, Executors.newScheduledThreadPool(1));
    try {
        return new GrokExtractor(new LocalMetricRegistry(), grokPatternRegistry, "id", "title", 0, Extractor.CursorStrategy.COPY, "message", "message", config, "admin", Lists.newArrayList(), Extractor.ConditionType.NONE, null);
    } catch (Extractor.ReservedFieldException | ConfigurationException e) {
        fail("Test setup is wrong: " + e.getMessage());
        throw new RuntimeException(e);
    }
}
Also used : ConfigurationException(org.graylog2.ConfigurationException) InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) GrokPatternService(org.graylog2.grok.GrokPatternService) InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) GrokPatternRegistry(org.graylog2.grok.GrokPatternRegistry) EventBus(com.google.common.eventbus.EventBus) ClusterEventBus(org.graylog2.events.ClusterEventBus) ClusterEventBus(org.graylog2.events.ClusterEventBus) ConfigurationException(org.graylog2.ConfigurationException) LocalMetricRegistry(org.graylog2.plugin.LocalMetricRegistry) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 8 with GrokPatternService

use of org.graylog2.grok.GrokPatternService in project graylog2-server by Graylog2.

the class GrokTesterResourceTest method setUp.

@Before
@SuppressForbidden("Using Executors.newSingleThreadExecutor() is okay in tests")
public void setUp() throws Exception {
    final ClusterEventBus clusterEventBus = new ClusterEventBus("cluster-event-bus", Executors.newSingleThreadExecutor());
    final InMemoryGrokPatternService grokPatternService = new InMemoryGrokPatternService(clusterEventBus);
    grokPatternService.save(GrokPattern.create("NUMBER", "[0-9]+"));
    resource = new GrokTesterResource(grokPatternService);
}
Also used : InMemoryGrokPatternService(org.graylog2.grok.InMemoryGrokPatternService) ClusterEventBus(org.graylog2.events.ClusterEventBus) Before(org.junit.Before) SuppressForbidden(org.graylog2.shared.SuppressForbidden)

Example 9 with GrokPatternService

use of org.graylog2.grok.GrokPatternService in project graylog2-server by Graylog2.

the class V20191121145100_FixDefaultGrokPatternsTest method patternWasModified.

@Test
public void patternWasModified() throws ValidationException {
    final GrokPattern pattern = GrokPattern.builder().name(PATTERN_NAME).pattern("modified").build();
    when(grokPatternService.loadByName(PATTERN_NAME)).thenReturn(Optional.of(pattern));
    migration.upgrade();
    verify(grokPatternService, never()).update(any(GrokPattern.class));
    verify(configService).write(MigrationCompleted.create(Collections.singleton(PATTERN_NAME)));
}
Also used : GrokPattern(org.graylog2.grok.GrokPattern) Test(org.junit.Test)

Example 10 with GrokPatternService

use of org.graylog2.grok.GrokPatternService in project graylog2-server by Graylog2.

the class InputFacade method resolveNativeEntityGrokPattern.

private void resolveNativeEntityGrokPattern(EntityDescriptor entityDescriptor, InputWithExtractors inputWithExtractors, MutableGraph<EntityDescriptor> mutableGraph) {
    inputWithExtractors.extractors().stream().filter(e -> e.getType().equals(Extractor.Type.GROK)).map(e -> (String) e.getExtractorConfig().get(GrokExtractor.CONFIG_GROK_PATTERN)).map(GrokPatternService::extractPatternNames).flatMap(Collection::stream).forEach(patternName -> {
        grokPatternService.loadByName(patternName).ifPresent(depPattern -> {
            final EntityDescriptor depEntityDescriptor = EntityDescriptor.create(depPattern.id(), ModelTypes.GROK_PATTERN_V1);
            mutableGraph.putEdge(entityDescriptor, depEntityDescriptor);
        });
    });
}
Also used : Extractor(org.graylog2.plugin.inputs.Extractor) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Tools(org.graylog2.plugin.Tools) InputService(org.graylog2.inputs.InputService) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) LoggerFactory(org.slf4j.LoggerFactory) ModelType(org.graylog2.contentpacks.model.ModelType) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) InputRegistry(org.graylog2.shared.inputs.InputRegistry) MessageInputFactory(org.graylog2.shared.inputs.MessageInputFactory) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ImmutableSet(com.google.common.collect.ImmutableSet) ModelId(org.graylog2.contentpacks.model.ModelId) GrokPatternService(org.graylog2.grok.GrokPatternService) ImmutableMap(com.google.common.collect.ImmutableMap) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) Set(java.util.Set) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) ServerStatus(org.graylog2.plugin.ServerStatus) ReferenceMapUtils.toReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) List(java.util.List) Stream(java.util.stream.Stream) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) PluginMetaData(org.graylog2.plugin.PluginMetaData) Optional(java.util.Optional) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) Configuration(org.graylog2.plugin.configuration.Configuration) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Converter(org.graylog2.plugin.inputs.Converter) Entity(org.graylog2.contentpacks.model.entities.Entity) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) DBLookupTableService(org.graylog2.lookup.db.DBLookupTableService) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Input(org.graylog2.inputs.Input) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) NotFoundException(org.graylog2.database.NotFoundException) ReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMap) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) Ints(com.google.common.primitives.Ints) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Message(org.graylog2.plugin.Message) ReferenceMapUtils.toValueMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toValueMap) Graph(com.google.common.graph.Graph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) GrokPatternService(org.graylog2.grok.GrokPatternService)

Aggregations

SuppressForbidden (org.graylog2.shared.SuppressForbidden)6 ClusterEventBus (org.graylog2.events.ClusterEventBus)5 GrokPatternService (org.graylog2.grok.GrokPatternService)5 InMemoryGrokPatternService (org.graylog2.grok.InMemoryGrokPatternService)5 Before (org.junit.Before)4 EventBus (com.google.common.eventbus.EventBus)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Optional (java.util.Optional)2 GrokPattern (org.graylog2.grok.GrokPattern)2 GrokPatternRegistry (org.graylog2.grok.GrokPatternRegistry)2 MigrationCompleted (org.graylog2.migrations.V20191121145100_FixDefaultGrokPatterns.MigrationCompleted)2 Test (org.junit.Test)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Graph (com.google.common.graph.Graph)1