]> granicus.if.org Git - icinga2/commitdiff
add LastState{OK,Warning,Critical,Unknown|Up,Down,Unreachable} time attributes
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 18 Jul 2013 16:16:39 +0000 (18:16 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 18 Jul 2013 16:16:39 +0000 (18:16 +0200)
lib/icinga/host.cpp
lib/icinga/host.h
lib/icinga/service-check.cpp
lib/icinga/service.cpp
lib/icinga/service.h

index e052962bfad3885397b5a03a96fbea92380c36a3..45ee6084776b0a205dc3398b7f0ab770f8d3eb0b 100644 (file)
@@ -566,6 +566,45 @@ HostState Host::GetLastHardState(void) const
        }
 }
 
+double Host::GetLastStateUp(void) const
+{
+       ASSERT(!OwnsLock());
+
+       Service::Ptr hc = GetHostCheckService();
+
+       if (!hc)
+               return 0;
+
+       if (hc->GetLastStateOK() > hc->GetLastStateWarning())
+               return hc->GetLastStateOK();
+       else
+               return hc->GetLastStateWarning();
+}
+
+double Host::GetLastStateDown(void) const
+{
+       ASSERT(!OwnsLock());
+
+       Service::Ptr hc = GetHostCheckService();
+
+       if (!hc)
+               return 0;
+
+       return hc->GetLastStateCritical();
+}
+
+double Host::GetLastStateUnreachable(void) const
+{
+       ASSERT(!OwnsLock());
+
+       Service::Ptr hc = GetHostCheckService();
+
+       if (!hc)
+               return 0;
+
+       return hc->GetLastStateUnreachable();
+}
+
 double Host::GetLastStateChange(void) const
 {
        Service::Ptr hc = GetHostCheckService();
index 85b6469a8c07bd5187049052eb51ab71d6dc5f74..176cfa6c91c435d72470887b2296e5c2a4b00372 100644 (file)
@@ -115,6 +115,9 @@ public:
        StateType GetLastStateType(void) const;
        double GetLastStateChange(void) const;
        double GetLastHardStateChange(void) const;
+       double GetLastStateUp(void) const;
+       double GetLastStateDown(void) const;
+       double GetLastStateUnreachable(void) const;
 
        static String StateToString(HostState state);
 
index c5ab8f22b126a66da7686cf278f79b4414634687..8677c8209644b4c746592b7145cd0ec31db169a7 100644 (file)
@@ -224,6 +224,76 @@ StateType Service::GetLastStateType(void) const
        return static_cast<StateType>(ivalue);
 }
 
+void Service::SetLastStateOK(double ts)
+{
+       m_LastStateOK = ts;
+       Touch("last_state_ok");
+}
+
+double Service::GetLastStateOK(void) const
+{
+       if (m_LastStateOK.IsEmpty())
+               return 0;
+
+       return m_LastStateOK;
+}
+
+void Service::SetLastStateWarning(double ts)
+{
+       m_LastStateWarning = ts;
+       Touch("last_state_warning");
+}
+
+double Service::GetLastStateWarning(void) const
+{
+       if (m_LastStateWarning.IsEmpty())
+               return 0;
+
+       return m_LastStateWarning;
+}
+
+void Service::SetLastStateCritical(double ts)
+{
+       m_LastStateCritical = ts;
+       Touch("last_state_critical");
+}
+
+double Service::GetLastStateCritical(void) const
+{
+       if (m_LastStateCritical.IsEmpty())
+               return 0;
+
+       return m_LastStateCritical;
+}
+
+void Service::SetLastStateUnknown(double ts)
+{
+       m_LastStateUnknown = ts;
+       Touch("last_state_unknown");
+}
+
+double Service::GetLastStateUnknown(void) const
+{
+       if (m_LastStateUnknown.IsEmpty())
+               return 0;
+
+       return m_LastStateUnknown;
+}
+
+void Service::SetLastStateUnreachable(double ts)
+{
+       m_LastStateUnreachable = ts;
+       Touch("last_state_unreachable");
+}
+
+double Service::GetLastStateUnreachable(void) const
+{
+       if (m_LastStateUnreachable.IsEmpty())
+               return 0;
+
+       return m_LastStateUnreachable;
+}
+
 void Service::SetLastReachable(bool reachable)
 {
        m_LastReachable = reachable;
@@ -400,6 +470,9 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
 
        bool reachable = IsReachable();
 
+       if (!reachable)
+               SetLastStateUnreachable(Utility::GetTime());
+
        Host::Ptr host = GetHost();
        bool host_reachable = true;
 
@@ -430,6 +503,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
                attempt = 1;
                recovery = true;
                ResetNotificationNumbers();
+               SetLastStateOK(Utility::GetTime());
        } else {
                if (old_attempt >= GetMaxCheckAttempts()) {
                        SetStateType(StateTypeHard);
@@ -442,6 +516,13 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr)
                }
 
                recovery = false;
+
+               if (cr->Get("state") == StateWarning)
+                       SetLastStateWarning(Utility::GetTime());
+               if (cr->Get("state") == StateCritical)
+                       SetLastStateCritical(Utility::GetTime());
+               if (cr->Get("state") == StateUnknown)
+                       SetLastStateUnknown(Utility::GetTime());
        }
 
        SetCurrentCheckAttempt(attempt);
index 495e52d8970558473d20f71f256ff03348e42280..57321b3aa3659bfa90c0b25b33e425f3fa2358a0 100644 (file)
@@ -70,6 +70,11 @@ Service::Service(const Dictionary::Ptr& serializedObject)
        RegisterAttribute("last_result", Attribute_Replicated, &m_LastResult);
        RegisterAttribute("last_state_change", Attribute_Replicated, &m_LastStateChange);
        RegisterAttribute("last_hard_state_change", Attribute_Replicated, &m_LastHardStateChange);
+       RegisterAttribute("last_state_ok", Attribute_Replicated, &m_LastStateOK);
+       RegisterAttribute("last_state_warning", Attribute_Replicated, &m_LastStateWarning);
+       RegisterAttribute("last_state_critical", Attribute_Replicated, &m_LastStateCritical);
+       RegisterAttribute("last_state_unknown", Attribute_Replicated, &m_LastStateUnknown);
+       RegisterAttribute("last_state_unreachable", Attribute_Replicated, &m_LastStateUnreachable);
        RegisterAttribute("last_in_downtime", Attribute_Replicated, &m_LastInDowntime);
        RegisterAttribute("enable_active_checks", Attribute_Replicated, &m_EnableActiveChecks);
        RegisterAttribute("enable_passive_checks", Attribute_Replicated, &m_EnablePassiveChecks);
index 3d7911a7d7eb185e920c39668b944ac3ac2b6141..34832eb3fa68d496f17d936deaa1a351375d3167 100644 (file)
@@ -184,6 +184,17 @@ public:
        void SetLastHardStateChange(double ts);
        double GetLastHardStateChange(void) const;
 
+       void SetLastStateOK(double ts);
+       double GetLastStateOK(void) const;
+       void SetLastStateWarning(double ts);
+       double GetLastStateWarning(void) const;
+       void SetLastStateCritical(double ts);
+       double GetLastStateCritical(void) const;
+       void SetLastStateUnknown(double ts);
+       double GetLastStateUnknown(void) const;
+       void SetLastStateUnreachable(double ts);
+       double GetLastStateUnreachable(void) const;
+
        void SetLastReachable(bool reachable);
        bool GetLastReachable(void) const;
 
@@ -340,6 +351,11 @@ private:
        Attribute<Dictionary::Ptr> m_LastResult;
        Attribute<double> m_LastStateChange;
        Attribute<double> m_LastHardStateChange;
+       Attribute<double> m_LastStateOK;
+       Attribute<double> m_LastStateWarning;
+       Attribute<double> m_LastStateCritical;
+       Attribute<double> m_LastStateUnknown;
+       Attribute<double> m_LastStateUnreachable;
        Attribute<bool> m_LastInDowntime;
        Attribute<bool> m_EnableActiveChecks;
        Attribute<bool> m_EnablePassiveChecks;