Search in sources :

Example 6 with Event

use of org.graylog.events.event.Event in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method withinGracePeriod.

@Test
public void withinGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent();
    event.setKeyTuple(ImmutableList.of("testkey"));
    final Event event2 = new TestEvent();
    event2.setKeyTuple(ImmutableList.of("testkey"));
    event2.setEventTimestamp(event.getEventTimestamp().plus(5L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).isTrue();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Example 7 with Event

use of org.graylog.events.event.Event in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method outsideGracePeriod.

@Test
public void outsideGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent();
    event.setKeyTuple(ImmutableList.of("testkey"));
    final Event event2 = new TestEvent();
    event2.setKeyTuple(ImmutableList.of("testkey"));
    event2.setEventTimestamp(event.getEventTimestamp().plus(11L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).isFalse();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Example 8 with Event

use of org.graylog.events.event.Event in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method insideOutsideInsideGracePeriod.

@Test
public void insideOutsideInsideGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent(DateTime.now(UTC), "testkey");
    final Event event2 = new TestEvent(event.getEventTimestamp().plus(5L), "testkey");
    final Event event3 = new TestEvent(event2.getEventTimestamp().plus(6L), "testkey");
    final Event event4 = new TestEvent(event3.getEventTimestamp().plus(6L), "testkey");
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).isTrue();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event3)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event4)).isTrue();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Example 9 with Event

use of org.graylog.events.event.Event in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method differentNotification.

@Test
public void differentNotification() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent();
    event.setKeyTuple(ImmutableList.of("testkey"));
    final Event event2 = new TestEvent();
    event2.setKeyTuple(ImmutableList.of("testkey"));
    event2.setEventTimestamp(event.getEventTimestamp().plus(1L));
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "4242", event2)).isFalse();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Example 10 with Event

use of org.graylog.events.event.Event in project graylog2-server by Graylog2.

the class NotificationGracePeriodServiceTest method insideThenInsideGracePeriod.

@Test
public void insideThenInsideGracePeriod() {
    final NotificationGracePeriodService notificationGracePeriodService = new NotificationGracePeriodService();
    when(settings.gracePeriodMs()).thenReturn(10L);
    when(definition.notificationSettings()).thenReturn(settings);
    when(definition.id()).thenReturn("1234");
    final Event event = new TestEvent(DateTime.now(UTC), "testkey");
    final Event event2 = new TestEvent(event.getEventTimestamp().plus(5L), "testkey");
    final Event event3 = new TestEvent(event2.getEventTimestamp().plus(4L), "testkey");
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event)).isFalse();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event2)).isTrue();
    assertThat(notificationGracePeriodService.inGracePeriod(definition, "5678", event3)).isTrue();
}
Also used : NotificationGracePeriodService(org.graylog.events.notifications.NotificationGracePeriodService) TestEvent(org.graylog.events.event.TestEvent) TestEvent(org.graylog.events.event.TestEvent) Event(org.graylog.events.event.Event) Test(org.junit.Test)

Aggregations

Event (org.graylog.events.event.Event)16 TestEvent (org.graylog.events.event.TestEvent)12 Test (org.junit.Test)12 EventWithContext (org.graylog.events.event.EventWithContext)8 NotificationGracePeriodService (org.graylog.events.notifications.NotificationGracePeriodService)8 Message (org.graylog2.plugin.Message)6 DateTime (org.joda.time.DateTime)6 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)5 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 Ints (com.google.common.primitives.Ints)1 Assisted (com.google.inject.assistedinject.Assisted)1