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