diff --git a/notifications/event/type.go b/notifications/event/type.go index 317f695..6acd973 100644 --- a/notifications/event/type.go +++ b/notifications/event/type.go @@ -17,11 +17,6 @@ const ( TypeAcknowledgementCleared // acknowledgement-cleared TypeAcknowledgementSet // acknowledgement-set TypeCustom // custom - TypeDowntimeEnd // downtime-end - TypeDowntimeRemoved // downtime-removed - TypeDowntimeStart // downtime-start - TypeFlappingEnd // flapping-end - TypeFlappingStart // flapping-start TypeIncidentAge // incident-age TypeMute // mute TypeState // state diff --git a/notifications/event/type_string.go b/notifications/event/type_string.go index b360f2b..116be56 100644 --- a/notifications/event/type_string.go +++ b/notifications/event/type_string.go @@ -12,25 +12,21 @@ func _() { _ = x[TypeAcknowledgementCleared-1] _ = x[TypeAcknowledgementSet-2] _ = x[TypeCustom-3] - _ = x[TypeDowntimeEnd-4] - _ = x[TypeDowntimeRemoved-5] - _ = x[TypeDowntimeStart-6] - _ = x[TypeFlappingEnd-7] - _ = x[TypeFlappingStart-8] - _ = x[TypeIncidentAge-9] - _ = x[TypeMute-10] - _ = x[TypeState-11] - _ = x[TypeUnmute-12] - _ = x[typeMax-13] + _ = x[TypeIncidentAge-4] + _ = x[TypeMute-5] + _ = x[TypeState-6] + _ = x[TypeUnmute-7] + _ = x[typeMax-8] } -const _Type_name = "unknownacknowledgement-clearedacknowledgement-setcustomdowntime-enddowntime-removeddowntime-startflapping-endflapping-startincident-agemutestateunmuteinternal" +const _Type_name = "unknownacknowledgement-clearedacknowledgement-setcustomincident-agemutestateunmuteinternal" -var _Type_index = [...]uint8{0, 7, 30, 49, 55, 67, 83, 97, 109, 123, 135, 139, 144, 150, 158} +var _Type_index = [...]uint8{0, 7, 30, 49, 55, 67, 71, 76, 82, 90} func (i Type) String() string { - if i >= Type(len(_Type_index)-1) { + idx := int(i) - 0 + if i < 0 || idx >= len(_Type_index)-1 { return "Type(" + strconv.FormatInt(int64(i), 10) + ")" } - return _Type_name[_Type_index[i]:_Type_index[i+1]] + return _Type_name[_Type_index[idx]:_Type_index[idx+1]] } diff --git a/notifications/event/type_test.go b/notifications/event/type_test.go index d435725..8a26e92 100644 --- a/notifications/event/type_test.go +++ b/notifications/event/type_test.go @@ -18,7 +18,6 @@ func TestType(t *testing.T) { {Name: "State", Expected: `"state"`, Data: TypeState, Error: nil}, {Name: "Mute", Expected: `"mute"`, Data: TypeMute, Error: nil}, {Name: "Unmute", Expected: `"unmute"`, Data: TypeUnmute, Error: nil}, - {Name: "DowntimeStart", Expected: `"downtime-start"`, Data: TypeDowntimeStart, Error: nil}, } for _, tt := range testdata { @@ -37,7 +36,6 @@ func TestType(t *testing.T) { {Name: "State", Expected: TypeState, Data: `"state"`, Error: nil}, {Name: "Mute", Expected: TypeMute, Data: `"mute"`, Error: nil}, {Name: "Unmute", Expected: TypeUnmute, Data: `"unmute"`, Error: nil}, - {Name: "DowntimeStart", Expected: TypeDowntimeStart, Data: `"downtime-start"`, Error: nil}, {Name: "Invalid", Expected: TypeUnknown, Data: `"invalid"`, Error: testutils.ErrorContains(`unknown type "invalid"`)}, {Name: "Invalid Unknown", Expected: TypeUnknown, Data: `"unknown"`, Error: testutils.ErrorContains(`unknown type "unknown"`)}, } @@ -58,7 +56,6 @@ func TestType(t *testing.T) { {Name: "State", Expected: TypeState, Data: `state`, Error: nil}, {Name: "Mute", Expected: TypeMute, Data: `mute`, Error: nil}, {Name: "Unmute", Expected: TypeUnmute, Data: `unmute`, Error: nil}, - {Name: "DowntimeStart", Expected: TypeDowntimeStart, Data: `downtime-start`, Error: nil}, {Name: "Invalid", Expected: TypeUnknown, Data: `invalid`, Error: testutils.ErrorContains(`unknown type "invalid"`)}, } @@ -78,7 +75,6 @@ func TestType(t *testing.T) { {Name: "State", Expected: `state`, Data: TypeState, Error: nil}, {Name: "Mute", Expected: `mute`, Data: TypeMute, Error: nil}, {Name: "Unmute", Expected: `unmute`, Data: TypeUnmute, Error: nil}, - {Name: "DowntimeStart", Expected: `downtime-start`, Data: TypeDowntimeStart, Error: nil}, } for _, tt := range testdata { diff --git a/notifications/plugin/plugin.go b/notifications/plugin/plugin.go index a31a312..c24997c 100644 --- a/notifications/plugin/plugin.go +++ b/notifications/plugin/plugin.go @@ -324,11 +324,21 @@ func FormatSubject(req *NotificationRequest) string { switch req.Event.Type { case event.TypeState: return fmt.Sprintf("[#%d] %s %s is %s", req.Incident.Id, req.Event.Type, req.Object.Name, req.Incident.Severity) - case event.TypeAcknowledgementCleared, event.TypeDowntimeRemoved: + case event.TypeAcknowledgementCleared: if req.Incident != nil { return fmt.Sprintf("[#%d] %s from %s", req.Incident.Id, req.Event.Type, req.Object.Name) } return fmt.Sprintf("%s from %s", req.Event.Type, req.Object.Name) + case event.TypeMute: + if req.Incident != nil { + return fmt.Sprintf("[#%d] %s is muted", req.Incident.Id, req.Object.Name) + } + return fmt.Sprintf("%s is muted", req.Object.Name) + case event.TypeUnmute: + if req.Incident != nil { + return fmt.Sprintf("[#%d] %s is unmuted", req.Incident.Id, req.Object.Name) + } + return fmt.Sprintf("%s is unmuted", req.Object.Name) default: if req.Incident != nil { return fmt.Sprintf("[#%d] %s on %s", req.Incident.Id, req.Event.Type, req.Object.Name)