use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class LookupDataAdapterFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(DataAdapterDto dataAdapterDto, EntityDescriptorIds entityDescriptorIds) {
// TODO: Create independent representation of entity?
final Map<String, Object> configuration = objectMapper.convertValue(dataAdapterDto.config(), TypeReferences.MAP_STRING_OBJECT);
final LookupDataAdapterEntity lookupDataAdapterEntity = LookupDataAdapterEntity.create(ValueReference.of(dataAdapterDto.name()), ValueReference.of(dataAdapterDto.title()), ValueReference.of(dataAdapterDto.description()), toReferenceMap(configuration));
final JsonNode data = objectMapper.convertValue(lookupDataAdapterEntity, JsonNode.class);
final Set<Constraint> constraints = versionConstraints(dataAdapterDto);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(dataAdapterDto.id(), ModelTypes.LOOKUP_ADAPTER_V1))).type(ModelTypes.LOOKUP_ADAPTER_V1).constraints(ImmutableSet.copyOf(constraints)).data(data).build();
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class Query method shallowMappedFilter.
// TODO: This code assumes that we only use shallow filters for streams.
// If this ever changes, we need to implement a mapper that can handle filter trees.
private Filter shallowMappedFilter(EntityDescriptorIds entityDescriptorIds) {
return Optional.ofNullable(filter()).map(optFilter -> {
Set<Filter> newFilters = optFilter.filters().stream().map(filter -> {
if (filter.type().equals(StreamFilter.NAME)) {
final StreamFilter streamFilter = (StreamFilter) filter;
final String streamId = entityDescriptorIds.getOrThrow(streamFilter.streamId(), ModelTypes.STREAM_V1);
return streamFilter.toBuilder().streamId(streamId).build();
}
return filter;
}).collect(toSet());
return optFilter.toGenericBuilder().filters(newFilters).build();
}).orElse(null);
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class NotificationTestData method getDummyContext.
public static EventNotificationContext getDummyContext(NotificationDto notificationDto, String userName) {
final EventDto eventDto = EventDto.builder().alert(true).eventDefinitionId("EventDefinitionTestId").eventDefinitionType("notification-test-v1").eventTimestamp(Tools.nowUTC()).processingTimestamp(Tools.nowUTC()).id("TEST_NOTIFICATION_ID").streams(ImmutableSet.of(Stream.DEFAULT_EVENTS_STREAM_ID)).message("Notification test message triggered from user <" + userName + ">").source(Stream.DEFAULT_STREAM_ID).keyTuple(ImmutableList.of("testkey")).key("testkey").originContext(EventOriginContext.elasticsearchMessage("testIndex_42", "b5e53442-12bb-4374-90ed-0deadbeefbaz")).priority(2).fields(ImmutableMap.of("field1", "value1", "field2", "value2")).build();
final EventDefinitionDto eventDefinitionDto = EventDefinitionDto.builder().alert(true).id(TEST_NOTIFICATION_ID).title("Event Definition Test Title").description("Event Definition Test Description").config(new EventProcessorConfig() {
@Override
public String type() {
return "test-dummy-v1";
}
@Override
public ValidationResult validate() {
return null;
}
@Override
public EventProcessorConfigEntity toContentPackEntity(EntityDescriptorIds entityDescriptorIds) {
return null;
}
}).fieldSpec(ImmutableMap.of()).priority(2).keySpec(ImmutableList.of()).notificationSettings(new EventNotificationSettings() {
@Override
public long gracePeriodMs() {
return 0;
}
@Override
public // disable to avoid errors in getBacklogForEvent()
long backlogSize() {
return 0;
}
@Override
public Builder toBuilder() {
return null;
}
}).build();
return EventNotificationContext.builder().notificationId(TEST_NOTIFICATION_ID).notificationConfig(notificationDto.config()).event(eventDto).eventDefinition(eventDefinitionDto).build();
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class PipelineFacade method exportNativeEntity.
@VisibleForTesting
Entity exportNativeEntity(PipelineDao pipelineDao, EntityDescriptorIds entityDescriptorIds) {
final Set<ValueReference> connectedStreams = connectedStreams(pipelineDao.id(), entityDescriptorIds);
final PipelineEntity pipelineEntity = PipelineEntity.create(ValueReference.of(pipelineDao.title()), ValueReference.of(pipelineDao.description()), ValueReference.of(pipelineDao.source()), connectedStreams);
final JsonNode data = objectMapper.convertValue(pipelineEntity, JsonNode.class);
return EntityV1.builder().id(ModelId.of(entityDescriptorIds.getOrThrow(pipelineDao.id(), ModelTypes.PIPELINE_V1))).type(ModelTypes.PIPELINE_V1).data(data).build();
}
use of org.graylog2.contentpacks.EntityDescriptorIds in project graylog2-server by Graylog2.
the class SidecarCollectorConfigurationFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Configuration configuration = configurationService.find(modelId.id());
if (isNull(configuration)) {
LOG.debug("Couldn't find collector configuration {}", entityDescriptor);
return Optional.empty();
}
return Optional.of(exportNativeEntity(configuration, entityDescriptorIds));
}
Aggregations