use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokResource method bulkUpdatePatternsFromTextFile.
@POST
@Consumes(MediaType.TEXT_PLAIN)
@Timed
@ApiOperation("Add a list of new patterns")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_IMPORT_CREATE)
public Response bulkUpdatePatternsFromTextFile(@ApiParam(name = "patterns", required = true) @NotNull InputStream patternsFile, // deprecated. used to drop all existing patterns before import
@Deprecated @QueryParam("replace") @DefaultValue("false") boolean deprecatedDropAllExisting, @ApiParam(name = "import-strategy", value = "Strategy to apply when importing.") @QueryParam("import-strategy") ImportStrategy importStrategy) throws ValidationException, IOException {
checkPermission(RestPermissions.INPUTS_CREATE);
final List<GrokPattern> grokPatterns = readGrokPatterns(patternsFile);
if (!grokPatterns.isEmpty()) {
try {
if (!grokPatternService.validateAll(grokPatterns)) {
throw new ValidationException("Invalid pattern contained. Did not save any patterns.");
}
} catch (GrokException | IllegalArgumentException e) {
throw new ValidationException("Invalid pattern. Did not save any patterns\n" + e.getMessage());
}
ImportStrategy resolvedStrategy = importStrategy != null ? importStrategy : deprecatedDropAllExisting ? ImportStrategy.DROP_ALL_EXISTING : ImportStrategy.ABORT_ON_CONFLICT;
grokPatternService.saveAll(grokPatterns, resolvedStrategy);
}
return Response.accepted().build();
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method createExcerpt.
@Test
public void createExcerpt() {
final GrokPattern grokPattern = GrokPattern.create("01234567890", "name", "pattern", null);
final EntityExcerpt excerpt = facade.createExcerpt(grokPattern);
assertThat(excerpt.id()).isEqualTo(ModelId.of("01234567890"));
assertThat(excerpt.type()).isEqualTo(ModelTypes.GROK_PATTERN_V1);
assertThat(excerpt.title()).isEqualTo(grokPattern.name());
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() throws NotFoundException {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final NativeEntity<GrokPattern> nativeEntity = facade.createNativeEntity(grokPatternEntity, Collections.emptyMap(), Collections.emptyMap(), "admin");
final GrokPattern expectedGrokPattern = GrokPattern.create("1", "Test", "[a-z]+", null);
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create("1", "1", ModelTypes.GROK_PATTERN_V1, "Test");
assertThat(nativeEntity.descriptor().title()).isEqualTo(expectedDescriptor.title());
assertThat(nativeEntity.descriptor().type()).isEqualTo(expectedDescriptor.type());
assertThat(nativeEntity.entity()).isEqualTo(expectedGrokPattern);
assertThat(grokPatternService.load("1")).isEqualTo(expectedGrokPattern);
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method findExisting.
@Test
public void findExisting() throws ValidationException {
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test", "[a-z]+"));
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final Optional<NativeEntity<GrokPattern>> existingGrokPattern = facade.findExisting(grokPatternEntity, Collections.emptyMap());
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create(grokPatternEntity.id(), "1", ModelTypes.GROK_PATTERN_V1, grokPattern.name(), false);
assertThat(existingGrokPattern).isPresent().get().satisfies(nativeEntity -> {
assertThat(nativeEntity.descriptor()).isEqualTo(expectedDescriptor);
assertThat(nativeEntity.entity()).isEqualTo(grokPattern);
});
}
use of org.graylog2.grok.GrokPattern in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method resolveEntityDescriptor.
@Test
public void resolveEntityDescriptor() throws ValidationException {
final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test1", "[a-z]+"));
final EntityDescriptor descriptor = EntityDescriptor.create(grokPattern.id(), ModelTypes.GROK_PATTERN_V1);
final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(descriptor);
assertThat(graph.nodes()).containsOnly(descriptor);
}
Aggregations