From 3c050fcc4628da2cef69a7fd0e077f7f3157da33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Fu=C3=9F?= Date: Mon, 21 Sep 2020 18:41:15 +0200 Subject: [PATCH] Drop passive check results for unreachable hosts/services Disregard passive check results while no active checks are being scheduled due to violated dependencies. This copes with the fact that programs feeding passive check results into Icinga may have no notion of reachability and so drive a checkable into HARD state although dependencies have caused active check scheduling being suspended. This may prevent superflous problem notifications being emitted during recovery. As disable_checks defaults to false, it was regarded OK (by @Al2Klimov) to make this behaviour (which resembles the active check case) unconditional and not conditionalize it on an additional attribute. In the description of disable_checks, note that a value of true both disables scheduling of active checks and drops passive check results. --- doc/09-object-types.md | 2 +- lib/icinga/apiactions.cpp | 4 ++++ lib/icinga/externalcommandprocessor.cpp | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/09-object-types.md b/doc/09-object-types.md index ebbf2e546..4a2b474e0 100644 --- a/doc/09-object-types.md +++ b/doc/09-object-types.md @@ -200,7 +200,7 @@ Configuration Attributes: parent\_service\_name | Object name | **Optional.** The parent service. If omitted, this dependency object is treated as host dependency. child\_host\_name | Object name | **Required.** The child host. child\_service\_name | Object name | **Optional.** The child service. If omitted, this dependency object is treated as host dependency. - disable\_checks | Boolean | **Optional.** Whether to disable checks when this dependency fails. Defaults to false. + disable\_checks | Boolean | **Optional.** Whether to disable checks (i.e., don't schedule active checks and drop passive results) when this dependency fails. Defaults to false. disable\_notifications | Boolean | **Optional.** Whether to disable notifications when this dependency fails. Defaults to true. ignore\_soft\_states | Boolean | **Optional.** Whether to ignore soft states for the reachability calculation. Defaults to true. period | Object name | **Optional.** Time period object during which this dependency is enabled. diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 8a7e8a9a8..f9d585a06 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "icinga/apiactions.hpp" +#include "icinga/checkable.hpp" #include "icinga/service.hpp" #include "icinga/servicegroup.hpp" #include "icinga/hostgroup.hpp" @@ -58,6 +59,9 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object, if (!checkable->GetEnablePassiveChecks()) return ApiActions::CreateResult(403, "Passive checks are disabled for object '" + checkable->GetName() + "'."); + if (!checkable->IsReachable(DependencyCheckExecution)) + return ApiActions::CreateResult(200, "Ignoring passive check result for unreachable object '" + checkable->GetName() + "'."); + Host::Ptr host; Service::Ptr service; tie(host, service) = GetHostService(checkable); diff --git a/lib/icinga/externalcommandprocessor.cpp b/lib/icinga/externalcommandprocessor.cpp index e974a0175..c51a9bf1f 100644 --- a/lib/icinga/externalcommandprocessor.cpp +++ b/lib/icinga/externalcommandprocessor.cpp @@ -1,6 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ #include "icinga/externalcommandprocessor.hpp" +#include "icinga/checkable.hpp" #include "icinga/host.hpp" #include "icinga/service.hpp" #include "icinga/user.hpp" @@ -283,6 +284,12 @@ void ExternalCommandProcessor::ProcessHostCheckResult(double time, const std::ve if (!host->GetEnablePassiveChecks()) BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for host '" + arguments[0] + "' which has passive checks disabled.")); + if (!host->IsReachable(DependencyCheckExecution)) { + Log(LogNotice, "ExternalCommandProcessor") + << "Ignoring passive check result for unreachable host '" << arguments[0] << "'"; + return; + } + int exitStatus = Convert::ToDouble(arguments[1]); CheckResult::Ptr result = new CheckResult(); std::pair co = PluginUtility::ParseCheckOutput(arguments[2]); @@ -324,6 +331,12 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std: if (!service->GetEnablePassiveChecks()) BOOST_THROW_EXCEPTION(std::invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled.")); + if (!service->IsReachable(DependencyCheckExecution)) { + Log(LogNotice, "ExternalCommandProcessor") + << "Ignoring passive check result for unreachable service '" << arguments[1] << "'"; + return; + } + int exitStatus = Convert::ToDouble(arguments[2]); CheckResult::Ptr result = new CheckResult(); String output = CompatUtility::UnEscapeString(arguments[3]);