From 7467624d047e4d32b8239e088910de812925a5f8 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Thu, 31 Oct 2019 14:43:07 +0100 Subject: [PATCH] Notification History: Use enum for types --- configobject/history/history.go | 2 +- etc/schema/mysql/history.sql | 2 +- utils/convert.go | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/configobject/history/history.go b/configobject/history/history.go index cf8706f0..7b97d34c 100644 --- a/configobject/history/history.go +++ b/configobject/history/history.go @@ -70,7 +70,7 @@ func notificationHistoryWorker(super *supervisor.Supervisor) { utils.DecodeHexIfNotNil(values["host_id"]), utils.DecodeHexIfNotNil(values["service_id"]), utils.EncodeChecksum(values["notification_id"].(string)), - values["type"], + utils.NotificationTypesToDbEnumString[values["type"].(string)], values["event_time"], values["state"], values["previous_hard_state"], diff --git a/etc/schema/mysql/history.sql b/etc/schema/mysql/history.sql index 1775d554..5e4310af 100644 --- a/etc/schema/mysql/history.sql +++ b/etc/schema/mysql/history.sql @@ -10,7 +10,7 @@ CREATE TABLE notification_history ( service_id binary(20) NULL DEFAULT NULL COMMENT 'service.id', notification_id binary(20) NOT NULL COMMENT 'notification.id', - type smallint(3) unsigned NOT NULL, + type enum('downtime_start', 'downtime_end', 'downtime_removed', 'custom', 'acknowledgement', 'problem', 'recovery', 'flapping_start', 'flapping_end') NOT NULL, event_time bigint(20) unsigned NOT NULL, state tinyint(1) unsigned NOT NULL, previous_hard_state tinyint(1) unsigned NOT NULL, diff --git a/utils/convert.go b/utils/convert.go index bf96e7c5..59c82264 100644 --- a/utils/convert.go +++ b/utils/convert.go @@ -11,7 +11,7 @@ var ( true: "y", false: "n", } - NotificationStates = map[string]int{ + NotificationStatesToInt = map[string]int{ "OK": 1, "Warning": 2, "Critical": 4, @@ -19,7 +19,7 @@ var ( "Up": 16, "Down": 32, } - NotificationTypes = map[string]int{ + NotificationTypesToInt = map[string]int{ "DowntimeStart": 1, "DowntimeEnd": 2, "DowntimeRemoved": 4, @@ -30,6 +30,17 @@ var ( "FlappingStart": 128, "FlappingEnd": 256, } + NotificationTypesToDbEnumString = map[string]string{ + "1": "downtime_start", + "2": "downtime_end", + "4": "downtime_removed", + "8": "custom", + "16": "acknowledgement", + "32": "problem", + "64": "recovery", + "128": "flapping_start", + "256": "flapping_end", + } CommentEntryTypes = map[string]string{ "1": "comment", "2": "downtime", @@ -73,7 +84,7 @@ func DecodeChecksum(c []byte) string { func NotificationStatesToBitMask(states []string) int { mask := 0 for _, s := range states { - mask += NotificationStates[s] + mask += NotificationStatesToInt[s] } return mask } @@ -82,7 +93,7 @@ func NotificationStatesToBitMask(states []string) int { func NotificationTypesToBitMask(types []string) int { mask := 0 for _, t := range types { - mask += NotificationTypes[t] + mask += NotificationTypesToInt[t] } return mask }