From da35fb736305de481c3369140962963957dfb7a1 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 23 Oct 2019 15:43:27 +0200 Subject: [PATCH] Schema: add {notification,state}_history#previous_hard_state --- configobject/history/history.go | 10 ++++++---- configobject/nullrows/nullrows.go | 8 ++++---- etc/schema/mysql/history.sql | 2 ++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/configobject/history/history.go b/configobject/history/history.go index 99a92d0c..b1dd40d5 100644 --- a/configobject/history/history.go +++ b/configobject/history/history.go @@ -52,8 +52,8 @@ func StartHistoryWorkers(super *supervisor.Supervisor) { func notificationHistoryWorker(super *supervisor.Supervisor) { statements := []string{ `REPLACE INTO notification_history (id, environment_id, endpoint_id, object_type, host_id, service_id, notification_id, type,` + - `send_time, state, output, long_output, users_notified)` + - `VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`, + `send_time, state, previous_hard_state, output, long_output, users_notified)` + + `VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, `REPLACE INTO history (id, environment_id, endpoint_id, object_type, host_id, service_id, notification_history_id,` + `state_history_id, downtime_history_id, comment_history_id, flapping_history_id, event_type, event_time)` + `VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`, @@ -73,6 +73,7 @@ func notificationHistoryWorker(super *supervisor.Supervisor) { values["type"], values["send_time"], values["state"], + values["previous_hard_state"], values["output"], values["long_output"], values["users_notified"], @@ -109,8 +110,8 @@ func notificationHistoryWorker(super *supervisor.Supervisor) { func stateHistoryWorker(super *supervisor.Supervisor) { statements := []string{ `REPLACE INTO state_history (id, environment_id, endpoint_id, object_type, host_id, service_id, change_time, state_type,` + - `soft_state, hard_state, attempt, last_soft_state, last_hard_state, output, long_output, max_check_attempts)` + - `VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, + `soft_state, hard_state, previous_hard_state, attempt, last_soft_state, last_hard_state, output, long_output, max_check_attempts)` + + `VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, `REPLACE INTO history (id, environment_id, endpoint_id, object_type, host_id, service_id, notification_history_id,` + `state_history_id, downtime_history_id, comment_history_id, flapping_history_id, event_type, event_time)` + `VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)`, @@ -136,6 +137,7 @@ func stateHistoryWorker(super *supervisor.Supervisor) { utils.IcingaStateTypeToString(float32(stateType)), values["soft_state"], values["hard_state"], + values["previous_hard_state"], values["attempt"], values["last_soft_state"], values["last_hard_state"], diff --git a/configobject/nullrows/nullrows.go b/configobject/nullrows/nullrows.go index aeb577aa..fd3352dc 100644 --- a/configobject/nullrows/nullrows.go +++ b/configobject/nullrows/nullrows.go @@ -64,15 +64,15 @@ func InsertNullRows(super *supervisor.Supervisor) { // notification_history execFunc( "notification_history", - "REPLACE INTO notification_history(id, environment_id, object_type, host_id, service_id, notification_id, type, send_time, state, output, long_output, users_notified) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", - emptyUUID[:], super.EnvId, "host", nil, nil, emptyID, 0, 0, 0, "", "", 0, + "REPLACE INTO notification_history(id, environment_id, object_type, host_id, service_id, notification_id, type, send_time, state, previous_hard_state, output, long_output, users_notified) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", + emptyUUID[:], super.EnvId, "host", nil, nil, emptyID, 0, 0, 0, 0, "", "", 0, ) // state_history execFunc( "state_history", - "REPLACE INTO state_history(id, environment_id, object_type, host_id, service_id, change_time, state_type, soft_state, hard_state, attempt, last_soft_state, last_hard_state, output, long_output, max_check_attempts) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", - emptyUUID[:], super.EnvId, "host", nil, nil, 0, "hard", 0, 0, 0, 0, 0, "", "", 0, + "REPLACE INTO state_history(id, environment_id, object_type, host_id, service_id, change_time, state_type, soft_state, hard_state, previous_hard_state, attempt, last_soft_state, last_hard_state, output, long_output, max_check_attempts) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", + emptyUUID[:], super.EnvId, "host", nil, nil, 0, "hard", 0, 0, 0, 0, 0, 0, "", "", 0, ) log.Info("Inserted \"NULL\" rows") diff --git a/etc/schema/mysql/history.sql b/etc/schema/mysql/history.sql index 51065bb5..efa9ff10 100644 --- a/etc/schema/mysql/history.sql +++ b/etc/schema/mysql/history.sql @@ -13,6 +13,7 @@ CREATE TABLE notification_history ( type smallint(3) unsigned NOT NULL, send_time bigint(20) unsigned NOT NULL, state tinyint(1) unsigned NOT NULL, + previous_hard_state tinyint(1) unsigned NOT NULL, output text DEFAULT NULL, long_output text DEFAULT NULL, users_notified smallint(5) unsigned NOT NULL, @@ -32,6 +33,7 @@ CREATE TABLE state_history ( state_type enum('hard', 'soft') NOT NULL, soft_state tinyint(1) unsigned NOT NULL, hard_state tinyint(1) unsigned NOT NULL, + previous_hard_state tinyint(1) unsigned NOT NULL, attempt tinyint(1) unsigned NOT NULL, last_soft_state tinyint(1) unsigned NOT NULL, last_hard_state tinyint(1) unsigned NOT NULL,