Merge pull request #9154 from Icinga/bugfix/icingadb-reachabilitychangehandler-9143

Icinga DB: ensure is_reachable and severity don't miss updates
This commit is contained in:
Julian Brost 2022-02-03 14:53:51 +01:00 committed by GitHub
commit 1b0ad099f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 8 deletions

View File

@ -215,10 +215,6 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
ResetNotificationNumbers();
SaveLastState(ServiceOK, cr->GetExecutionEnd());
/* update reachability for child objects in OK state */
if (!children.empty())
OnReachabilityChanged(this, cr, children, origin);
} else {
/* OK -> NOT-OK change, first SOFT state. Reset attempt counter. */
if (IsStateOK(old_state)) {
@ -241,10 +237,6 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
if (!IsStateOK(cr->GetState())) {
SaveLastState(cr->GetState(), cr->GetExecutionEnd());
}
/* update reachability for child objects in NOT-OK state */
if (!children.empty())
OnReachabilityChanged(this, cr, children, origin);
}
if (recovery) {
@ -514,6 +506,10 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
SetSuppressedNotifications(suppressed_types_after);
}
}
/* update reachability for child objects */
if ((stateChange || hardChange) && !children.empty())
OnReachabilityChanged(this, cr, children, origin);
}
void Checkable::ExecuteRemoteCheck(const Dictionary::Ptr& resolvedMacros)

View File

@ -84,6 +84,10 @@ void IcingaDB::ConfigStaticInitialize()
AcknowledgementClearedHandler(checkable, removedBy, changeTime);
});
Checkable::OnReachabilityChanged.connect([](const Checkable::Ptr&, const CheckResult::Ptr&, std::set<Checkable::Ptr> children, const MessageOrigin::Ptr&) {
IcingaDB::ReachabilityChangeHandler(children);
});
/* triggered on create, update and delete objects */
ConfigObject::OnActiveChanged.connect([](const ConfigObject::Ptr& object, const Value&) {
IcingaDB::VersionChangedHandler(object);
@ -2599,6 +2603,15 @@ void IcingaDB::StateChangeHandler(const ConfigObject::Ptr& object, const CheckRe
}
}
void IcingaDB::ReachabilityChangeHandler(const std::set<Checkable::Ptr>& children)
{
for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType<IcingaDB>()) {
for (auto& checkable : children) {
rw->UpdateState(checkable, StateUpdate::Full);
}
}
}
void IcingaDB::VersionChangedHandler(const ConfigObject::Ptr& object)
{
Type::Ptr type = object->GetReflectionType();

View File

@ -136,6 +136,7 @@ private:
static String GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj);
static bool PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& attributes, Dictionary::Ptr& checkSums);
static void ReachabilityChangeHandler(const std::set<Checkable::Ptr>& children);
static void StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type);
static void VersionChangedHandler(const ConfigObject::Ptr& object);
static void DowntimeStartedHandler(const Downtime::Ptr& downtime);