From 13632021e4f9f738531598e54334b7a20d0c8d4b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 20 May 2025 17:29:21 +0200 Subject: [PATCH] Don't unconditionally migrate icinga_statehistory.last_hard_state (IDO) -> state_history.hard_state For hard state change: icinga_statehistory.state is the current (hard) state (icinga_statehistory.last_hard_state is the previous one) For soft state change: icinga_statehistory.last_hard_state is the current hard state --- cmd/icingadb-migrate/convert.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/icingadb-migrate/convert.go b/cmd/icingadb-migrate/convert.go index faa16713..a594fa51 100644 --- a/cmd/icingadb-migrate/convert.go +++ b/cmd/icingadb-migrate/convert.go @@ -790,6 +790,11 @@ func convertStateRows( hostId := calcObjectId(env, row.Name1) serviceId := calcServiceId(env, row.Name1, row.Name2) + hardState := row.LastHardState // in case of soft state, the "current" hard state is the last one + if icingadbTypes.StateType(row.StateType) == icingadbTypes.StateHard { + hardState = row.State + } + stateHistory = append(stateHistory, &history.StateHistory{ HistoryTableEntity: history.HistoryTableEntity{ EntityWithoutChecksum: v1.EntityWithoutChecksum{ @@ -805,7 +810,7 @@ func convertStateRows( EventTime: ts, StateType: icingadbTypes.StateType(row.StateType), SoftState: row.State, - HardState: row.LastHardState, + HardState: hardState, PreviousSoftState: row.LastState, PreviousHardState: previousHardState, CheckAttempt: row.CurrentCheckAttempt, @@ -845,7 +850,7 @@ func convertStateRows( }, EventTime: ts, StateType: icingadbTypes.StateType(row.StateType), - HardState: row.LastHardState, + HardState: hardState, PreviousHardState: previousHardState, }) }