Search in sources :

Example 1 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor 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 EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class EventDefinitionFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Optional<EventDefinitionDto> eventDefinition = eventDefinitionService.get(modelId.id());
    if (!eventDefinition.isPresent()) {
        LOG.debug("Couldn't find event definition {}", entityDescriptor);
        return Optional.empty();
    }
    return Optional.of(exportNativeEntity(eventDefinition.get(), entityDescriptorIds));
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 3 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class EventNotificationHandlerConfigEntity method toNativeEntity.

@Override
public EventNotificationHandler.Config toNativeEntity(Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> natvieEntities) {
    String notificationId = notificationId().asString(parameters);
    final EntityDescriptor notificationDescriptor = EntityDescriptor.create(notificationId, ModelTypes.NOTIFICATION_V1);
    final Object notification = natvieEntities.get(notificationDescriptor);
    final EventNotificationHandler.Config.Builder configBuilder = EventNotificationHandler.Config.builder();
    if (notification == null) {
        throw new ContentPackException("Missing notification (" + notificationId + ") for event definition");
    } else if (notification instanceof NotificationDto) {
        NotificationDto notificationDto = (NotificationDto) notification;
        configBuilder.notificationId(notificationDto.id());
    } else {
        throw new ContentPackException("Invalid type for notification (" + notificationId + ") of event definition: " + notification.getClass());
    }
    return configBuilder.notificationParameters(notificationParameters().orElse(null)).build();
}
Also used : ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NotificationDto(org.graylog.events.notifications.NotificationDto)

Example 4 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class NotificationFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Optional<NotificationDto> notificationDto = notificationService.get(modelId.id());
    if (!notificationDto.isPresent()) {
        LOG.debug("Couldn't find notification {}", entityDescriptor);
        return Optional.empty();
    }
    final NotificationEntity entity = (NotificationEntity) notificationDto.get().toContentPackEntity(entityDescriptorIds);
    final JsonNode data = objectMapper.convertValue(entity, JsonNode.class);
    return Optional.of(EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(notificationDto.get().id(), ModelTypes.NOTIFICATION_V1))).type(ModelTypes.NOTIFICATION_V1).data(data).build());
}
Also used : NotificationDto(org.graylog.events.notifications.NotificationDto) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 5 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.

the class InputFacade 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 InputEntity input = objectMapper.convertValue(entity.data(), InputEntity.class);
    resolveForInstallationV1LookupTable(entity, input, parameters, entities, graph);
    resolveForInstallationV1GrokPattern(entity, input, parameters, entities, graph);
    return ImmutableGraph.copyOf(graph);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)92 Test (org.junit.Test)63 Entity (org.graylog2.contentpacks.model.entities.Entity)62 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)59 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)44 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)44 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)42 ModelId (org.graylog2.contentpacks.model.ModelId)26 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)15 Map (java.util.Map)14 Graph (com.google.common.graph.Graph)13 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)13 Optional (java.util.Optional)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)12 NotFoundException (org.graylog2.database.NotFoundException)12