From 167076cc4b57e163368246d2ea9d333764d46a46 Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Tue, 13 Jan 2026 15:48:07 +0100 Subject: [PATCH] Align Icinga 2 Types with SQL Representation Certain Icinga 2 object fields of a floating type are incorrectly stored as unsigned integers in the schema. Since none of those columns are in the history tables, changing them was considered not too invasive. Furthermore, some struct fields were changed from "float64" to "types.Float", since the SQL schema supports NULL values. Fixes #882. --- pkg/icingadb/v1/checkable.go | 2 +- pkg/icingadb/v1/state.go | 6 +++--- schema/mysql/schema.sql | 24 +++++++++++------------ schema/mysql/upgrades/1.5.2-pr1063.sql | 19 ++++++++++++++++++ schema/pgsql/schema.sql | 24 +++++++++++------------ schema/pgsql/upgrades/1.5.2-pr1063.sql | 27 ++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 schema/mysql/upgrades/1.5.2-pr1063.sql create mode 100644 schema/pgsql/upgrades/1.5.2-pr1063.sql diff --git a/pkg/icingadb/v1/checkable.go b/pkg/icingadb/v1/checkable.go index 3dfa268f..0e47837d 100644 --- a/pkg/icingadb/v1/checkable.go +++ b/pkg/icingadb/v1/checkable.go @@ -16,7 +16,7 @@ type Checkable struct { CheckTimeperiodId types.Binary `json:"check_timeperiod_id"` CheckRetryInterval float64 `json:"check_retry_interval"` TotalChildren types.Int `json:"total_children"` - CheckTimeout float64 `json:"check_timeout"` + CheckTimeout types.Float `json:"check_timeout"` CheckcommandName string `json:"checkcommand_name"` CheckcommandId types.Binary `json:"checkcommand_id"` CommandEndpointName string `json:"command_endpoint_name"` diff --git a/pkg/icingadb/v1/state.go b/pkg/icingadb/v1/state.go index 83f7f52b..269033c9 100644 --- a/pkg/icingadb/v1/state.go +++ b/pkg/icingadb/v1/state.go @@ -13,7 +13,7 @@ type State struct { CheckCommandline types.String `json:"check_commandline"` CheckSource types.String `json:"check_source"` SchedulingSource types.String `json:"scheduling_source"` - ExecutionTime float64 `json:"execution_time"` + ExecutionTime types.Float `json:"execution_time"` HardState uint8 `json:"hard_state"` InDowntime types.Bool `json:"in_downtime"` AffectsChildren types.Bool `json:"affects_children"` @@ -25,7 +25,7 @@ type State struct { IsReachable types.Bool `json:"is_reachable"` LastStateChange types.UnixMilli `json:"last_state_change"` LastUpdate types.UnixMilli `json:"last_update"` - Latency float64 `json:"latency"` + Latency types.Float `json:"latency"` LongOutput types.String `json:"long_output"` NextCheck types.UnixMilli `json:"next_check"` NextUpdate types.UnixMilli `json:"next_update"` @@ -37,5 +37,5 @@ type State struct { Severity uint16 `json:"severity"` SoftState uint8 `json:"soft_state"` StateType string `json:"state_type"` - CheckTimeout float64 `json:"check_timeout"` + CheckTimeout types.Float `json:"check_timeout"` } diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index 650774d6..ce9339a2 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -184,9 +184,9 @@ CREATE TABLE host ( check_timeperiod_name varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'timeperiod.name', check_timeperiod_id binary(20) DEFAULT NULL COMMENT 'timeperiod.id', - check_timeout int unsigned DEFAULT NULL, - check_interval int unsigned NOT NULL, - check_retry_interval int unsigned NOT NULL, + check_timeout float DEFAULT NULL, + check_interval float NOT NULL, + check_retry_interval float NOT NULL, total_children int unsigned DEFAULT NULL, @@ -318,9 +318,9 @@ CREATE TABLE host_state ( affects_children enum('n', 'y') NOT NULL, - execution_time int unsigned DEFAULT NULL, - latency int unsigned DEFAULT NULL, - check_timeout int unsigned DEFAULT NULL, + execution_time float DEFAULT NULL, + latency float DEFAULT NULL, + check_timeout float DEFAULT NULL, check_source text DEFAULT NULL, scheduling_source text DEFAULT NULL, @@ -357,9 +357,9 @@ CREATE TABLE service ( check_timeperiod_name varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'timeperiod.name', check_timeperiod_id binary(20) DEFAULT NULL COMMENT 'timeperiod.id', - check_timeout int unsigned DEFAULT NULL, - check_interval int unsigned NOT NULL, - check_retry_interval int unsigned NOT NULL, + check_timeout float DEFAULT NULL, + check_interval float NOT NULL, + check_retry_interval float NOT NULL, total_children int unsigned DEFAULT NULL, @@ -492,9 +492,9 @@ CREATE TABLE service_state ( affects_children enum('n', 'y') NOT NULL, - execution_time int unsigned DEFAULT NULL, - latency int unsigned DEFAULT NULL, - check_timeout int unsigned DEFAULT NULL, + execution_time float DEFAULT NULL, + latency float DEFAULT NULL, + check_timeout float DEFAULT NULL, check_source text DEFAULT NULL, scheduling_source text DEFAULT NULL, diff --git a/schema/mysql/upgrades/1.5.2-pr1063.sql b/schema/mysql/upgrades/1.5.2-pr1063.sql new file mode 100644 index 00000000..50ecd96a --- /dev/null +++ b/schema/mysql/upgrades/1.5.2-pr1063.sql @@ -0,0 +1,19 @@ +ALTER TABLE host + MODIFY COLUMN check_timeout float DEFAULT NULL, + MODIFY COLUMN check_interval float NOT NULL, + MODIFY COLUMN check_retry_interval float NOT NULL; + +ALTER TABLE host_state + MODIFY COLUMN execution_time float DEFAULT NULL, + MODIFY COLUMN latency float DEFAULT NULL, + MODIFY COLUMN check_timeout float DEFAULT NULL; + +ALTER TABLE service + MODIFY COLUMN check_timeout float DEFAULT NULL, + MODIFY COLUMN check_interval float NOT NULL, + MODIFY COLUMN check_retry_interval float NOT NULL; + +ALTER TABLE service_state + MODIFY COLUMN execution_time float DEFAULT NULL, + MODIFY COLUMN latency float DEFAULT NULL, + MODIFY COLUMN check_timeout float DEFAULT NULL; diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index f6113469..57fa9f62 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -210,9 +210,9 @@ CREATE TABLE host ( check_timeperiod_name citext NOT NULL, check_timeperiod_id bytea20 DEFAULT NULL, - check_timeout uint DEFAULT NULL, - check_interval uint NOT NULL, - check_retry_interval uint NOT NULL, + check_timeout float DEFAULT NULL, + check_interval float NOT NULL, + check_retry_interval float NOT NULL, total_children uint DEFAULT NULL, @@ -431,9 +431,9 @@ CREATE TABLE host_state ( affects_children boolenum NOT NULL, - execution_time uint DEFAULT NULL, - latency uint DEFAULT NULL, - check_timeout uint DEFAULT NULL, + execution_time float DEFAULT NULL, + latency float DEFAULT NULL, + check_timeout float DEFAULT NULL, check_source text DEFAULT NULL, scheduling_source text DEFAULT NULL, @@ -489,9 +489,9 @@ CREATE TABLE service ( check_timeperiod_name citext NOT NULL, check_timeperiod_id bytea20 DEFAULT NULL, - check_timeout uint DEFAULT NULL, - check_interval uint NOT NULL, - check_retry_interval uint NOT NULL, + check_timeout float DEFAULT NULL, + check_interval float NOT NULL, + check_retry_interval float NOT NULL, total_children uint DEFAULT NULL, @@ -706,9 +706,9 @@ CREATE TABLE service_state ( affects_children boolenum NOT NULL, - execution_time uint DEFAULT NULL, - latency uint DEFAULT NULL, - check_timeout uint DEFAULT NULL, + execution_time float DEFAULT NULL, + latency float DEFAULT NULL, + check_timeout float DEFAULT NULL, check_source text DEFAULT NULL, scheduling_source text DEFAULT NULL, diff --git a/schema/pgsql/upgrades/1.5.2-pr1063.sql b/schema/pgsql/upgrades/1.5.2-pr1063.sql new file mode 100644 index 00000000..00f78b39 --- /dev/null +++ b/schema/pgsql/upgrades/1.5.2-pr1063.sql @@ -0,0 +1,27 @@ +ALTER TABLE host + ALTER COLUMN check_timeout TYPE float, + ALTER COLUMN check_timeout SET DEFAULT NULL, + ALTER COLUMN check_interval TYPE float, + ALTER COLUMN check_retry_interval TYPE float; + +ALTER TABLE host_state + ALTER COLUMN execution_time TYPE float, + ALTER COLUMN execution_time SET DEFAULT NULL, + ALTER COLUMN latency TYPE float, + ALTER COLUMN latency SET DEFAULT NULL, + ALTER COLUMN check_timeout TYPE float, + ALTER COLUMN check_timeout SET DEFAULT NULL; + +ALTER TABLE service + ALTER COLUMN check_timeout TYPE float, + ALTER COLUMN check_timeout SET DEFAULT NULL, + ALTER COLUMN check_interval TYPE float, + ALTER COLUMN check_retry_interval TYPE float; + +ALTER TABLE service_state + ALTER COLUMN execution_time TYPE float, + ALTER COLUMN execution_time SET DEFAULT NULL, + ALTER COLUMN latency TYPE float, + ALTER COLUMN latency SET DEFAULT NULL, + ALTER COLUMN check_timeout TYPE float, + ALTER COLUMN check_timeout SET DEFAULT NULL;