Skip to content

Commit

Permalink
PLAT-13506 Allow skipping resolved alert notifications for webhook ch…
Browse files Browse the repository at this point in the history
…annel

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
  • Loading branch information
anmalysh-yb committed May 13, 2024
1 parent f1980c8 commit 60146cc
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlertTemplateVariable> variables = alertTemplateVariableService.list(customer.getUuid());
Context context = new Context(channel, channelTemplates, variables);
String text = getNotificationText(alert, context, false);
Expand Down
4 changes: 4 additions & 0 deletions managed/src/main/resources/swagger-strict.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions managed/src/main/resources/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -385,6 +386,25 @@ export const AddDestinationChannelForm = (props) => {
/>
</Col>
</Row>
<Row className="component-flex">
<Col lg={1} className="noLeftPadding">
<Field name="sendResolved">
{({ field }) => (
<YBToggle
name="sendResolved"
isReadOnly={isReadOnly}
input={{
value: field.value,
onChange: field.onChange
}}
/>
)}
</Field>
</Col>
<Col lg={11} className="component-label">
<strong>Send resolved alert notification</strong>
</Col>
</Row>
<Row>
<Col lg={12}>
<Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const prepareInitialValues = (values) => {
break;
case 'WebHook':
initialValues['webhookURL'] = values.params.webhookUrl;
initialValues['sendResolved'] = values.params.sendResolved;
if (!values.params.httpAuth?.type) {
break;
}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 60146cc

Please sign in to comment.