Search in sources :

Example 1 with EventFieldSpec

use of org.graylog.events.fields.EventFieldSpec in project graylog2-server by Graylog2.

the class EventDefinitionDtoTest method testValidEventDefinitionWithKeySpecInFieldSpec.

@Test
public void testValidEventDefinitionWithKeySpecInFieldSpec() {
    final EventFieldSpec fieldSpecMock = mock(EventFieldSpec.class);
    final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().fieldSpec(ImmutableMap.of("foo", fieldSpecMock, "bar", fieldSpecMock)).keySpec(ImmutableList.of("foo", "bar")).build();
    final ValidationResult validationResult = invalidEventDefinition.validate();
    assertThat(validationResult.failed()).isFalse();
    assertThat(validationResult.getErrors().size()).isEqualTo(0);
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 2 with EventFieldSpec

use of org.graylog.events.fields.EventFieldSpec in project graylog2-server by Graylog2.

the class EventDefinitionDtoTest method testValidateWithKeySpecNotInFieldSpec.

@Test
public void testValidateWithKeySpecNotInFieldSpec() {
    final EventFieldSpec fieldSpecMock = mock(EventFieldSpec.class);
    final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().fieldSpec(ImmutableMap.of("bar", fieldSpecMock, "baz", fieldSpecMock)).keySpec(ImmutableList.of("foo")).build();
    final ValidationResult validationResult = invalidEventDefinition.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("key_spec");
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Example 3 with EventFieldSpec

use of org.graylog.events.fields.EventFieldSpec in project graylog2-server by Graylog2.

the class EventDefinitionFacadeTest method createTestEntity.

private EntityV1 createTestEntity() {
    final EventFieldSpec fieldSpec = EventFieldSpec.builder().dataType(FieldValueType.STRING).providers(ImmutableList.of(TemplateFieldValueProvider.Config.builder().template("template").build())).build();
    final Expr.Greater trueExpr = Expr.Greater.create(Expr.NumberValue.create(2), Expr.NumberValue.create(1));
    final AggregationSeries serie = AggregationSeries.create("id-deef", AggregationFunction.COUNT, "field");
    final AggregationConditions condition = AggregationConditions.builder().expression(Expr.And.create(trueExpr, trueExpr)).build();
    final AggregationEventProcessorConfigEntity aggregationConfig = AggregationEventProcessorConfigEntity.builder().query(ValueReference.of("author: \"Jane Hopper\"")).streams(ImmutableSet.of()).groupBy(ImmutableList.of("project")).series(ImmutableList.of(serie)).conditions(condition).executeEveryMs(122200000L).searchWithinMs(1231312123L).build();
    final EventDefinitionEntity eventDefinitionEntity = EventDefinitionEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("description")).priority(ValueReference.of(1)).config(aggregationConfig).alert(ValueReference.of(true)).fieldSpec(ImmutableMap.of("fieldSpec", fieldSpec)).keySpec(ImmutableList.of("keyspec")).notificationSettings(EventNotificationSettings.builder().gracePeriodMs(123123).backlogSize(123).build()).notifications(ImmutableList.of(EventNotificationHandlerConfigEntity.builder().notificationId(ValueReference.of("123123")).build())).storage(ImmutableList.of()).build();
    final JsonNode data = objectMapper.convertValue(eventDefinitionEntity, JsonNode.class);
    return EntityV1.builder().data(data).id(ModelId.of("beef-1337")).type(ModelTypes.EVENT_DEFINITION_V1).build();
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) Expr(org.graylog.events.conditions.Expr) AggregationConditions(org.graylog.events.processor.aggregation.AggregationConditions) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) AggregationSeries(org.graylog.events.processor.aggregation.AggregationSeries) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity)

Example 4 with EventFieldSpec

use of org.graylog.events.fields.EventFieldSpec in project graylog2-server by Graylog2.

the class EventDefinitionDtoTest method testValidateWithInvalidFieldName.

@Test
public void testValidateWithInvalidFieldName() {
    final EventFieldSpec fieldSpecMock = mock(EventFieldSpec.class);
    final EventDefinitionDto invalidEventDefinition = testSubject.toBuilder().fieldSpec(ImmutableMap.of("foo\\bar", fieldSpecMock, "$yo&^a", fieldSpecMock)).build();
    final ValidationResult validationResult = invalidEventDefinition.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("field_spec");
    final List<String> fieldValidation = (List<String>) validationResult.getErrors().get("field_spec");
    assertThat(fieldValidation.size()).isEqualTo(2);
    assertThat(fieldValidation.get(0)).contains("foo\\bar");
    assertThat(fieldValidation.get(1)).contains("$yo&^a");
}
Also used : EventFieldSpec(org.graylog.events.fields.EventFieldSpec) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Aggregations

EventFieldSpec (org.graylog.events.fields.EventFieldSpec)4 ValidationResult (org.graylog2.plugin.rest.ValidationResult)3 Test (org.junit.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Expr (org.graylog.events.conditions.Expr)1 AggregationEventProcessorConfigEntity (org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity)1 EventDefinitionEntity (org.graylog.events.contentpack.entities.EventDefinitionEntity)1 AggregationConditions (org.graylog.events.processor.aggregation.AggregationConditions)1 AggregationSeries (org.graylog.events.processor.aggregation.AggregationSeries)1