From 60146cc776d01cbdacc58cb7250ca7519176dfe4 Mon Sep 17 00:00:00 2001 From: Aleksandr Malyshev Date: Mon, 6 May 2024 13:02:04 +0300 Subject: [PATCH] PLAT-13506 Allow skipping resolved alert notifications for webhook channel Summary: Adding a setting to skip resolved alerts notifications via WebHook channel Test Plan: Configure alert destination to webhook channel. Raise alert, make sure webhook is called. Reslove alert, make sure webhook is called. Modify webhook channel config to skip resolved alert notifications. Raise alert, make sure webhook is called. Reslove alert, make sure webhook is not called. Reviewers: vbansal, #yba-api-review! Reviewed By: vbansal Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D34783 --- .../alerts/AlertChannelWebHookParams.java | 8 ++++++++ .../alerts/impl/AlertChannelWebHook.java | 5 +++++ .../src/main/resources/swagger-strict.json | 4 ++++ managed/src/main/resources/swagger.json | 4 ++++ .../AddDestinationChannelForm.js | 20 +++++++++++++++++++ .../AlertDestinationChannels.js | 3 ++- 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/managed/src/main/java/com/yugabyte/yw/common/alerts/AlertChannelWebHookParams.java b/managed/src/main/java/com/yugabyte/yw/common/alerts/AlertChannelWebHookParams.java index d26a1175f363..24431809d506 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/alerts/AlertChannelWebHookParams.java +++ b/managed/src/main/java/com/yugabyte/yw/common/alerts/AlertChannelWebHookParams.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import com.yugabyte.yw.models.AlertChannel.ChannelType; +import com.yugabyte.yw.models.common.YbaApi; import com.yugabyte.yw.models.helpers.auth.HttpAuth; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -27,6 +28,13 @@ public class AlertChannelWebHookParams extends AlertChannelParams { @ApiModelProperty(value = "Authentication Details", accessMode = READ_WRITE) private HttpAuth httpAuth; + @ApiModelProperty( + value = + "WARNING: This is a preview API that could change. " + "Send resolved alert notification", + accessMode = READ_WRITE) + @YbaApi(visibility = YbaApi.YbaApiVisibility.PREVIEW, sinceYBAVersion = "2.23.0.0") + private boolean sendResolved = true; + public AlertChannelWebHookParams() { setChannelType(ChannelType.WebHook); } diff --git a/managed/src/main/java/com/yugabyte/yw/common/alerts/impl/AlertChannelWebHook.java b/managed/src/main/java/com/yugabyte/yw/common/alerts/impl/AlertChannelWebHook.java index b9f3646c5232..7488d375f32a 100644 --- a/managed/src/main/java/com/yugabyte/yw/common/alerts/impl/AlertChannelWebHook.java +++ b/managed/src/main/java/com/yugabyte/yw/common/alerts/impl/AlertChannelWebHook.java @@ -42,6 +42,11 @@ public void sendNotification( throws PlatformNotificationException { log.trace("sendNotification {}", alert); AlertChannelWebHookParams params = (AlertChannelWebHookParams) channel.getParams(); + + if (!params.isSendResolved() && alert.getState() == Alert.State.RESOLVED) { + return; + } + List variables = alertTemplateVariableService.list(customer.getUuid()); Context context = new Context(channel, channelTemplates, variables); String text = getNotificationText(alert, context, false); diff --git a/managed/src/main/resources/swagger-strict.json b/managed/src/main/resources/swagger-strict.json index d2419279fdd7..5cb5496d0ab0 100644 --- a/managed/src/main/resources/swagger-strict.json +++ b/managed/src/main/resources/swagger-strict.json @@ -583,6 +583,10 @@ "$ref" : "#/definitions/HTTP Auth information", "description" : "Authentication Details" }, + "sendResolved" : { + "description" : "WARNING: This is a preview API that could change. Send resolved alert notification", + "type" : "boolean" + }, "webhookUrl" : { "description" : "Webhook URL", "type" : "string" diff --git a/managed/src/main/resources/swagger.json b/managed/src/main/resources/swagger.json index fad0a7488321..405ac77d7b0d 100644 --- a/managed/src/main/resources/swagger.json +++ b/managed/src/main/resources/swagger.json @@ -595,6 +595,10 @@ "$ref" : "#/definitions/HTTP Auth information", "description" : "Authentication Details" }, + "sendResolved" : { + "description" : "WARNING: This is a preview API that could change. Send resolved alert notification", + "type" : "boolean" + }, "webhookUrl" : { "description" : "Webhook URL", "type" : "string" diff --git a/managed/ui/src/components/alerts/AlertConfiguration/AddDestinationChannelForm.js b/managed/ui/src/components/alerts/AlertConfiguration/AddDestinationChannelForm.js index 687e788da84a..b3d395548db5 100644 --- a/managed/ui/src/components/alerts/AlertConfiguration/AddDestinationChannelForm.js +++ b/managed/ui/src/components/alerts/AlertConfiguration/AddDestinationChannelForm.js @@ -95,6 +95,7 @@ export const AddDestinationChannelForm = (props) => { payload['name'] = values['webHook_name']; payload['params']['channelType'] = 'WebHook'; payload['params']['webhookUrl'] = values.webhookURL; + payload['params']['sendResolved'] = values.sendResolved; const httpAuth = { type: webhookAuthType.toUpperCase() @@ -385,6 +386,25 @@ export const AddDestinationChannelForm = (props) => { /> + + + + {({ field }) => ( + + )} + + + + Send resolved alert notification + + { break; case 'WebHook': initialValues['webhookURL'] = values.params.webhookUrl; + initialValues['sendResolved'] = values.params.sendResolved; if (!values.params.httpAuth?.type) { break; } @@ -317,7 +318,7 @@ export const AlertDestinationChannels = (props) => { defaultSmtp={initialValues.defaultSmtp} type={type} editAlertChannel={editAlertChannel} - editValues={type === 'edit' ? initialValues : {}} + editValues={type === 'edit' ? initialValues : {sendResolved: true}} updateDestinationChannel={getAlertChannelsList} enableNotificationTemplates={enableNotificationTemplates} {...props}