summaryrefslogtreecommitdiffstats
path: root/tests/internal/value/notification_types.go
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 12:36:04 +0000
commitb09c6d56832eb1718c07d74abf3bc6ae3fe4e030 (patch)
treed2caec2610d4ea887803ec9e9c3cd77136c448ba /tests/internal/value/notification_types.go
parentInitial commit. (diff)
downloadicingadb-upstream.tar.xz
icingadb-upstream.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--tests/internal/value/notification_types.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/internal/value/notification_types.go b/tests/internal/value/notification_types.go
new file mode 100644
index 0000000..f368ed5
--- /dev/null
+++ b/tests/internal/value/notification_types.go
@@ -0,0 +1,40 @@
+package value
+
+import "fmt"
+
+type NotificationTypes []string
+
+func (t NotificationTypes) IcingaDbValue() interface{} {
+ v := uint(0)
+
+ for _, s := range t {
+ if bit, ok := notificationTypeMap[s]; ok {
+ v |= bit
+ } else {
+ panic(fmt.Errorf("unknown notification type %q", s))
+ }
+ }
+
+ return v
+}
+
+func (t NotificationTypes) Icinga2ConfigValue() string {
+ return ToIcinga2Config([]string(t))
+}
+
+func (t NotificationTypes) Icinga2ApiValue() interface{} {
+ return ToIcinga2Api([]string(t))
+}
+
+// https://github.com/Icinga/icinga2/blob/a8f98cf72115d50152137bc924277b426f483a3f/lib/icinga/notification.hpp#L34-L50
+var notificationTypeMap = map[string]uint{
+ "DowntimeStart": 1,
+ "DowntimeEnd": 2,
+ "DowntimeRemoved": 4,
+ "Custom": 8,
+ "Acknowledgement": 16,
+ "Problem": 32,
+ "Recovery": 64,
+ "FlappingStart": 128,
+ "FlappingEnd": 256,
+}