Search in sources :

Example 1 with ModelId

use of org.graylog2.contentpacks.model.ModelId 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 2 with ModelId

use of org.graylog2.contentpacks.model.ModelId 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 3 with ModelId

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

the class InputFacade method resolveNativeEntity.

@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    try {
        final Input input = inputService.find(modelId.toString());
        final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
        resolveNativeEntityLookupTable(entityDescriptor, inputWithExtractors, mutableGraph);
        resolveNativeEntityGrokPattern(entityDescriptor, inputWithExtractors, mutableGraph);
        return ImmutableGraph.copyOf(mutableGraph);
    } catch (NotFoundException e) {
        LOG.debug("Couldn't find input {}", entityDescriptor, e);
    }
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Input(org.graylog2.inputs.Input) MessageInput(org.graylog2.plugin.inputs.MessageInput) NotFoundException(org.graylog2.database.NotFoundException) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 4 with ModelId

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

the class LookupTableFacade method resolveNativeEntity.

@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
    final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
    mutableGraph.addNode(entityDescriptor);
    final ModelId modelId = entityDescriptor.id();
    final Optional<LookupTableDto> lookupTableDto = lookupTableService.get(modelId.id());
    lookupTableDto.map(LookupTableDto::dataAdapterId).map(this::adapterDescriptor).ifPresent(dataAdapter -> mutableGraph.putEdge(entityDescriptor, dataAdapter));
    lookupTableDto.map(LookupTableDto::cacheId).map(this::cacheDescriptor).ifPresent(cache -> mutableGraph.putEdge(entityDescriptor, cache));
    return ImmutableGraph.copyOf(mutableGraph);
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) LookupTableDto(org.graylog2.lookup.dto.LookupTableDto) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 5 with ModelId

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

the class SidecarCollectorFacade method exportEntity.

@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
    final ModelId modelId = entityDescriptor.id();
    final Collector collector = collectorService.find(modelId.id());
    if (isNull(collector)) {
        LOG.debug("Couldn't find collector {}", entityDescriptor);
        return Optional.empty();
    }
    return Optional.of(exportNativeEntity(collector, entityDescriptorIds));
}
Also used : Collector(org.graylog.plugins.sidecar.rest.models.Collector) ModelId(org.graylog2.contentpacks.model.ModelId)

Aggregations

ModelId (org.graylog2.contentpacks.model.ModelId)31 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)16 Entity (org.graylog2.contentpacks.model.entities.Entity)11 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)11 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)11 Map (java.util.Map)10 Set (java.util.Set)10 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)10 Test (org.junit.Test)10 Optional (java.util.Optional)9 ContentPack (org.graylog2.contentpacks.model.ContentPack)9 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)8 NotFoundException (org.graylog2.database.NotFoundException)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Graph (com.google.common.graph.Graph)7 GraphBuilder (com.google.common.graph.GraphBuilder)7