use of org.graylog.events.processor.EventDefinitionDto in project graylog2-server by Graylog2.
the class AggregationEventProcessorTest method createEventsWithFilter.
@Test
public void createEventsWithFilter() throws Exception {
when(eventProcessorDependencyCheck.hasMessagesIndexedUpTo(any(DateTime.class))).thenReturn(true);
final DateTime now = DateTime.now(DateTimeZone.UTC);
final AbsoluteRange timerange = AbsoluteRange.create(now.minusHours(1), now.plusHours(1));
final AggregationEventProcessorConfig config = AggregationEventProcessorConfig.builder().query("aQueryString").streams(ImmutableSet.of()).groupBy(ImmutableList.of()).series(ImmutableList.of()).conditions(null).searchWithinMs(30000).executeEveryMs(30000).build();
final EventDefinitionDto eventDefinitionDto = buildEventDefinitionDto(ImmutableSet.of(), ImmutableList.of(), null);
final AggregationEventProcessorParameters parameters = AggregationEventProcessorParameters.builder().timerange(timerange).build();
final AggregationEventProcessor eventProcessor = new AggregationEventProcessor(eventDefinitionDto, searchFactory, eventProcessorDependencyCheck, stateService, moreSearch, streamService, messages);
assertThatCode(() -> eventProcessor.createEvents(eventFactory, parameters, (events) -> {
})).doesNotThrowAnyException();
verify(moreSearch, times(1)).scrollQuery(eq(config.query()), eq(config.streams()), eq(config.queryParameters()), eq(parameters.timerange()), eq(parameters.batchSize()), any(MoreSearch.ScrollCallback.class));
verify(searchFactory, never()).create(eq(config), eq(parameters), any(String.class), eq(eventDefinitionDto));
}
use of org.graylog.events.processor.EventDefinitionDto in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final EntityV1 entityV1 = createTestEntity();
final NotificationDto notificationDto = NotificationDto.builder().config(HTTPEventNotificationConfig.builder().url("https://hulud.net").build()).title("Notify me Senpai").description("A notification for senpai").id("dead-beef").build();
final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
final ImmutableMap<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(entityDescriptor, notificationDto);
final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
final JobTriggerDto jobTriggerDto = mock(JobTriggerDto.class);
when(jobDefinitionDto.id()).thenReturn("job-123123");
when(jobSchedulerClock.nowUTC()).thenReturn(DateTime.now(DateTimeZone.UTC));
when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
when(jobTriggerService.create(any(JobTriggerDto.class))).thenReturn(jobTriggerDto);
final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
when(userService.load("kmerz")).thenReturn(kmerzUser);
final NativeEntity<EventDefinitionDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), nativeEntities, "kmerz");
assertThat(nativeEntity).isNotNull();
final EventDefinitionDto eventDefinitionDto = nativeEntity.entity();
assertThat(eventDefinitionDto.title()).isEqualTo("title");
assertThat(eventDefinitionDto.description()).isEqualTo("description");
assertThat(eventDefinitionDto.config().type()).isEqualTo("aggregation-v1");
// verify that ownership was registered for this entity
verify(entityOwnershipService, times(1)).registerNewEventDefinition(nativeEntity.entity().id(), kmerzUser);
}
use of org.graylog.events.processor.EventDefinitionDto in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfigTest method toJobSchedulerConfig.
@Test
@MongoDBFixtures("aggregation-processors.json")
public void toJobSchedulerConfig() {
final EventDefinitionDto dto = dbService.get("54e3deadbeefdeadbeefaffe").orElse(null);
assertThat(dto).isNotNull();
assertThat(dto.config().toJobSchedulerConfig(dto, clock)).isPresent().get().satisfies(schedulerConfig -> {
assertThat(schedulerConfig.jobDefinitionConfig()).satisfies(jobDefinitionConfig -> {
assertThat(jobDefinitionConfig).isInstanceOf(EventProcessorExecutionJob.Config.class);
final EventProcessorExecutionJob.Config config = (EventProcessorExecutionJob.Config) jobDefinitionConfig;
assertThat(config.eventDefinitionId()).isEqualTo(dto.id());
assertThat(config.processingWindowSize()).isEqualTo(300000);
assertThat(config.processingHopSize()).isEqualTo(300000);
assertThat(config.parameters()).isEqualTo(AggregationEventProcessorParameters.builder().timerange(AbsoluteRange.create(clock.nowUTC().minus(300000), clock.nowUTC())).build());
});
assertThat(schedulerConfig.schedule()).satisfies(schedule -> {
assertThat(schedule).isInstanceOf(IntervalJobSchedule.class);
final IntervalJobSchedule config = (IntervalJobSchedule) schedule;
assertThat(config.interval()).isEqualTo(300000);
assertThat(config.unit()).isEqualTo(TimeUnit.MILLISECONDS);
});
});
}
use of org.graylog.events.processor.EventDefinitionDto in project graylog2-server by Graylog2.
the class V20200102140000_UnifyEventSeriesId method upgrade.
@Override
public void upgrade() {
if (clusterConfigService.get(MigrationCompleted.class) != null) {
LOG.debug("Migration already completed.");
return;
}
final List<EventDefinitionDto> changedEventDefinitions;
try (final Stream<EventDefinitionDto> dtoStream = eventDefinitionService.streamAll()) {
changedEventDefinitions = dtoStream.map(this::unifySeriesId).filter(Objects::nonNull).collect(Collectors.toList());
}
for (final EventDefinitionDto changedDto : changedEventDefinitions) {
LOG.info("Unified series Id for EventDefinition <{}>", changedDto.id());
eventDefinitionService.save(changedDto);
}
clusterConfigService.write(MigrationCompleted.create());
}
use of org.graylog.events.processor.EventDefinitionDto in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method createExcerpt.
@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void createExcerpt() {
final Optional<EventDefinitionDto> eventDefinitionDto = eventDefinitionService.get("5d4032513d2746703d1467f6");
assertThat(eventDefinitionDto).isPresent();
final EntityExcerpt excerpt = facade.createExcerpt(eventDefinitionDto.get());
assertThat(excerpt.title()).isEqualTo("title");
assertThat(excerpt.id()).isEqualTo(ModelId.of("5d4032513d2746703d1467f6"));
assertThat(excerpt.type()).isEqualTo(ModelTypes.EVENT_DEFINITION_V1);
}
Aggregations