Search in sources :

Example 1 with LegacyAlarmCallbackEventNotificationConfig

use of org.graylog.events.legacy.LegacyAlarmCallbackEventNotificationConfig in project graylog2-server by Graylog2.

the class V20191129134600_CreateInitialUrlWhitelist method extractFromNotification.

private Optional<WhitelistEntry> extractFromNotification(NotificationDto notificationDto) {
    final EventNotificationConfig config = notificationDto.config();
    String url = "";
    if (config instanceof HTTPEventNotificationConfig) {
        url = ((HTTPEventNotificationConfig) config).url();
    } else if (config instanceof LegacyAlarmCallbackEventNotificationConfig) {
        url = Objects.toString(((LegacyAlarmCallbackEventNotificationConfig) config).configuration().get("url"), "");
    }
    if (StringUtils.isNotBlank(url)) {
        return defaultIfNotMatching(LiteralWhitelistEntry.create(UUID.randomUUID().toString(), "\"" + notificationDto.title() + "\" alert notification", url), url);
    } else {
        return Optional.empty();
    }
}
Also used : LegacyAlarmCallbackEventNotificationConfig(org.graylog.events.legacy.LegacyAlarmCallbackEventNotificationConfig) EventNotificationConfig(org.graylog.events.notifications.EventNotificationConfig) HTTPEventNotificationConfig(org.graylog.events.notifications.types.HTTPEventNotificationConfig) LegacyAlarmCallbackEventNotificationConfig(org.graylog.events.legacy.LegacyAlarmCallbackEventNotificationConfig) HTTPEventNotificationConfig(org.graylog.events.notifications.types.HTTPEventNotificationConfig)

Example 2 with LegacyAlarmCallbackEventNotificationConfig

use of org.graylog.events.legacy.LegacyAlarmCallbackEventNotificationConfig in project graylog2-server by Graylog2.

the class NotificationDtoTest method testValidateLegacyWithEmptyConfigParameters.

@Test
public void testValidateLegacyWithEmptyConfigParameters() {
    final LegacyAlarmCallbackEventNotificationConfig emptyConfig = LegacyAlarmCallbackEventNotificationConfig.Builder.create().callbackType("").configuration(new HashMap<>()).build();
    final NotificationDto emptyNotification = getLegacyNotification().toBuilder().config(emptyConfig).build();
    final ValidationResult validationResult = emptyNotification.validate();
    assertThat(validationResult.failed()).isTrue();
    assertThat(validationResult.getErrors()).containsOnlyKeys("callback_type");
}
Also used : HashMap(java.util.HashMap) LegacyAlarmCallbackEventNotificationConfig(org.graylog.events.legacy.LegacyAlarmCallbackEventNotificationConfig) ValidationResult(org.graylog2.plugin.rest.ValidationResult) Test(org.junit.Test)

Aggregations

LegacyAlarmCallbackEventNotificationConfig (org.graylog.events.legacy.LegacyAlarmCallbackEventNotificationConfig)2 HashMap (java.util.HashMap)1 EventNotificationConfig (org.graylog.events.notifications.EventNotificationConfig)1 HTTPEventNotificationConfig (org.graylog.events.notifications.types.HTTPEventNotificationConfig)1 ValidationResult (org.graylog2.plugin.rest.ValidationResult)1 Test (org.junit.Test)1