diff --git a/lib/icinga/checkable.cpp b/lib/icinga/checkable.cpp index a4c62500e..1fe6a3d97 100644 --- a/lib/icinga/checkable.cpp +++ b/lib/icinga/checkable.cpp @@ -139,6 +139,21 @@ int Checkable::GetSeverity() const return 0; } +bool Checkable::GetReachable() const +{ + return IsReachable(); +} + +bool Checkable::GetProblem() const +{ + return !IsStateOK(GetStateRaw()); +} + +bool Checkable::GetHandled() const +{ + return GetProblem() && (IsInDowntime() || IsAcknowledged()); +} + void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime) { if (!downtime->GetFixed()) diff --git a/lib/icinga/checkable.hpp b/lib/icinga/checkable.hpp index 29a5c6db0..44cfaad49 100644 --- a/lib/icinga/checkable.hpp +++ b/lib/icinga/checkable.hpp @@ -85,6 +85,9 @@ public: void ClearAcknowledgement(const MessageOrigin::Ptr& origin = nullptr); int GetSeverity() const override; + bool GetReachable() const override; + bool GetProblem() const override; + bool GetHandled() const override; /* Checks */ intrusive_ptr GetCheckCommand() const; @@ -96,7 +99,7 @@ public: void UpdateNextCheck(const MessageOrigin::Ptr& origin = nullptr); bool HasBeenChecked() const; - virtual bool IsStateOK(ServiceState state) = 0; + virtual bool IsStateOK(ServiceState state) const = 0; double GetLastCheck() const final; diff --git a/lib/icinga/checkable.ti b/lib/icinga/checkable.ti index 158c5ceae..286e4b8f6 100644 --- a/lib/icinga/checkable.ti +++ b/lib/icinga/checkable.ti @@ -123,6 +123,15 @@ abstract class Checkable : CustomVarObject [no_storage] int severity { get; }; + [no_storage] bool reachable { + get; + }; + [no_storage] bool problem { + get; + }; + [no_storage] bool handled { + get; + }; [state] bool force_next_check; [state] int acknowledgement (AcknowledgementRaw) { diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 4b95ffa9f..9744eed46 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -192,7 +192,7 @@ int Host::GetSeverity() const return severity; } -bool Host::IsStateOK(ServiceState state) +bool Host::IsStateOK(ServiceState state) const { return Host::CalculateState(state) == HostUp; } diff --git a/lib/icinga/host.hpp b/lib/icinga/host.hpp index a72a7874c..237d8aaa1 100644 --- a/lib/icinga/host.hpp +++ b/lib/icinga/host.hpp @@ -39,7 +39,7 @@ public: HostState GetLastHardState() const override; int GetSeverity() const override; - bool IsStateOK(ServiceState state) override; + bool IsStateOK(ServiceState state) const override; void SaveLastState(ServiceState state, double timestamp) override; static HostState StateFromString(const String& state); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 63fd70445..0b52298f5 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -133,7 +133,7 @@ int Service::GetSeverity() const return severity; } -bool Service::IsStateOK(ServiceState state) +bool Service::IsStateOK(ServiceState state) const { return state == ServiceOK; } diff --git a/lib/icinga/service.hpp b/lib/icinga/service.hpp index 8617eee3b..8453e8506 100644 --- a/lib/icinga/service.hpp +++ b/lib/icinga/service.hpp @@ -32,7 +32,7 @@ public: bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override; - bool IsStateOK(ServiceState state) override; + bool IsStateOK(ServiceState state) const override; void SaveLastState(ServiceState state, double timestamp) override; static ServiceState StateFromString(const String& state);