use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlarmCallbackFactoryTest method testCreateByAlarmCallbackConfiguration.
@Test
public void testCreateByAlarmCallbackConfiguration() throws Exception {
AlarmCallbackConfiguration configuration = mock(AlarmCallbackConfiguration.class);
when(configuration.getType()).thenReturn(DummyAlarmCallback.class.getCanonicalName());
AlarmCallback alarmCallback = alarmCallbackFactory.create(configuration);
assertNotNull(alarmCallback);
assertTrue(alarmCallback instanceof DummyAlarmCallback);
assertEquals(dummyAlarmCallback, alarmCallback);
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlertNotificationsSenderTest method executeStreamWithNotifications.
@Test
public void executeStreamWithNotifications() throws Exception {
final Stream stream = mock(Stream.class);
final Alert alert = mock(Alert.class);
final AlertCondition alertCondition = mock(AlertCondition.class);
final AlertCondition.CheckResult positiveCheckResult = new AbstractAlertCondition.CheckResult(true, alertCondition, "Mocked positive CheckResult", Tools.nowUTC(), Collections.emptyList());
final AlarmCallbackConfiguration alarmCallbackConfiguration = mock(AlarmCallbackConfiguration.class);
when(alarmCallbackConfigurationService.getForStream(eq(stream))).thenReturn(ImmutableList.of(alarmCallbackConfiguration));
final AlarmCallback alarmCallback = mock(AlarmCallback.class);
when(alarmCallbackFactory.create(eq(alarmCallbackConfiguration))).thenReturn(alarmCallback);
alertNotificationsSender.send(positiveCheckResult, stream, alert, alertCondition);
final ArgumentCaptor<Stream> streamCaptor = ArgumentCaptor.forClass(Stream.class);
final ArgumentCaptor<AlertCondition.CheckResult> checkResultCaptor = ArgumentCaptor.forClass(AlertCondition.CheckResult.class);
verify(alarmCallback, times(1)).call(streamCaptor.capture(), checkResultCaptor.capture());
assertThat(streamCaptor.getValue()).isEqualTo(stream);
assertThat(checkResultCaptor.getValue()).isEqualTo(positiveCheckResult);
final ArgumentCaptor<AlarmCallbackConfiguration> alarmCallbackConfigurationCaptor = ArgumentCaptor.forClass(AlarmCallbackConfiguration.class);
final ArgumentCaptor<Alert> alertCaptor = ArgumentCaptor.forClass(Alert.class);
final ArgumentCaptor<AlertCondition> alertConditionCaptor = ArgumentCaptor.forClass(AlertCondition.class);
verify(alarmCallbackHistoryService, times(1)).success(alarmCallbackConfigurationCaptor.capture(), alertCaptor.capture(), alertConditionCaptor.capture());
assertThat(alarmCallbackConfigurationCaptor.getValue()).isEqualTo(alarmCallbackConfiguration);
assertThat(alertCaptor.getValue()).isEqualTo(alert);
assertThat(alertConditionCaptor.getValue()).isEqualTo(alertCondition);
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlertNotificationsSender method send.
public void send(AlertCondition.CheckResult result, Stream stream, Alert alert, AlertCondition alertCondition) {
final List<AlarmCallbackConfiguration> callConfigurations = alarmCallbackConfigurationService.getForStream(stream);
// Checking if alarm callbacks have been defined
for (AlarmCallbackConfiguration configuration : callConfigurations) {
AlarmCallbackHistory alarmCallbackHistory;
AlarmCallback alarmCallback = null;
try {
alarmCallback = alarmCallbackFactory.create(configuration);
alarmCallback.call(stream, result);
alarmCallbackHistory = alarmCallbackHistoryService.success(configuration, alert, alertCondition);
} catch (Exception e) {
if (alarmCallback != null) {
LOG.warn("Alarm callback <" + alarmCallback.getName() + "> failed. Skipping.", e);
} else {
LOG.warn("Alarm callback with id " + configuration.getId() + " failed. Skipping.", e);
}
alarmCallbackHistory = alarmCallbackHistoryService.error(configuration, alert, alertCondition, e.getMessage());
}
try {
alarmCallbackHistoryService.save(alarmCallbackHistory);
} catch (Exception e) {
LOG.warn("Unable to save history of alarm callback run: ", e);
}
}
}
use of org.graylog2.plugin.alarms.callbacks.AlarmCallback in project graylog2-server by Graylog2.
the class AlarmCallbackFactory method create.
public AlarmCallback create(AlarmCallbackConfiguration configuration) throws ClassNotFoundException, AlarmCallbackConfigurationException {
AlarmCallback alarmCallback = create(configuration.getType());
alarmCallback.initialize(new Configuration(configuration.getConfiguration()));
return alarmCallback;
}
Aggregations