use of org.graylog2.alarmcallbacks.AlarmCallbackHistory in project graylog2-server by Graylog2.
the class AlarmCallbackHistoryServiceImplTest method testSuccess.
@Test
public void testSuccess() throws Exception {
final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(new Date());
final Alert alert = mockAlert();
final AlertCondition alertCondition = mockAlertCondition();
final AlarmCallbackHistory alarmCallbackHistory = this.alarmCallbackHistoryService.success(alarmCallbackConfiguration, alert, alertCondition);
verifyAlarmCallbackHistory(alarmCallbackHistory, alert, alertCondition);
assertThat(alarmCallbackHistory.result()).isNotNull().isInstanceOf(AlarmCallbackSuccess.class);
assertThat(alarmCallbackHistory.result().type()).isEqualTo("success");
}
use of org.graylog2.alarmcallbacks.AlarmCallbackHistory in project graylog2-server by Graylog2.
the class AlarmCallbackHistoryServiceImplTest method testError.
@Test
public void testError() throws Exception {
final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(new Date());
final Alert alert = mockAlert();
final AlertCondition alertCondition = mockAlertCondition();
final String errorMessage = "Dummy Error Message";
final AlarmCallbackHistory alarmCallbackHistory = this.alarmCallbackHistoryService.error(alarmCallbackConfiguration, alert, alertCondition, errorMessage);
verifyAlarmCallbackHistory(alarmCallbackHistory, alert, alertCondition);
assertThat(alarmCallbackHistory.result()).isNotNull().isInstanceOf(AlarmCallbackError.class);
assertThat(alarmCallbackHistory.result().type()).isEqualTo("error");
final AlarmCallbackError result = (AlarmCallbackError) alarmCallbackHistory.result();
assertThat(result.error()).isEqualTo(errorMessage);
}
use of org.graylog2.alarmcallbacks.AlarmCallbackHistory in project graylog2-server by Graylog2.
the class AlarmCallbackHistoryServiceImplTest method testSaveForDummyError.
@Test
public void testSaveForDummyError() throws Exception {
final Date createdAt = DateTime.parse(CFG_CREATED_AT).toDate();
final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(createdAt);
final Alert alert = mockAlert();
final AlertCondition alertCondition = mockAlertCondition();
final String errorMessage = "Dummy Error Message";
final AlarmCallbackHistory error = this.alarmCallbackHistoryService.error(alarmCallbackConfiguration, alert, alertCondition, errorMessage);
this.alarmCallbackHistoryService.save(error);
MongoCollection<Document> collection = mongodb.mongoConnection().getMongoDatabase().getCollection(collectionName);
Document document = collection.find().first();
Document configuration = document.get("alarmcallbackconfiguration", Document.class);
Document result = document.get("result", Document.class);
assertThat(document.get("alert_id")).isEqualTo(ALERT_ID);
assertThat(document.get("alertcondition_id")).isEqualTo(ALERT_CONDITION_ID);
assertThat(configuration.get("id")).isEqualTo(CFG_ID);
assertThat(configuration.get("type")).isEqualTo(CFG_TYPE);
assertThat(configuration.get("stream_id")).isEqualTo(CFG_STREAM_ID);
assertThat(configuration.get("creator_user_id")).isEqualTo(CFG_USER);
assertThat(result.get("type")).isEqualTo("error");
assertThat(result.get("error")).isEqualTo(errorMessage);
}
use of org.graylog2.alarmcallbacks.AlarmCallbackHistory in project graylog2-server by Graylog2.
the class AlarmCallbackHistoryServiceImplTest method testSaveForDummySuccess.
@Test
public void testSaveForDummySuccess() throws Exception {
final Date createdAt = DateTime.parse(CFG_CREATED_AT).toDate();
final AlarmCallbackConfiguration alarmCallbackConfiguration = mockAlarmCallbackConfiguration(createdAt);
final Alert alert = mockAlert();
final AlertCondition alertCondition = mockAlertCondition();
final AlarmCallbackHistory success = this.alarmCallbackHistoryService.success(alarmCallbackConfiguration, alert, alertCondition);
this.alarmCallbackHistoryService.save(success);
MongoCollection<Document> collection = mongodb.mongoConnection().getMongoDatabase().getCollection(collectionName);
Document document = collection.find().first();
Document configuration = document.get("alarmcallbackconfiguration", Document.class);
Document result = document.get("result", Document.class);
assertThat(document.get("alert_id")).isEqualTo(ALERT_ID);
assertThat(document.get("alertcondition_id")).isEqualTo(ALERT_CONDITION_ID);
assertThat(configuration.get("id")).isEqualTo(CFG_ID);
assertThat(configuration.get("type")).isEqualTo(CFG_TYPE);
assertThat(configuration.get("stream_id")).isEqualTo(CFG_STREAM_ID);
assertThat(configuration.get("creator_user_id")).isEqualTo(CFG_USER);
assertThat(result.get("type")).isEqualTo("success");
}
use of org.graylog2.alarmcallbacks.AlarmCallbackHistory in project graylog2-server by Graylog2.
the class AlertServiceImplTest method repeatNotificationsOptionShouldComplyWithGracePeriod.
@Test
@MongoDBFixtures("unresolved-alert.json")
public void repeatNotificationsOptionShouldComplyWithGracePeriod() throws Exception {
final AlertCondition alertCondition = mock(AlertCondition.class);
when(alertCondition.getGrace()).thenReturn(15);
when(alertCondition.shouldRepeatNotifications()).thenReturn(true);
final Alert alert = alertService.load(ALERT_ID, STREAM_ID);
// Should repeat notification when there was no previous alert
assertThat(alertService.shouldRepeatNotifications(alertCondition, alert)).isTrue();
final AlarmCallbackHistory alarmCallbackHistory = mock(AlarmCallbackHistory.class);
when(alarmCallbackHistory.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minusMinutes(14));
when(alarmCallbackHistoryService.getForAlertId(ALERT_ID)).thenReturn(ImmutableList.of(alarmCallbackHistory));
// Should not repeat notification if a notification was sent during grace period
assertThat(alertService.shouldRepeatNotifications(alertCondition, alert)).isFalse();
when(alarmCallbackHistory.createdAt()).thenReturn(DateTime.now(DateTimeZone.UTC).minusMinutes(15));
when(alarmCallbackHistoryService.getForAlertId(ALERT_ID)).thenReturn(ImmutableList.of(alarmCallbackHistory));
// Should repeat notification after grace period passed
assertThat(alertService.shouldRepeatNotifications(alertCondition, alert)).isTrue();
}
Aggregations