-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifications.go
More file actions
77 lines (72 loc) · 1.49 KB
/
Notifications.go
File metadata and controls
77 lines (72 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package icingadsl
import (
"errors"
"strings"
)
type NotificationType uint
const (
DowntimeStart NotificationType = iota
DowntimeEnd
DowntimeRemoved
Custom
Acknowledgement
Problem
Recovery
FlappingStart
FlappingEnd
)
/*
* Parse a notification type string (typically received when Icinga 2 is executing a notification plugin)
* into a fitting enum to simplify the following logic.
*/
func ParseNotificationType(nt string) (NotificationType, error) {
switch strings.ToLower(nt) {
case "downtimestart":
return DowntimeStart, nil
case "downtimeend":
return DowntimeEnd, nil
case "downtimeremoved":
return DowntimeRemoved, nil
case "custom":
return Custom, nil
case "acknowledgement":
return Acknowledgement, nil
case "problem":
return Problem, nil
case "recovery":
return Recovery, nil
case "flappingstart":
return FlappingStart, nil
case "flappingend":
return FlappingEnd, nil
default:
return 0, errors.New("no matching state for the provided string")
}
}
/*
* Transforms a notification type into a string
*/
func (nt NotificationType) String() string {
switch nt {
case DowntimeStart:
return "downtimestart"
case DowntimeEnd:
return "downtimeend"
case DowntimeRemoved:
return "downtimeremoved"
case Custom:
return "custom"
case Acknowledgement:
return "acknowledgement"
case Problem:
return "problem"
case Recovery:
return "recovery"
case FlappingStart:
return "flappingstart"
case FlappingEnd:
return "flappingend"
default:
return ""
}
}