use of org.graylog2.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class FieldContentValueAlertConditionTest method testCorrectUsageOfRelativeRange.
@Test
public void testCorrectUsageOfRelativeRange() throws Exception {
final Stream stream = mock(Stream.class);
final Searches searches = mock(Searches.class);
final Configuration configuration = mock(Configuration.class);
final SearchResult searchResult = mock(SearchResult.class);
final int alertCheckInterval = 42;
final RelativeRange relativeRange = RelativeRange.create(alertCheckInterval);
when(stream.getId()).thenReturn("stream-id");
when(configuration.getAlertCheckInterval()).thenReturn(alertCheckInterval);
when(searches.search(anyString(), anyString(), eq(relativeRange), anyInt(), anyInt(), any(Sorting.class))).thenReturn(searchResult);
final FieldContentValueAlertCondition alertCondition = new FieldContentValueAlertCondition(searches, configuration, stream, null, DateTime.now(DateTimeZone.UTC), "mockuser", ImmutableMap.<String, Object>of("field", "test", "value", "test"), "Field Content Value Test COndition");
final AbstractAlertCondition.CheckResult result = alertCondition.runCheck();
}
use of org.graylog2.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class AlertScannerTest method testCheckWithNegativeResult.
@Test
public void testCheckWithNegativeResult() throws Exception {
final AlertCondition alertCondition = mock(AlertCondition.class);
final Stream stream = mock(Stream.class);
when(alertService.inGracePeriod(eq(alertCondition))).thenReturn(false);
when(alertCondition.runCheck()).thenReturn(new AbstractAlertCondition.NegativeCheckResult());
assertThat(this.alertScanner.checkAlertCondition(stream, alertCondition)).isFalse();
verify(alertCondition, times(1)).runCheck();
}
use of org.graylog2.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method buildBodyUsesDefaultBodyIfConfigDoesNotExist.
@Test
public void buildBodyUsesDefaultBodyIfConfigDoesNotExist() throws Exception {
Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("123456");
when(stream.getTitle()).thenReturn("Stream Title");
AlertCondition alertCondition = mock(AlertCondition.class);
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
when(checkResult.getTriggeredAt()).thenReturn(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
when(checkResult.getTriggeredCondition()).thenReturn(alertCondition);
String body = emailAlertSender.buildBody(stream, checkResult, Collections.<Message>emptyList());
assertThat(body).containsSequence("Date: 2015-01-01T00:00:00.000Z\n", "Stream ID: 123456\n", "Stream title: Stream Title");
}
use of org.graylog2.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method defaultBodyTemplateShowsBacklogIfBacklogIsNotEmpty.
@Test
public void defaultBodyTemplateShowsBacklogIfBacklogIsNotEmpty() throws Exception {
FormattedEmailAlertSender emailAlertSender = new FormattedEmailAlertSender(new EmailConfiguration(), mockNotificationService, mockNodeId, templateEngine, emailFactory);
Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("123456");
when(stream.getTitle()).thenReturn("Stream Title");
AlertCondition alertCondition = mock(AlertCondition.class);
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
when(checkResult.getTriggeredAt()).thenReturn(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
when(checkResult.getTriggeredCondition()).thenReturn(alertCondition);
Message message = new Message("Test", "source", new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
String body = emailAlertSender.buildBody(stream, checkResult, Collections.singletonList(message));
assertThat(body).doesNotContain("<No backlog>\n").containsSequence("Last messages accounting for this alert:\n", message.toString());
}
use of org.graylog2.plugin.alarms.AlertCondition in project graylog2-server by Graylog2.
the class FormattedEmailAlertSenderTest method defaultBodyTemplateDoesNotShowBacklogIfBacklogIsEmpty.
@Test
public void defaultBodyTemplateDoesNotShowBacklogIfBacklogIsEmpty() throws Exception {
FormattedEmailAlertSender emailAlertSender = new FormattedEmailAlertSender(new EmailConfiguration(), mockNotificationService, mockNodeId, templateEngine, emailFactory);
Stream stream = mock(Stream.class);
when(stream.getId()).thenReturn("123456");
when(stream.getTitle()).thenReturn("Stream Title");
AlertCondition alertCondition = mock(AlertCondition.class);
AlertCondition.CheckResult checkResult = mock(AbstractAlertCondition.CheckResult.class);
when(checkResult.getTriggeredAt()).thenReturn(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC));
when(checkResult.getTriggeredCondition()).thenReturn(alertCondition);
String body = emailAlertSender.buildBody(stream, checkResult, Collections.<Message>emptyList());
assertThat(body).contains("<No backlog>\n").doesNotContain("Last messages accounting for this alert:\n");
}
Aggregations