From 6c7a9eb6519914bc8a4f9382f33f7091331470eb Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 4 Nov 2019 11:02:07 +0100 Subject: [PATCH] IcingaDB#SendStatusUpdate(): add icinga:history:stream:state#previous_soft_state --- lib/icinga/checkable-check.cpp | 4 ++++ lib/icinga/checkable.ti | 3 +++ lib/icingadb/icingadb-objects.cpp | 13 +++++++------ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index 94940b29f..8443fdc7f 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -303,6 +303,10 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig SetLastHardStatesRaw(GetLastHardStatesRaw() / 100u + new_state * 100u); } + if (stateChange) { + SetLastSoftStatesRaw(GetLastSoftStatesRaw() / 100u + new_state * 100u); + } + if (!IsStateOK(new_state)) TriggerDowntimes(); diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti index 07a946258..72eb52781 100644 --- a/lib/icinga/checkable.ti +++ b/lib/icinga/checkable.ti @@ -108,6 +108,9 @@ abstract class Checkable : CustomVarObject [state, no_user_view, no_user_modify] "unsigned short" last_hard_states_raw { default {{{ return /* current */ 99 * 100 + /* previous */ 99; }}} }; + [state, no_user_view, no_user_modify] "unsigned short" last_soft_states_raw { + default {{{ return /* current */ 99 * 100 + /* previous */ 99; }}} + }; [state, enum] StateType last_state_type { default {{{ return StateTypeSoft; }}} }; diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index 0869aeb97..1716b6f21 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -1129,10 +1129,10 @@ void IcingaDB::SendConfigDelete(const ConfigObject::Ptr& object) }); } -static -unsigned short GetPreviousHardState(const Checkable::Ptr& checkable, const Service::Ptr& service) +static inline +unsigned short GetPreviousState(const Checkable::Ptr& checkable, const Service::Ptr& service, StateType type) { - auto phs (checkable->GetLastHardStatesRaw() % 100u); + auto phs ((type == StateTypeHard ? checkable->GetLastHardStatesRaw() : checkable->GetLastSoftStatesRaw()) % 100u); if (service) { return phs; @@ -1185,7 +1185,8 @@ void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResu // TODO: last_hard/soft_state should be "previous". "last_soft_state", Convert::ToString(cr ? cr->GetState() : 99), "last_hard_state", Convert::ToString(service ? service->GetLastHardState() : host->GetLastHardState()), - "previous_hard_state", Convert::ToString(GetPreviousHardState(checkable, service)), + "previous_soft_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeSoft)), + "previous_hard_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeHard)), "output", Utility::ValidateUTF8(std::move(output.first)), "long_output", Utility::ValidateUTF8(std::move(output.second)), "check_source", cr->GetCheckSource(), @@ -1239,7 +1240,7 @@ void IcingaDB::SendSentNotification( "notification_id", GetObjectIdentifier(notification), "type", Convert::ToString(type), "state", Convert::ToString(cr->GetState()), - "previous_hard_state", Convert::ToString(GetPreviousHardState(checkable, service)), + "previous_hard_state", Convert::ToString(GetPreviousState(checkable, service, StateTypeHard)), "author", Utility::ValidateUTF8(author), "text", Utility::ValidateUTF8(finalText), "users_notified", Convert::ToString(users), @@ -1574,7 +1575,7 @@ Dictionary::Ptr IcingaDB::SerializeState(const Checkable::Ptr& checkable) attrs->Set("severity", host->GetSeverity()); } - attrs->Set("previous_hard_state", GetPreviousHardState(checkable, service)); + attrs->Set("previous_hard_state", GetPreviousState(checkable, service, StateTypeHard)); attrs->Set("check_attempt", checkable->GetCheckAttempt()); attrs->Set("is_active", checkable->IsActive());