Search in sources :

Example 6 with AlarmCallbackHistory

use of org.graylog2.alarmcallbacks.AlarmCallbackHistory 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);
        }
    }
}
Also used : AlarmCallbackHistory(org.graylog2.alarmcallbacks.AlarmCallbackHistory) AlarmCallback(org.graylog2.plugin.alarms.callbacks.AlarmCallback) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)

Aggregations

Date (java.util.Date)4 Alert (org.graylog2.alerts.Alert)4 MongoDBServiceTest (org.graylog2.database.MongoDBServiceTest)4 AlertCondition (org.graylog2.plugin.alarms.AlertCondition)4 Test (org.junit.Test)4 IgnorePropertyValue (com.lordofthejars.nosqlunit.annotation.IgnorePropertyValue)2 ShouldMatchDataSet (com.lordofthejars.nosqlunit.annotation.ShouldMatchDataSet)2 UsingDataSet (com.lordofthejars.nosqlunit.annotation.UsingDataSet)2 AlarmCallbackHistory (org.graylog2.alarmcallbacks.AlarmCallbackHistory)2 Timed (com.codahale.metrics.annotation.Timed)1 ApiOperation (io.swagger.annotations.ApiOperation)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 AlarmCallbackConfiguration (org.graylog2.alarmcallbacks.AlarmCallbackConfiguration)1 AlarmCallback (org.graylog2.plugin.alarms.callbacks.AlarmCallback)1 AlarmCallbackError (org.graylog2.rest.models.alarmcallbacks.AlarmCallbackError)1 AlarmCallbackHistorySummary (org.graylog2.rest.models.alarmcallbacks.AlarmCallbackHistorySummary)1