From 68100d7ee67509b3bfc43997422c7614ba00e7c3 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:52:11 -0800 Subject: [PATCH] Overriding defaultTitle with subject for SNS notifications (#708) (#723) * Overriding defaultTitle with subject for SNS notifications Signed-off-by: uros * Overriding defaultTitle with subject for SNS notifications - condition fix Signed-off-by: uros Signed-off-by: uros (cherry picked from commit 88536b233c56d687ae61b7c31b69b883b7b1affe) Co-authored-by: uroskarama <117112198+uroskarama@users.noreply.github.com> Signed-off-by: AWSHurneyt --- .../util/destinationmigration/NotificationApiUtils.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/destinationmigration/NotificationApiUtils.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/destinationmigration/NotificationApiUtils.kt index 489aa59d6..ed8bd8fcb 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/destinationmigration/NotificationApiUtils.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/destinationmigration/NotificationApiUtils.kt @@ -26,6 +26,7 @@ import org.opensearch.commons.notifications.action.LegacyPublishNotificationRequ import org.opensearch.commons.notifications.action.LegacyPublishNotificationResponse import org.opensearch.commons.notifications.action.SendNotificationResponse import org.opensearch.commons.notifications.model.ChannelMessage +import org.opensearch.commons.notifications.model.ConfigType import org.opensearch.commons.notifications.model.EventSource import org.opensearch.commons.notifications.model.NotificationConfigInfo import org.opensearch.commons.notifications.model.SeverityType @@ -136,12 +137,14 @@ suspend fun NotificationConfigInfo.sendNotification(client: Client, title: Strin } /** - * A placeholder Alerting title will be used if no subject is passed in. + * For most channel types, a placeholder Alerting title will be used but the email channel/SNS notification will + * use the subject, so it appears as the actual subject of the email/SNS notification. */ fun NotificationConfigInfo.getTitle(subject: String?): String { val defaultTitle = "Alerting-Notification Action" - return if (subject.isNullOrEmpty()) defaultTitle else subject -} + if (this.notificationConfig.configType == ConfigType.EMAIL || this.notificationConfig.configType == ConfigType.SNS) { + return if (subject.isNullOrEmpty()) defaultTitle else subject + } /** * All valid response statuses.