Skip to content

Commit 2bce7c2

Browse files
committed
Implement functionality for Downtime and Flapping notifications
- For now these will simply add an article to an existing ticket
1 parent 786e285 commit 2bce7c2

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Acknowledgement notifications will add an article to an existing ticket.
1010
This will also set the ticket state to `open`.
1111
If no ticket exists nothing will happen.
1212

13+
Downtime/Flapping notifications will add an article to an existing ticket.
14+
If no ticket exists nothing will happen.
15+
1316
Recovery notifications will close an existing ticket.
1417
This will set the ticket state to `closed`.
1518
If no ticket exists nothing will happen.

cmd/root.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func sendNotification(_ *cobra.Command, _ []string) {
141141
switch notificationType {
142142
case icingadsl.Custom:
143143
// If ticket exists, adds article to existing ticket
144-
notificationErr = handleCustomNotification(ctx, c, ticket)
144+
notificationErr = handleCustomNotification(ctx, c, ticket, "Custom")
145145
case icingadsl.Acknowledgement:
146146
// If ticket exists, adds article to existing ticket
147147
notificationErr = handleAcknowledgeNotification(ctx, c, ticket)
@@ -155,15 +155,20 @@ func sendNotification(_ *cobra.Command, _ []string) {
155155
// If ticket is closed, reopens the ticket with the article
156156
notificationErr = handleRecoveryNotification(ctx, c, ticket)
157157
case icingadsl.DowntimeStart:
158-
// Currently no implemented
158+
// If ticket exists, adds article to existing ticket
159+
notificationErr = handleCustomNotification(ctx, c, ticket, "DowntimeStart")
159160
case icingadsl.DowntimeEnd:
160-
// Currently no implemented
161+
// If ticket exists, adds article to existing ticket
162+
notificationErr = handleCustomNotification(ctx, c, ticket, "DowntimeEnd")
161163
case icingadsl.DowntimeRemoved:
162-
// Currently no implemented
164+
// If ticket exists, adds article to existing ticket
165+
notificationErr = handleCustomNotification(ctx, c, ticket, "DowntimeRemoved")
163166
case icingadsl.FlappingStart:
164-
// Currently no implemented
167+
// If ticket exists, adds article to existing ticket
168+
notificationErr = handleCustomNotification(ctx, c, ticket, "FlappingStart")
165169
case icingadsl.FlappingEnd:
166-
// Currently no implemented
170+
// If ticket exists, adds article to existing ticket
171+
notificationErr = handleCustomNotification(ctx, c, ticket, "FlappingEnd")
167172
default:
168173
check.ExitError(fmt.Errorf("unsupported notification type. Currently supported: Problem/Recovery/Acknowledgement"))
169174
}
@@ -284,15 +289,15 @@ func handleRecoveryNotification(ctx context.Context, c *client.Client, ticket za
284289

285290
// handleCustomNotification adds an article to an existing ticket
286291
// If no ticket exists nothing happens and the function returns
287-
func handleCustomNotification(ctx context.Context, c *client.Client, ticket zammad.Ticket) error {
292+
func handleCustomNotification(ctx context.Context, c *client.Client, ticket zammad.Ticket, notificationType string) error {
288293
if ticket.ID == 0 {
289294
return nil
290295
}
291296

292297
a := zammad.Article{
293298
TicketID: ticket.ID,
294-
Subject: "Custom",
295-
Body: fmt.Sprintf("Custom for: %s %s", cliConfig.IcingaCheckState, cliConfig.IcingaCheckOutput),
299+
Subject: notificationType,
300+
Body: fmt.Sprintf("%s for: %s %s", notificationType, cliConfig.IcingaCheckState, cliConfig.IcingaCheckOutput),
296301
ContentType: "text/html",
297302
Type: "web",
298303
Internal: true,

0 commit comments

Comments
 (0)