Search in sources :

Example 11 with EventDefinitionDto

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));
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 12 with 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);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) NotificationDto(org.graylog.events.notifications.NotificationDto) EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) JobTriggerDto(org.graylog.scheduler.JobTriggerDto) Test(org.junit.Test)

Example 13 with EventDefinitionDto

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);
        });
    });
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) EventProcessorExecutionJob(org.graylog.events.processor.EventProcessorExecutionJob) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 14 with EventDefinitionDto

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());
}
Also used : EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) Objects(java.util.Objects)

Example 15 with EventDefinitionDto

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);
}
Also used : EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) EventDefinitionDto(org.graylog.events.processor.EventDefinitionDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)25 Test (org.junit.Test)10 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)7 DateTime (org.joda.time.DateTime)7 TestEvent (org.graylog.events.event.TestEvent)5 Event (org.graylog.events.event.Event)4 EventWithContext (org.graylog.events.event.EventWithContext)4 EventProcessorConfig (org.graylog.events.processor.EventProcessorConfig)4 Message (org.graylog2.plugin.Message)4 AggregationEventProcessorConfig (org.graylog.events.processor.aggregation.AggregationEventProcessorConfig)3 AggregationSeries (org.graylog.events.processor.aggregation.AggregationSeries)3 JobDefinitionDto (org.graylog.scheduler.JobDefinitionDto)3 JobTriggerDto (org.graylog.scheduler.JobTriggerDto)3 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)3 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)3 ApiOperation (io.swagger.annotations.ApiOperation)2 EventDto (org.graylog.events.event.EventDto)2 ModelId (org.graylog2.contentpacks.model.ModelId)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2