Search in sources :

Example 1 with AlertReceivers

use of org.graylog2.rest.models.alarmcallbacks.requests.AlertReceivers in project graylog2-server by Graylog2.

the class V20161125161400_AlertReceiversMigration method updateConfiguration.

private Optional<String> updateConfiguration(Stream stream, AlarmCallbackConfiguration callbackConfiguration) {
    final Map<String, List<String>> alertReceivers = stream.getAlertReceivers();
    final List<String> usernames = alertReceivers.get("users");
    final List<String> emails = alertReceivers.get("emails");
    final Map<String, Object> configuration = callbackConfiguration.getConfiguration();
    if (usernames != null && !usernames.isEmpty()) {
        LOG.debug("Moving users alert receivers from stream <" + stream.getId() + ">");
        configuration.put(EmailAlarmCallback.CK_USER_RECEIVERS, usernames);
    }
    if (emails != null && !emails.isEmpty()) {
        LOG.debug("Moving emails alert receivers from stream <" + stream.getId() + ">");
        configuration.put(EmailAlarmCallback.CK_EMAIL_RECEIVERS, emails);
    }
    final AlarmCallbackConfigurationImpl updatedConfiguration = ((AlarmCallbackConfigurationImpl) callbackConfiguration).toBuilder().setConfiguration(configuration).build();
    try {
        final String callbackId = this.alarmCallbackService.save(updatedConfiguration);
        LOG.debug("Successfully created email alarm callback <" + callbackId + "> for stream <" + stream.getId() + ">.");
        return Optional.of(callbackId);
    } catch (ValidationException e) {
        LOG.error("Unable to create email alarm callback for stream <" + stream.getId() + ">: ", e);
    }
    return Optional.empty();
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) List(java.util.List) BasicDBObject(com.mongodb.BasicDBObject) AlarmCallbackConfigurationImpl(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl)

Aggregations

BasicDBObject (com.mongodb.BasicDBObject)1 List (java.util.List)1 AlarmCallbackConfigurationImpl (org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl)1 ValidationException (org.graylog2.plugin.database.ValidationException)1