Make json keys and DB columns consistent

This commit is contained in:
Yonas Habteab 2022-06-23 14:22:30 +02:00
parent 8f31ac1438
commit fa6c23d634
6 changed files with 25 additions and 20 deletions

View file

@ -14,7 +14,7 @@ type StateHistory struct {
HardState uint8 `json:"hard_state"`
PreviousSoftState uint8 `json:"previous_soft_state"`
PreviousHardState uint8 `json:"previous_hard_state"`
Attempt uint8 `json:"attempt"`
CheckAttempt uint8 `json:"check_attempt"`
Output types.String `json:"output"`
LongOutput types.String `json:"long_output"`
MaxCheckAttempts uint32 `json:"max_check_attempts"`

View file

@ -9,14 +9,14 @@ type State struct {
EnvironmentMeta `json:",inline"`
AcknowledgementCommentId types.Binary `json:"acknowledgement_comment_id"`
LastCommentId types.Binary `json:"last_comment_id"`
Attempt uint8 `json:"check_attempt"`
CheckCommandline types.String `json:"commandline"`
CheckAttempt uint8 `json:"check_attempt"`
CheckCommandline types.String `json:"check_commandline"`
CheckSource types.String `json:"check_source"`
SchedulingSource types.String `json:"scheduling_source"`
ExecutionTime float64 `json:"execution_time"`
HardState uint8 `json:"hard_state"`
InDowntime types.Bool `json:"in_downtime"`
IsAcknowledged types.AcknowledgementState `json:"acknowledgement"`
IsAcknowledged types.AcknowledgementState `json:"is_acknowledged"`
IsFlapping types.Bool `json:"is_flapping"`
IsHandled types.Bool `json:"is_handled"`
IsProblem types.Bool `json:"is_problem"`
@ -35,5 +35,5 @@ type State struct {
Severity uint16 `json:"severity"`
SoftState uint8 `json:"state"`
StateType types.StateType `json:"state_type"`
Timeout float64 `json:"check_timeout"`
CheckTimeout float64 `json:"check_timeout"`
}

View file

@ -290,7 +290,7 @@ CREATE TABLE host_state (
hard_state tinyint unsigned NOT NULL,
previous_soft_state tinyint unsigned NOT NULL,
previous_hard_state tinyint unsigned NOT NULL,
attempt tinyint unsigned NOT NULL,
check_attempt tinyint unsigned NOT NULL,
severity smallint unsigned NOT NULL,
output longtext DEFAULT NULL,
@ -313,7 +313,7 @@ CREATE TABLE host_state (
execution_time int unsigned DEFAULT NULL,
latency int unsigned DEFAULT NULL,
timeout int unsigned DEFAULT NULL,
check_timeout int unsigned DEFAULT NULL,
check_source text DEFAULT NULL,
scheduling_source text DEFAULT NULL,
@ -456,7 +456,7 @@ CREATE TABLE service_state (
hard_state tinyint unsigned NOT NULL,
previous_soft_state tinyint unsigned NOT NULL,
previous_hard_state tinyint unsigned NOT NULL,
attempt tinyint unsigned NOT NULL,
check_attempt tinyint unsigned NOT NULL,
severity smallint unsigned NOT NULL,
output longtext DEFAULT NULL,
@ -480,7 +480,7 @@ CREATE TABLE service_state (
execution_time int unsigned DEFAULT NULL,
latency int unsigned DEFAULT NULL,
timeout int unsigned DEFAULT NULL,
check_timeout int unsigned DEFAULT NULL,
check_source text DEFAULT NULL,
scheduling_source text DEFAULT NULL,
@ -1141,7 +1141,7 @@ CREATE TABLE state_history (
hard_state tinyint unsigned NOT NULL,
previous_soft_state tinyint unsigned NOT NULL,
previous_hard_state tinyint unsigned NOT NULL,
attempt tinyint unsigned NOT NULL,
check_attempt tinyint unsigned NOT NULL,
output longtext DEFAULT NULL,
long_output longtext DEFAULT NULL,
max_check_attempts int unsigned NOT NULL,

View file

@ -164,10 +164,14 @@ ALTER TABLE notification_history
MODIFY `text` longtext NOT NULL;
ALTER TABLE host_state
ADD COLUMN previous_soft_state tinyint unsigned NOT NULL AFTER hard_state;
ADD COLUMN previous_soft_state tinyint unsigned NOT NULL AFTER hard_state,
CHANGE attempt check_attempt tinyint unsigned NOT NULL,
CHANGE timeout check_timeout int unsigned DEFAULT NULL;
ALTER TABLE service_state
ADD COLUMN previous_soft_state tinyint unsigned NOT NULL AFTER hard_state;
ADD COLUMN previous_soft_state tinyint unsigned NOT NULL AFTER hard_state,
CHANGE attempt check_attempt tinyint unsigned NOT NULL,
CHANGE timeout check_timeout int unsigned DEFAULT NULL;
ALTER TABLE checkcommand_argument
ADD COLUMN `separator` varchar(255) DEFAULT NULL AFTER set_if;
@ -191,7 +195,8 @@ ALTER TABLE flapping_history
ADD index idx_flapping_history_end_time (end_time) COMMENT 'Filter for history retention';
ALTER TABLE state_history
ADD index idx_state_history_event_time (event_time) COMMENT 'Filter for history retention';
ADD index idx_state_history_event_time (event_time) COMMENT 'Filter for history retention',
CHANGE attempt check_attempt tinyint unsigned NOT NULL;
ALTER TABLE icon_image
DROP PRIMARY KEY,

View file

@ -392,7 +392,7 @@ CREATE TABLE host_state (
hard_state tinyuint NOT NULL,
previous_soft_state tinyuint NOT NULL,
previous_hard_state tinyuint NOT NULL,
attempt tinyuint NOT NULL,
check_attempt tinyuint NOT NULL,
severity smalluint NOT NULL,
output text DEFAULT NULL,
@ -416,7 +416,7 @@ CREATE TABLE host_state (
execution_time uint DEFAULT NULL,
latency uint DEFAULT NULL,
timeout uint DEFAULT NULL,
check_timeout uint DEFAULT NULL,
check_source text DEFAULT NULL,
scheduling_source text DEFAULT NULL,
@ -658,7 +658,7 @@ CREATE TABLE service_state (
hard_state tinyuint NOT NULL,
previous_soft_state tinyuint NOT NULL,
previous_hard_state tinyuint NOT NULL,
attempt tinyuint NOT NULL,
check_attempt tinyuint NOT NULL,
severity smalluint NOT NULL,
output text DEFAULT NULL,
@ -682,7 +682,7 @@ CREATE TABLE service_state (
execution_time uint DEFAULT NULL,
latency uint DEFAULT NULL,
timeout uint DEFAULT NULL,
check_timeout uint DEFAULT NULL,
check_source text DEFAULT NULL,
scheduling_source text DEFAULT NULL,
@ -1823,7 +1823,7 @@ CREATE TABLE state_history (
hard_state tinyuint NOT NULL,
previous_soft_state tinyuint NOT NULL,
previous_hard_state tinyuint NOT NULL,
attempt tinyuint NOT NULL,
check_attempt tinyuint NOT NULL,
output text DEFAULT NULL,
long_output text DEFAULT NULL,
max_check_attempts uint NOT NULL,

View file

@ -342,14 +342,14 @@ func (c *CurrentState) WriteSlaEventToDatabase(db *sqlx.DB, m *SlaHistoryMeta) e
if len(m.ServiceId) == 0 {
_, err := db.NamedExec("INSERT INTO host_state"+
" (id, host_id, environment_id, properties_checksum, soft_state, previous_soft_state,"+
" hard_state, previous_hard_state, attempt, severity, last_state_change, next_check, next_update)"+
" hard_state, previous_hard_state, check_attempt, severity, last_state_change, next_check, next_update)"+
" VALUES (:host_id, :host_id, :environment_id, :properties_checksum, :state, :state, :state, :state, 0, 0, 0, 0, 0)",
&v)
return err
} else {
_, err := db.NamedExec("INSERT INTO service_state"+
" (id, host_id, service_id, environment_id, properties_checksum, soft_state, previous_soft_state,"+
" hard_state, previous_hard_state, attempt, severity, last_state_change, next_check, next_update)"+
" hard_state, previous_hard_state, check_attempt, severity, last_state_change, next_check, next_update)"+
" VALUES (:service_id, :host_id, :service_id, :environment_id, :properties_checksum, :state, :state, :state, :state, 0, 0, 0, 0, 0)",
&v)
return err