diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:40:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:40:59 +0000 |
commit | bc4e624732bd51c0dd1e9529cf228e8c23127732 (patch) | |
tree | d95dab8960e9d02d3b95f8653074ad2e54ca207c /tests/internal/value/notification_states.go | |
parent | Initial commit. (diff) | |
download | icingadb-bc4e624732bd51c0dd1e9529cf228e8c23127732.tar.xz icingadb-bc4e624732bd51c0dd1e9529cf228e8c23127732.zip |
Adding upstream version 1.1.1.upstream/1.1.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/internal/value/notification_states.go')
-rw-r--r-- | tests/internal/value/notification_states.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/internal/value/notification_states.go b/tests/internal/value/notification_states.go new file mode 100644 index 0000000..3c5479e --- /dev/null +++ b/tests/internal/value/notification_states.go @@ -0,0 +1,37 @@ +package value + +import "fmt" + +type NotificationStates []string + +func (s NotificationStates) IcingaDbValue() interface{} { + v := uint(0) + + for _, s := range s { + if bit, ok := notificationStateMap[s]; ok { + v |= bit + } else { + panic(fmt.Errorf("unknown notification state %q", s)) + } + } + + return v +} + +func (s NotificationStates) Icinga2ConfigValue() string { + return ToIcinga2Config([]string(s)) +} + +func (s NotificationStates) Icinga2ApiValue() interface{} { + return ToIcinga2Api([]string(s)) +} + +// https://github.com/Icinga/icinga2/blob/a8f98cf72115d50152137bc924277b426f483a3f/lib/icinga/notification.hpp#L20-L32 +var notificationStateMap = map[string]uint{ + "OK": 1, + "Warning": 2, + "Critical": 4, + "Unknown": 8, + "Up": 16, + "Down": 32, +} |