From 31a224c5095bc7918b2ca84875c8e54415ab2550 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 31 Mar 2025 13:53:14 +0200 Subject: [PATCH] Checkable::GetSeverity(): always take reachability into account So far, Service::GetSeverity() only considered the state of its own host, i.e. the implicit service to its own host dependency, and treated it similar to acknowledgements and downtimes. In contrast, Host::GetSeverity() considered reachability and treated it like a state, i.e. for the severity calculation, the host was either up, down, or unreachable. This commit changes the following things: 1. Make the service severity also consider explicitly configured dependencies by using IsReachable(). 2. Prefer acknowledgements and downtimes over unreachability in the severity calculation so that if an already acknowledged or in-downtime services (i.e. already handled service) becomes unreachable, it shouln't become more severe. 3. To unify host and service severities a bit, hosts now use the same logic that treats reachability more like acknowledgements/downtimes instead of like a state (changing the other way around would the state from the check plugin would not affect the severity for unrachable services anymore). --- lib/icinga/host.cpp | 10 +++------- lib/icinga/service.cpp | 8 +++----- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index e50ba9b6f..22dd79b40 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -180,18 +180,14 @@ int Host::GetSeverity() const return 0; } - int severity = 0; - - if (IsReachable()) { - severity = 64; - } else { - severity = 32; - } + int severity = 32; // DOWN if (IsAcknowledged()) { severity += 512; } else if (IsInDowntime()) { severity += 256; + } else if (!IsReachable()) { + severity += 1024; } else { severity += 2048; } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 11d7c9633..c24647c82 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -133,14 +133,12 @@ int Service::GetSeverity() const severity = 256; } - Host::Ptr host = GetHost(); - ObjectLock hlock (host); - if (host->GetState() != HostUp) { - severity += 1024; - } else if (IsAcknowledged()) { + if (IsAcknowledged()) { severity += 512; } else if (IsInDowntime()) { severity += 256; + } else if (!IsReachable()) { + severity += 1024; } else { severity += 2048; }