From dfea35036279a0e3ac226b2306b2c6324a47beda Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 21 Jul 2021 13:17:42 -0400 Subject: [PATCH 01/17] add originalstatus field to alert status struct --- engine/sendmessage.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index 50fc1d1efc..18b713b013 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -91,11 +91,17 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if err != nil { return nil, errors.Wrap(err, "lookup alert log entry") } + + stat, err := p.cfg.NotificationStore.OriginalMessageStatus(ctx, msg.AlertID, msg.Dest) + if err != nil { + return nil, fmt.Errorf("lookup original message: %w", err) + } notifMsg = notification.AlertStatus{ - Dest: msg.Dest, - AlertID: e.AlertID(), - CallbackID: msg.ID, - LogEntry: e.String(), + Dest: msg.Dest, + AlertID: e.AlertID(), + CallbackID: msg.ID, + LogEntry: e.String(), + OriginalStatus: stat, } case notification.MessageTypeTest: notifMsg = notification.Test{ From 29d56ecf6e6f49a3d8ef05ee7dc7e525cd61adc1 Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 21 Jul 2021 13:17:52 -0400 Subject: [PATCH 02/17] add field to struct --- notification/alertstatus.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 7f87d6d4c7..081a3a09c2 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -5,6 +5,9 @@ type AlertStatus struct { CallbackID string AlertID int LogEntry string + + // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. + OriginalStatus *SendResult } var _ Message = &AlertStatus{} From e1bb15218b1552fd6f431f26290c9cf66f03b034 Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 21 Jul 2021 13:18:18 -0400 Subject: [PATCH 03/17] add alert status replies in thread in slack --- notification/slack/channel.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notification/slack/channel.go b/notification/slack/channel.go index 29790a0fa0..804ba805b1 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -321,12 +321,16 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str if t.OriginalStatus != nil { // Reply in thread if we already sent a message for this alert. vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) - vals.Set("text", "Escalated.") + // only if escalation results in second notification to channel + vals.Set("text", "Notified.") vals.Set("reply_broadcast", "true") break } vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID)))) + case notification.AlertStatus: + vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) + vals.Set("text", t.LogEntry) case notification.AlertBundle: vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts"))) case notification.ScheduleOnCallUsers: From 36ab498e3076635c3f2040177a831a52e3f39da6 Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 21 Jul 2021 13:18:50 -0400 Subject: [PATCH 04/17] modified rate limiting to include only some types --- engine/message/ratelimit.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/message/ratelimit.go b/engine/message/ratelimit.go index e75fd7d1d2..9f928b9666 100644 --- a/engine/message/ratelimit.go +++ b/engine/message/ratelimit.go @@ -15,8 +15,10 @@ var PerCMThrottle ThrottleConfig func init() { var perCM ThrottleConfigBuilder - // all message types - perCM.AddRules([]ThrottleRule{{Count: 1, Per: time.Minute}}) + // Rate limit sms, voice and email types + perCM. + WithDestTypes(notification.DestTypeVoice, notification.DestTypeSMS, notification.DestTypeUserEmail). + AddRules([]ThrottleRule{{Count: 1, Per: time.Minute}}) // On-Call Status Notifications perCM. @@ -29,6 +31,7 @@ func init() { // status notifications perCM. WithMsgTypes(notification.MessageTypeAlertStatus). + WithDestTypes(notification.DestTypeVoice, notification.DestTypeSMS, notification.DestTypeUserEmail). AddRules([]ThrottleRule{ {Count: 1, Per: 3 * time.Minute}, {Count: 3, Per: 20 * time.Minute}, From 5ef54dfba99019b2b97ae6e714f9e4d0c2314f2c Mon Sep 17 00:00:00 2001 From: arurao Date: Thu, 22 Jul 2021 14:18:06 -0400 Subject: [PATCH 05/17] adding alert as a field to alertstatus --- engine/sendmessage.go | 19 +++++++++++++++---- notification/alertstatus.go | 4 ++-- notification/slack/channel.go | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index 18b713b013..92cb15fb24 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -91,18 +91,29 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if err != nil { return nil, errors.Wrap(err, "lookup alert log entry") } - + a, err := p.cfg.AlertStore.FindOne(ctx, msg.AlertID) + if err != nil { + return nil, fmt.Errorf("lookup original alert: %w", err) + } stat, err := p.cfg.NotificationStore.OriginalMessageStatus(ctx, msg.AlertID, msg.Dest) if err != nil { return nil, fmt.Errorf("lookup original message: %w", err) } - notifMsg = notification.AlertStatus{ + alert := notification.Alert{ Dest: msg.Dest, - AlertID: e.AlertID(), CallbackID: msg.ID, - LogEntry: e.String(), + AlertID: e.AlertID(), + Summary: a.Summary, + Details: a.Details, OriginalStatus: stat, } + notifMsg = notification.AlertStatus{ + Dest: msg.Dest, + AlertID: e.AlertID(), + CallbackID: msg.ID, + LogEntry: e.String(), + Alert: alert, + } case notification.MessageTypeTest: notifMsg = notification.Test{ Dest: msg.Dest, diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 081a3a09c2..72196865be 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -6,8 +6,8 @@ type AlertStatus struct { AlertID int LogEntry string - // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. - OriginalStatus *SendResult + // The Alert that this status is in regard to. + Alert Alert } var _ Message = &AlertStatus{} diff --git a/notification/slack/channel.go b/notification/slack/channel.go index 804ba805b1..9812f58e8c 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -329,7 +329,7 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID)))) case notification.AlertStatus: - vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) + vals.Set("thread_ts", t.Alert.OriginalStatus.ProviderMessageID.ExternalID) vals.Set("text", t.LogEntry) case notification.AlertBundle: vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts"))) From 6fb9fbb1090fec66a67531d22876dff5e80455f8 Mon Sep 17 00:00:00 2001 From: arurao Date: Thu, 22 Jul 2021 15:02:06 -0400 Subject: [PATCH 06/17] added fields for summary and details --- engine/sendmessage.go | 12 +++--------- notification/alertstatus.go | 9 +++++++-- notification/slack/channel.go | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index 92cb15fb24..c8ba22338c 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -99,21 +99,15 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if err != nil { return nil, fmt.Errorf("lookup original message: %w", err) } - alert := notification.Alert{ + notifMsg = notification.AlertStatus{ Dest: msg.Dest, - CallbackID: msg.ID, AlertID: e.AlertID(), + CallbackID: msg.ID, + LogEntry: e.String(), Summary: a.Summary, Details: a.Details, OriginalStatus: stat, } - notifMsg = notification.AlertStatus{ - Dest: msg.Dest, - AlertID: e.AlertID(), - CallbackID: msg.ID, - LogEntry: e.String(), - Alert: alert, - } case notification.MessageTypeTest: notifMsg = notification.Test{ Dest: msg.Dest, diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 72196865be..9b387411b4 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -6,8 +6,13 @@ type AlertStatus struct { AlertID int LogEntry string - // The Alert that this status is in regard to. - Alert Alert + // Summary of the alert that this status is in regards to. + Summary string + // Details of the alert that this status is in regards to. + Details string + + // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. + OriginalStatus *SendResult } var _ Message = &AlertStatus{} diff --git a/notification/slack/channel.go b/notification/slack/channel.go index 9812f58e8c..804ba805b1 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -329,7 +329,7 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID)))) case notification.AlertStatus: - vals.Set("thread_ts", t.Alert.OriginalStatus.ProviderMessageID.ExternalID) + vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) vals.Set("text", t.LogEntry) case notification.AlertBundle: vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts"))) From 3eeab92961fede6cdecab047779fc54392bd9841 Mon Sep 17 00:00:00 2001 From: Arundhati Rao Date: Wed, 28 Jul 2021 15:45:40 -0400 Subject: [PATCH 07/17] Update notification/alertstatus.go Co-authored-by: Nathaniel Caza --- notification/alertstatus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 9b387411b4..d25d00a1a1 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -12,7 +12,7 @@ type AlertStatus struct { Details string // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. - OriginalStatus *SendResult + OriginalStatus SendResult } var _ Message = &AlertStatus{} From 0ab269992871e46947f10fc1e1f554e4629766a5 Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 28 Jul 2021 15:47:27 -0400 Subject: [PATCH 08/17] updating field as per alert status struct --- engine/sendmessage.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index c8ba22338c..c175a6495c 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -106,7 +106,7 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi LogEntry: e.String(), Summary: a.Summary, Details: a.Details, - OriginalStatus: stat, + OriginalStatus: *stat, } case notification.MessageTypeTest: notifMsg = notification.Test{ From 3e74c04f91a48f0acce979ad02cea548233d00ac Mon Sep 17 00:00:00 2001 From: arurao Date: Thu, 29 Jul 2021 17:08:27 -0400 Subject: [PATCH 09/17] return err if couldn't find orig msg,tweak to test --- engine/sendmessage.go | 3 +++ smoketest/statusinprogress_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index c175a6495c..e2e10966c9 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -99,6 +99,9 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if err != nil { return nil, fmt.Errorf("lookup original message: %w", err) } + if stat == nil { + return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String()) + } notifMsg = notification.AlertStatus{ Dest: msg.Dest, AlertID: e.AlertID(), diff --git a/smoketest/statusinprogress_test.go b/smoketest/statusinprogress_test.go index 8c2277bb2c..56507520c8 100644 --- a/smoketest/statusinprogress_test.go +++ b/smoketest/statusinprogress_test.go @@ -47,6 +47,10 @@ func TestStatusInProgress(t *testing.T) { insert into user_last_alert_log (user_id, alert_id, log_id, next_log_id) values ({{uuid "u1"}}, 1, 102, 103); + + insert into outgoing_messages(message_type, user_id, contact_method_id, alert_id, service_id, escalation_policy_id, last_status, sent_at) + values + ('alert_notification', {{uuid "u1"}}, {{uuid "c1"}}, 1, {{uuid "sid"}}, {{uuid "eid"}}, 'sent', now()); ` h := harness.NewHarness(t, sql, "sched-module-v3") From e6cc988cb7a72fa54ab0e1416802edb898c234aa Mon Sep 17 00:00:00 2001 From: Arundhati Rao Date: Tue, 3 Aug 2021 13:20:14 -0400 Subject: [PATCH 10/17] Update notification/slack/channel.go Co-authored-by: David Talbot --- notification/slack/channel.go | 1 - 1 file changed, 1 deletion(-) diff --git a/notification/slack/channel.go b/notification/slack/channel.go index 804ba805b1..32c4771174 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -321,7 +321,6 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str if t.OriginalStatus != nil { // Reply in thread if we already sent a message for this alert. vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) - // only if escalation results in second notification to channel vals.Set("text", "Notified.") vals.Set("reply_broadcast", "true") break From 84a0763385631be869434fc3131ea7afdf556e48 Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 4 Aug 2021 17:08:34 -0400 Subject: [PATCH 11/17] rewording and prefixing with current status --- engine/sendmessage.go | 11 +++++++++++ notification/alertstatus.go | 2 ++ notification/slack/channel.go | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index e2e10966c9..07b98df041 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -102,6 +102,16 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if stat == nil { return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String()) } + var status string + switch e.Type() { + case alertlog.TypeAcknowledged: + status = "Acknowledged" + case alertlog.TypeEscalated: + status = "Unacknowledged" + case alertlog.TypeClosed: + status = "Closed" + default: + } notifMsg = notification.AlertStatus{ Dest: msg.Dest, AlertID: e.AlertID(), @@ -109,6 +119,7 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi LogEntry: e.String(), Summary: a.Summary, Details: a.Details, + Status: status, OriginalStatus: *stat, } case notification.MessageTypeTest: diff --git a/notification/alertstatus.go b/notification/alertstatus.go index d25d00a1a1..737b698fff 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -13,6 +13,8 @@ type AlertStatus struct { // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. OriginalStatus SendResult + + Status string } var _ Message = &AlertStatus{} diff --git a/notification/slack/channel.go b/notification/slack/channel.go index 804ba805b1..7125b18507 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -322,7 +322,7 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str // Reply in thread if we already sent a message for this alert. vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) // only if escalation results in second notification to channel - vals.Set("text", "Notified.") + vals.Set("text", "Broadcasting to channel, due to repeat notification.") vals.Set("reply_broadcast", "true") break } @@ -330,7 +330,8 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID)))) case notification.AlertStatus: vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) - vals.Set("text", t.LogEntry) + text := "Status Update: " + t.Status + "\n" + t.LogEntry + vals.Set("text", text) case notification.AlertBundle: vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts"))) case notification.ScheduleOnCallUsers: From ad51d0e7c2057670ac2f37121934c5a267b922d8 Mon Sep 17 00:00:00 2001 From: arurao Date: Wed, 4 Aug 2021 17:11:28 -0400 Subject: [PATCH 12/17] added comment --- notification/alertstatus.go | 1 + 1 file changed, 1 insertion(+) diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 737b698fff..c3c3678854 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -14,6 +14,7 @@ type AlertStatus struct { // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. OriginalStatus SendResult + // Status is the most recent status of the Alert. Status string } From 31a23a20c53958feba50bd1abeda2160aea91bcb Mon Sep 17 00:00:00 2001 From: Arundhati Rao Date: Wed, 4 Aug 2021 17:39:55 -0400 Subject: [PATCH 13/17] Update notification/slack/channel.go Co-authored-by: David Talbot --- notification/slack/channel.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification/slack/channel.go b/notification/slack/channel.go index a0a2be81ee..6585640977 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -321,7 +321,7 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str if t.OriginalStatus != nil { // Reply in thread if we already sent a message for this alert. vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) - vals.Set("text", "Broadcasting to channel, due to repeat notification.") + vals.Set("text", "Broadcasting to channel due to repeat notification.") vals.Set("reply_broadcast", "true") break } From 0cf103f58dda2bfe1f9d15c38102f55cde5da4ea Mon Sep 17 00:00:00 2001 From: arurao Date: Thu, 5 Aug 2021 16:18:12 -0400 Subject: [PATCH 14/17] new type for status --- engine/sendmessage.go | 10 +++++----- notification/alertstatus.go | 13 +++++++++++-- notification/slack/channel.go | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index 07b98df041..90fedeaa3b 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -102,14 +102,14 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if stat == nil { return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String()) } - var status string + var status notification.RecentStatus switch e.Type() { case alertlog.TypeAcknowledged: - status = "Acknowledged" + status = notification.RecentStatusAcknowledged case alertlog.TypeEscalated: - status = "Unacknowledged" + status = notification.RecentStatusUnacknowledged case alertlog.TypeClosed: - status = "Closed" + status = notification.RecentStatusClosed default: } notifMsg = notification.AlertStatus{ @@ -119,7 +119,7 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi LogEntry: e.String(), Summary: a.Summary, Details: a.Details, - Status: status, + FriendlyStatus: status, OriginalStatus: *stat, } case notification.MessageTypeTest: diff --git a/notification/alertstatus.go b/notification/alertstatus.go index c3c3678854..8dc426d0e8 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -1,5 +1,14 @@ package notification +type RecentStatus string + +// Notification status types +const ( + RecentStatusClosed RecentStatus = "Closed" + RecentStatusAcknowledged RecentStatus = "Acknowledged" + RecentStatusUnacknowledged RecentStatus = "Unacknowledged" +) + type AlertStatus struct { Dest Dest CallbackID string @@ -14,8 +23,8 @@ type AlertStatus struct { // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. OriginalStatus SendResult - // Status is the most recent status of the Alert. - Status string + // FriendlyStatus is the most recent status of the Alert, which is to be used for display purposes only. + FriendlyStatus RecentStatus } var _ Message = &AlertStatus{} diff --git a/notification/slack/channel.go b/notification/slack/channel.go index a0a2be81ee..beaddf9228 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -329,7 +329,7 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID)))) case notification.AlertStatus: vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) - text := "Status Update: " + t.Status + "\n" + t.LogEntry + text := "Status Update: " + string(t.FriendlyStatus) + "\n" + t.LogEntry vals.Set("text", text) case notification.AlertBundle: vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts"))) From 4878af9ad8fb76bc27ef2b641a7e68d1366cab87 Mon Sep 17 00:00:00 2001 From: arurao Date: Thu, 5 Aug 2021 17:43:02 -0400 Subject: [PATCH 15/17] use alert.Status in the new field --- engine/sendmessage.go | 12 +----------- notification/alertstatus.go | 13 +++---------- notification/slack/channel.go | 13 ++++++++++++- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index 90fedeaa3b..b4c4cd603b 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -102,16 +102,6 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if stat == nil { return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String()) } - var status notification.RecentStatus - switch e.Type() { - case alertlog.TypeAcknowledged: - status = notification.RecentStatusAcknowledged - case alertlog.TypeEscalated: - status = notification.RecentStatusUnacknowledged - case alertlog.TypeClosed: - status = notification.RecentStatusClosed - default: - } notifMsg = notification.AlertStatus{ Dest: msg.Dest, AlertID: e.AlertID(), @@ -119,7 +109,7 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi LogEntry: e.String(), Summary: a.Summary, Details: a.Details, - FriendlyStatus: status, + NewAlertStatus: a.Status, OriginalStatus: *stat, } case notification.MessageTypeTest: diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 8dc426d0e8..56ca1cb8b8 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -1,13 +1,6 @@ package notification -type RecentStatus string - -// Notification status types -const ( - RecentStatusClosed RecentStatus = "Closed" - RecentStatusAcknowledged RecentStatus = "Acknowledged" - RecentStatusUnacknowledged RecentStatus = "Unacknowledged" -) +import "github.com/target/goalert/alert" type AlertStatus struct { Dest Dest @@ -23,8 +16,8 @@ type AlertStatus struct { // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. OriginalStatus SendResult - // FriendlyStatus is the most recent status of the Alert, which is to be used for display purposes only. - FriendlyStatus RecentStatus + // NewState contains the most recent status for the alert. + NewAlertStatus alert.Status } var _ Message = &AlertStatus{} diff --git a/notification/slack/channel.go b/notification/slack/channel.go index b732d969a9..9c148ef3ee 100644 --- a/notification/slack/channel.go +++ b/notification/slack/channel.go @@ -11,6 +11,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/target/goalert/alert" "github.com/target/goalert/config" "github.com/target/goalert/notification" "github.com/target/goalert/permission" @@ -329,7 +330,17 @@ func (s *ChannelSender) Send(ctx context.Context, msg notification.Message) (str vals.Set("text", fmt.Sprintf("Alert: %s\n\n<%s>", t.Summary, cfg.CallbackURL("/alerts/"+strconv.Itoa(t.AlertID)))) case notification.AlertStatus: vals.Set("thread_ts", t.OriginalStatus.ProviderMessageID.ExternalID) - text := "Status Update: " + string(t.FriendlyStatus) + "\n" + t.LogEntry + var status string + switch t.NewAlertStatus { + case alert.StatusActive: + status = "Acknowledged" + case alert.StatusTriggered: + status = "Unacknowledged" + case alert.StatusClosed: + status = "Closed" + } + + text := "Status Update: " + status + "\n" + t.LogEntry vals.Set("text", text) case notification.AlertBundle: vals.Set("text", fmt.Sprintf("Service '%s' has %d unacknowledged alerts.\n\n<%s>", t.ServiceName, t.Count, cfg.CallbackURL("/services/"+t.ServiceID+"/alerts"))) From ddedcb9413460df4b262c7239b30d7ebe8490a21 Mon Sep 17 00:00:00 2001 From: arurao Date: Thu, 12 Aug 2021 12:19:37 -0400 Subject: [PATCH 16/17] mapping statuses in engine --- engine/sendmessage.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/engine/sendmessage.go b/engine/sendmessage.go index b4c4cd603b..acc5a27b82 100644 --- a/engine/sendmessage.go +++ b/engine/sendmessage.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/pkg/errors" + "github.com/target/goalert/alert" alertlog "github.com/target/goalert/alert/log" "github.com/target/goalert/engine/message" "github.com/target/goalert/notification" @@ -102,6 +103,17 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi if stat == nil { return nil, fmt.Errorf("could not find original notification for alert %d to %s", msg.AlertID, msg.Dest.String()) } + + var status alert.Status + switch e.Type() { + case alertlog.TypeAcknowledged: + status = alert.StatusActive + case alertlog.TypeEscalated: + status = alert.StatusTriggered + case alertlog.TypeClosed: + status = alert.StatusClosed + } + notifMsg = notification.AlertStatus{ Dest: msg.Dest, AlertID: e.AlertID(), @@ -109,7 +121,7 @@ func (p *Engine) sendMessage(ctx context.Context, msg *message.Message) (*notifi LogEntry: e.String(), Summary: a.Summary, Details: a.Details, - NewAlertStatus: a.Status, + NewAlertStatus: status, OriginalStatus: *stat, } case notification.MessageTypeTest: From bf0b8c60e91e128746d2bed14e3c4da523dd7349 Mon Sep 17 00:00:00 2001 From: David Talbot Date: Thu, 12 Aug 2021 13:02:32 -0400 Subject: [PATCH 17/17] Update notification/alertstatus.go --- notification/alertstatus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notification/alertstatus.go b/notification/alertstatus.go index 56ca1cb8b8..bf3b49044f 100644 --- a/notification/alertstatus.go +++ b/notification/alertstatus.go @@ -16,7 +16,7 @@ type AlertStatus struct { // OriginalStatus is the status of the first Alert notification to this Dest for this AlertID. OriginalStatus SendResult - // NewState contains the most recent status for the alert. + // NewAlertStatus contains the most recent status for the alert. NewAlertStatus alert.Status }