use of org.graylog2.inputs.extractors.GrokExtractor in project graylog2-server by Graylog2.
the class GrokExtractorTest method testNamedCapturesOnly.
@Test
public void testNamedCapturesOnly() {
final Map<String, Object> config = new HashMap<>();
final GrokPattern mynumber = GrokPattern.create("MYNUMBER", "(?:%{BASE10NUM})");
patternSet.add(mynumber);
config.put("named_captures_only", true);
final GrokExtractor extractor1 = makeExtractor("%{MYNUMBER:num}", config);
config.put("named_captures_only", true);
final GrokExtractor extractor2 = makeExtractor("%{MYNUMBER:num;int}", config);
config.put("named_captures_only", false);
final GrokExtractor extractor3 = makeExtractor("%{MYNUMBER:num}", config);
final GrokExtractor extractor4 = makeExtractor("%{MYNUMBER:num}");
assertThat(extractor1.run("2015")).hasSize(1).containsOnly(new Extractor.Result("2015", "num", -1, -1));
assertThat(extractor2.run("2015")).hasSize(1).containsOnly(new Extractor.Result(2015, "num", -1, -1));
assertThat(extractor3.run("2015")).hasSize(2).containsOnly(new Extractor.Result("2015", "num", -1, -1), new Extractor.Result("2015", "BASE10NUM", -1, -1));
assertThat(extractor4.run("2015")).hasSize(2).containsOnly(new Extractor.Result("2015", "num", -1, -1), new Extractor.Result("2015", "BASE10NUM", -1, -1));
}
use of org.graylog2.inputs.extractors.GrokExtractor 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.inputs.extractors.GrokExtractor in project graylog2-server by Graylog2.
the class InputFacadeTest method resolveForInstallationGrokPattern.
@Test
@MongoDBFixtures("InputFacadeTest.json")
public void resolveForInstallationGrokPattern() throws NotFoundException {
final Input input = inputService.find("5ae2ebbeef27464477f0fd8b");
final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
final GrokExtractor grokExtractor = (GrokExtractor) inputWithExtractors.extractors().iterator().next();
final ExtractorEntity extractorEntity = ExtractorEntity.create(ValueReference.of(grokExtractor.getTitle()), ValueReference.of(grokExtractor.getType()), ValueReference.of(grokExtractor.getCursorStrategy()), ValueReference.of(grokExtractor.getTargetField()), ValueReference.of(grokExtractor.getSourceField()), ReferenceMapUtils.toReferenceMap(grokExtractor.getExtractorConfig()), Collections.emptyList(), ValueReference.of(grokExtractor.getConditionType()), ValueReference.of(grokExtractor.getConditionValue()), ValueReference.of(grokExtractor.getOrder()));
List<ExtractorEntity> extractorEntities = new ArrayList<>(1);
extractorEntities.add(extractorEntity);
InputEntity inputEntity = InputEntity.create(ValueReference.of(input.getTitle()), ReferenceMapUtils.toReferenceMap(input.getConfiguration()), Collections.emptyMap(), ValueReference.of(input.getType()), ValueReference.of(input.isGlobal()), extractorEntities);
Entity entity = EntityV1.builder().id(ModelId.of(input.getId())).type(ModelTypes.INPUT_V1).data(objectMapper.convertValue(inputEntity, JsonNode.class)).build();
final GrokPatternEntity grokPatternEntity = GrokPatternEntity.create("GREEDY", ".*");
final Entity expectedEntity = EntityV1.builder().id(ModelId.of("dead-feed")).data(objectMapper.convertValue(grokPatternEntity, JsonNode.class)).type(ModelTypes.GROK_PATTERN_V1).build();
final EntityDescriptor entityDescriptor = expectedEntity.toEntityDescriptor();
final Map<EntityDescriptor, Entity> entities = new HashMap<>(1);
entities.put(entityDescriptor, expectedEntity);
Graph<Entity> graph = facade.resolveForInstallation(entity, Collections.emptyMap(), entities);
assertThat(graph.nodes()).contains(expectedEntity);
}
Aggregations