Search in sources :

Example 1 with EventDefinitionEntity

use of org.graylog.events.contentpack.entities.EventDefinitionEntity in project graylog2-server by Graylog2.

the class EventDefinitionFacade method resolveForInstallationV1.

private Graph<Entity> resolveForInstallationV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
    final MutableGraph<Entity> graph = GraphBuilder.directed().build();
    graph.addNode(entity);
    final EventDefinitionEntity eventDefinition = objectMapper.convertValue(entity.data(), EventDefinitionEntity.class);
    eventDefinition.resolveForInstallation(entity, parameters, entities, graph);
    return ImmutableGraph.copyOf(graph);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity)

Example 2 with EventDefinitionEntity

use of org.graylog.events.contentpack.entities.EventDefinitionEntity in project graylog2-server by Graylog2.

the class EventDefinitionFacade method exportNativeEntity.

@VisibleForTesting
private Entity exportNativeEntity(EventDefinitionDto eventDefinition, EntityDescriptorIds entityDescriptorIds) {
    // Presence of a job definition means that the event definition should be scheduled
    final Optional<JobDefinitionDto> jobDefinition = jobDefinitionService.getByConfigField(EventProcessorExecutionJob.Config.FIELD_EVENT_DEFINITION_ID, eventDefinition.id());
    final EventDefinitionEntity entity = eventDefinition.toContentPackEntity(entityDescriptorIds).toBuilder().isScheduled(ValueReference.of(jobDefinition.isPresent())).build();
    final JsonNode data = objectMapper.convertValue(entity, JsonNode.class);
    return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(eventDefinition.id(), ModelTypes.EVENT_DEFINITION_V1))).type(ModelTypes.EVENT_DEFINITION_V1).constraints(versionConstraints(eventDefinition)).data(data).build();
}
Also used : JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with EventDefinitionEntity

use of org.graylog.events.contentpack.entities.EventDefinitionEntity 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 EventDefinitionEntity

use of org.graylog.events.contentpack.entities.EventDefinitionEntity in project graylog2-server by Graylog2.

the class EventDefinitionFacadeTest method exportEntity.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void exportEntity() {
    final ModelId id = ModelId.of("5d4032513d2746703d1467f6");
    when(jobDefinitionService.getByConfigField(eq("event_definition_id"), eq(id.id()))).thenReturn(Optional.of(mock(JobDefinitionDto.class)));
    final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.EVENT_DEFINITION_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(entity).isPresent();
    final EntityV1 entityV1 = (EntityV1) entity.get();
    final EventDefinitionEntity eventDefinitionEntity = objectMapper.convertValue(entityV1.data(), EventDefinitionEntity.class);
    assertThat(eventDefinitionEntity.title().asString()).isEqualTo("title");
    assertThat(eventDefinitionEntity.description().asString()).isEqualTo("description");
    assertThat(eventDefinitionEntity.config().type()).isEqualTo(AggregationEventProcessorConfigEntity.TYPE_NAME);
    assertThat(eventDefinitionEntity.isScheduled().asBoolean(ImmutableMap.of())).isTrue();
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 5 with EventDefinitionEntity

use of org.graylog.events.contentpack.entities.EventDefinitionEntity in project graylog2-server by Graylog2.

the class EventDefinitionFacadeTest method exportEntityWithoutScheduling.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void exportEntityWithoutScheduling() {
    final ModelId id = ModelId.of("5d4032513d2746703d1467f6");
    when(jobDefinitionService.getByConfigField(eq("event_definition_id"), eq(id.id()))).thenReturn(Optional.empty());
    final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.EVENT_DEFINITION_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(entity).isPresent();
    final EntityV1 entityV1 = (EntityV1) entity.get();
    final EventDefinitionEntity eventDefinitionEntity = objectMapper.convertValue(entityV1.data(), EventDefinitionEntity.class);
    assertThat(eventDefinitionEntity.title().asString()).isEqualTo("title");
    assertThat(eventDefinitionEntity.description().asString()).isEqualTo("description");
    assertThat(eventDefinitionEntity.config().type()).isEqualTo(AggregationEventProcessorConfigEntity.TYPE_NAME);
    assertThat(eventDefinitionEntity.isScheduled().asBoolean(ImmutableMap.of())).isFalse();
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EventDefinitionEntity (org.graylog.events.contentpack.entities.EventDefinitionEntity)6 AggregationEventProcessorConfigEntity (org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity)3 Entity (org.graylog2.contentpacks.model.entities.Entity)3 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 EventNotificationHandlerConfigEntity (org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity)2 HttpEventNotificationConfigEntity (org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity)2 NotificationEntity (org.graylog.events.contentpack.entities.NotificationEntity)2 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)2 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)2 ModelId (org.graylog2.contentpacks.model.ModelId)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)2 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Expr (org.graylog.events.conditions.Expr)1 EventFieldSpec (org.graylog.events.fields.EventFieldSpec)1 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)1 AggregationConditions (org.graylog.events.processor.aggregation.AggregationConditions)1