Search in sources :

Example 1 with AggregationConditions

use of org.graylog.events.processor.aggregation.AggregationConditions in project graylog2-server by Graylog2.

the class V20200102140000_UnifyEventSeriesId method unifySeriesId.

private EventDefinitionDto unifySeriesId(EventDefinitionDto dto) {
    if (!dto.config().type().equals(AggregationEventProcessorConfig.TYPE_NAME)) {
        return null;
    }
    final AggregationEventProcessorConfig config = (AggregationEventProcessorConfig) dto.config();
    if (config.series().isEmpty()) {
        return null;
    }
    final ObjectMapper objectMapper = objectMapperProvider.get();
    final AggregationEventProcessorConfig.Builder configBuilder = config.toBuilder();
    final Map<String, String> refMap = new HashMap<>();
    configBuilder.series(config.series().stream().map(s -> {
        final String newId = s.function().toSeriesId(s.field());
        refMap.put(s.id(), newId);
        return s.toBuilder().id(newId).build();
    }).collect(Collectors.toList()));
    // convert conditions to json, fix them and convert back to POJO
    final JsonNode conditionsJson = objectMapper.valueToTree(config.conditions());
    convertConditions(dto.id(), refMap, conditionsJson);
    final AggregationConditions convertedConditions = objectMapper.convertValue(conditionsJson, AggregationConditions.class);
    configBuilder.conditions(convertedConditions);
    return dto.toBuilder().config(configBuilder.build()).build();
}
Also used : AggregationConditions(org.graylog.events.processor.aggregation.AggregationConditions) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) AggregationEventProcessorConfig(org.graylog.events.processor.aggregation.AggregationEventProcessorConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with AggregationConditions

use of org.graylog.events.processor.aggregation.AggregationConditions 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)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 AggregationConditions (org.graylog.events.processor.aggregation.AggregationConditions)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashMap (java.util.HashMap)1 Expr (org.graylog.events.conditions.Expr)1 AggregationEventProcessorConfigEntity (org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity)1 EventDefinitionEntity (org.graylog.events.contentpack.entities.EventDefinitionEntity)1 EventFieldSpec (org.graylog.events.fields.EventFieldSpec)1 AggregationEventProcessorConfig (org.graylog.events.processor.aggregation.AggregationEventProcessorConfig)1 AggregationSeries (org.graylog.events.processor.aggregation.AggregationSeries)1