From c244a99b4cd46f7ec8fb20b96b695b10c0bd7bd8 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 30 May 2024 18:34:40 -0700 Subject: [PATCH] alertsInCorrelation without notifciations Signed-off-by: Riya Saxena --- .../util/NotificationApiHelper.java | 41 -------------- .../util/NotificationApiUtils.java | 56 ------------------- 2 files changed, 97 deletions(-) delete mode 100644 src/main/java/org/opensearch/securityanalytics/util/NotificationApiHelper.java delete mode 100644 src/main/java/org/opensearch/securityanalytics/util/NotificationApiUtils.java diff --git a/src/main/java/org/opensearch/securityanalytics/util/NotificationApiHelper.java b/src/main/java/org/opensearch/securityanalytics/util/NotificationApiHelper.java deleted file mode 100644 index d1499a135..000000000 --- a/src/main/java/org/opensearch/securityanalytics/util/NotificationApiHelper.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.opensearch.securityanalytics.util; - -import org.opensearch.commons.notifications.model.ChannelMessage; -import org.opensearch.commons.notifications.model.EventSource; -import org.opensearch.commons.notifications.model.SeverityType; - -import java.util.List; -/** - * Helper class for sending test notifications. - */ -public class NotificationApiHelper { - - public static ChannelMessage generateMessage(String configId) { - return new ChannelMessage( - getMessageTextDescription(configId), - getMessageHtmlDescription(configId), - null - ); - } - - public static EventSource generateEventSource(String configId, String severity, List tags) { - return new EventSource( - getMessageTitle(configId), - configId, - SeverityType.INFO, - tags - ); - } - - private static String getMessageTitle(String configId) { - return "Test Message Title-" + configId; // TODO: change as per spec - } - - private static String getMessageTextDescription(String configId) { - return "Test message content body for config id " + configId; // TODO: change as per spec - } - - private static String getMessageHtmlDescription(String configId) { - return "
Test Message

Test Message for config id " + configId + "

"; // TODO: change as per spec - } -} diff --git a/src/main/java/org/opensearch/securityanalytics/util/NotificationApiUtils.java b/src/main/java/org/opensearch/securityanalytics/util/NotificationApiUtils.java deleted file mode 100644 index 618de8527..000000000 --- a/src/main/java/org/opensearch/securityanalytics/util/NotificationApiUtils.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.util; - -import com.google.protobuf.BoolValue; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.action.bulk.BackoffPolicy; -import org.opensearch.client.node.NodeClient; -import org.opensearch.common.unit.TimeValue; -import org.opensearch.commons.notifications.NotificationsPluginInterface; -import org.opensearch.commons.notifications.action.*; -import org.opensearch.commons.notifications.model.ChannelMessage; -import org.opensearch.commons.notifications.model.EventSource; -import org.opensearch.commons.notifications.model.NotificationConfigInfo; -import org.opensearch.commons.notifications.model.SeverityType; -import org.opensearch.core.action.ActionListener; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.rest.RestStatus; - -import java.io.IOException; -import java.util.List; -import java.util.Set; - -public class NotificationApiUtils { - - private static final Logger logger = LogManager.getLogger(NotificationApiUtils.class); - /** - * Extension function for publishing a notification to a channel in the Notification plugin. - */ - public static void sendNotification(NodeClient client, String configId, String severity, List channelIds) throws IOException { - ChannelMessage message = NotificationApiHelper.generateMessage(configId); - NotificationsPluginInterface.INSTANCE.sendNotification(client, new EventSource(configId, configId, SeverityType.CRITICAL, channelIds), message, channelIds, new ActionListener() { - @Override - public void onResponse(SendNotificationResponse sendNotificationResponse) { - if(sendNotificationResponse.getStatus() == RestStatus.OK) { - logger.info("Successfully sent a notification, Notification Event: " + sendNotificationResponse.getNotificationEvent()); - } - else { - logger.error("Successfully sent a notification, Notification Event: " + sendNotificationResponse.getNotificationEvent()); - } - - } - @Override - public void onFailure(Exception e) { - logger.error("Failed while sending a notification: " + e.toString()); - new SecurityAnalyticsException("Failed to send notification", RestStatus.INTERNAL_SERVER_ERROR, e); - } - }); - } - - -} \ No newline at end of file