Search in sources :

Example 76 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class GrokPatternFacadeTest method delete.

@Test
public void delete() throws ValidationException {
    final GrokPattern grokPattern = grokPatternService.save(GrokPattern.create("Test1", "[a-z]+"));
    grokPatternService.save(GrokPattern.create("Test2", "[a-z]+"));
    assertThat(grokPatternService.loadAll()).hasSize(2);
    facade.delete(grokPattern);
    assertThat(grokPatternService.loadAll()).hasSize(1);
}
Also used : GrokPattern(org.graylog2.grok.GrokPattern) Test(org.junit.Test)

Example 77 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class GrokPatternFacadeTest method findExistingFailsWithDivergingPatterns.

@Test
public void findExistingFailsWithDivergingPatterns() throws ValidationException {
    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", "BOOM"), JsonNode.class)).build();
    assertThatThrownBy(() -> facade.findExisting(grokPatternEntity, Collections.emptyMap())).isInstanceOf(DivergingEntityConfigurationException.class).hasMessage("Expected Grok pattern for name \"Test\": <BOOM>; actual Grok pattern: <[a-z]+>");
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) DivergingEntityConfigurationException(org.graylog2.contentpacks.exceptions.DivergingEntityConfigurationException) Test(org.junit.Test)

Example 78 with ValidationException

use of org.graylog2.plugin.database.ValidationException 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 79 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class InputFacade method addExtractor.

private Extractor addExtractor(final Input input, final String title, final int order, final Extractor.CursorStrategy cursorStrategy, final Extractor.Type type, final String sourceField, final String targetField, final Map<String, Object> configuration, final List<Converter> converters, final Extractor.ConditionType conditionType, final String conditionValue, final String username) throws ValidationException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, Extractor.ReservedFieldException {
    final String extractorId = UUID.randomUUID().toString();
    final Extractor extractor = extractorFactory.factory(extractorId, title, order, cursorStrategy, type, sourceField, targetField, configuration, username, converters, conditionType, conditionValue);
    inputService.addExtractor(input, extractor);
    return extractor;
}
Also used : Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor)

Example 80 with ValidationException

use of org.graylog2.plugin.database.ValidationException in project graylog2-server by Graylog2.

the class InputFacade method createExtractors.

private List<Extractor> createExtractors(final Input input, final List<ExtractorEntity> extractorEntities, final String username, final Map<String, ValueReference> parameters) throws Extractor.ReservedFieldException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, ValidationException {
    final ImmutableList.Builder<Extractor> result = ImmutableList.builder();
    for (ExtractorEntity extractorEntity : extractorEntities) {
        final List<Converter> converters = createConverters(extractorEntity.converters(), parameters);
        final Extractor extractor = addExtractor(input, extractorEntity.title().asString(parameters), extractorEntity.order().asInteger(parameters), extractorEntity.cursorStrategy().asEnum(parameters, Extractor.CursorStrategy.class), extractorEntity.type().asEnum(parameters, Extractor.Type.class), extractorEntity.sourceField().asString(parameters), extractorEntity.targetField().asString(parameters), toValueMap(extractorEntity.configuration(), parameters), converters, extractorEntity.conditionType().asEnum(parameters, Extractor.ConditionType.class), extractorEntity.conditionValue().asString(parameters), username);
        result.add(extractor);
    }
    return result.build();
}
Also used : ModelType(org.graylog2.contentpacks.model.ModelType) ImmutableList(com.google.common.collect.ImmutableList) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) Converter(org.graylog2.plugin.inputs.Converter) Extractor(org.graylog2.plugin.inputs.Extractor) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)52 AuditEvent (org.graylog2.audit.jersey.AuditEvent)52 ValidationException (org.graylog2.plugin.database.ValidationException)52 Timed (com.codahale.metrics.annotation.Timed)39 Path (javax.ws.rs.Path)32 ApiResponses (io.swagger.annotations.ApiResponses)30 BadRequestException (javax.ws.rs.BadRequestException)28 PUT (javax.ws.rs.PUT)27 Consumes (javax.ws.rs.Consumes)25 POST (javax.ws.rs.POST)24 Produces (javax.ws.rs.Produces)24 User (org.graylog2.plugin.database.users.User)22 URI (java.net.URI)20 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)15 NotFoundException (org.graylog2.database.NotFoundException)15 Test (org.junit.Test)15 Stream (org.graylog2.plugin.streams.Stream)14 ObjectId (org.bson.types.ObjectId)13 GrokPattern (org.graylog2.grok.GrokPattern)13 MessageInput (org.graylog2.plugin.inputs.MessageInput)13