From 4b2934612ed859ee82c7a4c4afab96c6824b3dee Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 29 Oct 2019 16:54:28 +0100 Subject: [PATCH] Schema: add *_state#previous_hard_state --- configobject/objecttypes/host/hoststate/hoststate.go | 3 +++ configobject/objecttypes/service/servicestate/servicestate.go | 3 +++ configobject/statesync/statesync.go | 3 ++- etc/schema/mysql/host.sql | 1 + etc/schema/mysql/service.sql | 1 + 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/configobject/objecttypes/host/hoststate/hoststate.go b/configobject/objecttypes/host/hoststate/hoststate.go index 1ad90d18..742ab584 100644 --- a/configobject/objecttypes/host/hoststate/hoststate.go +++ b/configobject/objecttypes/host/hoststate/hoststate.go @@ -14,6 +14,7 @@ var ( "state_type", "soft_state", "hard_state", + "previous_hard_state", "attempt", "severity", "output", @@ -45,6 +46,7 @@ type HostState struct { StateType float32 `json:"state_type"` SoftState float32 `json:"state"` HardState float32 `json:"NONE"` //TODO (NoH): I'm not sure where to get this from + PreviousHardState uint8 `json:"previous_hard_state"` Attempt float32 `json:"check_attempt"` Severity float32 `json:"severity"` Output string `json:"output"` @@ -90,6 +92,7 @@ func (h *HostState) UpdateValues() []interface{} { utils.IcingaStateTypeToString(h.StateType), h.SoftState, h.HardState, + h.PreviousHardState, h.Attempt, h.Severity, h.Output, diff --git a/configobject/objecttypes/service/servicestate/servicestate.go b/configobject/objecttypes/service/servicestate/servicestate.go index fbee60bc..8b4a8a10 100644 --- a/configobject/objecttypes/service/servicestate/servicestate.go +++ b/configobject/objecttypes/service/servicestate/servicestate.go @@ -14,6 +14,7 @@ var ( "state_type", "soft_state", "hard_state", + "previous_hard_state", "attempt", "severity", "output", @@ -45,6 +46,7 @@ type ServiceState struct { StateType float32 `json:"state_type"` SoftState float32 `json:"state"` HardState float32 `json:"NONE"` //TODO (NoH): I'm not sure where to get this from + PreviousHardState uint8 `json:"previous_hard_state"` Attempt float32 `json:"check_attempt"` Severity float32 `json:"severity"` Output string `json:"output"` @@ -90,6 +92,7 @@ func (s *ServiceState) UpdateValues() []interface{} { utils.IcingaStateTypeToString(s.StateType), s.SoftState, s.HardState, + s.PreviousHardState, s.Attempt, s.Severity, s.Output, diff --git a/configobject/statesync/statesync.go b/configobject/statesync/statesync.go index db252cb2..3c32db57 100644 --- a/configobject/statesync/statesync.go +++ b/configobject/statesync/statesync.go @@ -101,7 +101,7 @@ func syncStates(super *supervisor.Supervisor, objectType string) { _, errExec := super.Dbw.SqlExecTx( tx, mysqlObservers[objectType], - `REPLACE INTO `+objectType+`_state (`+objectType+`_id, environment_id, state_type, soft_state, hard_state, attempt, severity, output, long_output, performance_data,`+ + `REPLACE INTO `+objectType+`_state (`+objectType+`_id, environment_id, state_type, soft_state, hard_state, previous_hard_state, attempt, severity, output, long_output, performance_data,`+ `check_commandline, is_problem, is_handled, is_reachable, is_flapping, is_acknowledged, acknowledgement_comment_id,`+ `in_downtime, execution_time, latency, timeout, last_update, last_state_change, last_soft_state,`+ `last_hard_state, next_check, next_update) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`, @@ -110,6 +110,7 @@ func syncStates(super *supervisor.Supervisor, objectType string) { redisStateTypeToDBStateType(values["state_type"]), values["state"], values["last_hard_state"], + values["previous_hard_state"], values["check_attempt"], redisIntToDBInt(values["severity"]), values["output"], diff --git a/etc/schema/mysql/host.sql b/etc/schema/mysql/host.sql index e536c3ee..75f423b1 100644 --- a/etc/schema/mysql/host.sql +++ b/etc/schema/mysql/host.sql @@ -114,6 +114,7 @@ CREATE TABLE host_state ( 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, severity smallint unsigned NOT NULL, diff --git a/etc/schema/mysql/service.sql b/etc/schema/mysql/service.sql index 02b41d4f..8226fdc1 100644 --- a/etc/schema/mysql/service.sql +++ b/etc/schema/mysql/service.sql @@ -107,6 +107,7 @@ CREATE TABLE service_state ( 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, severity smallint unsigned NOT NULL,