]> granicus.if.org Git - icinga2/commitdiff
Add host.last_state_{up,down} and last_check attribute, hide *_raw attributes
authorMichael Friedrich <michael.friedrich@netways.de>
Mon, 2 Nov 2015 13:10:44 +0000 (14:10 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Mon, 2 Nov 2015 13:10:44 +0000 (14:10 +0100)
fixes #10508
fixes #10509

doc/6-object-types.md
lib/compat/statusdatawriter.cpp
lib/icinga/checkable-check.cpp
lib/icinga/checkable.hpp
lib/icinga/checkable.ti
lib/icinga/host.cpp
lib/icinga/host.hpp
lib/icinga/host.ti
lib/icinga/service.cpp
lib/icinga/service.hpp
lib/icinga/service.ti

index 46a7335bd49b9873a266dc2b6e8052b4c8bbc91b..03732b0193a9d895b152a3f41dfca2aafac9ffde 100644 (file)
@@ -591,6 +591,7 @@ Runtime Attributes:
   Name                      | Type          | Description
   --------------------------|---------------|-----------------
   next\_check               | Number        | When the next check occurs (as a UNIX timestamp).
+  last\_check               | Number        | When the last check occured (as a UNIX timestamp).
   check\_attempt            | Number        | The current check attempt number.
   state\_type               | Number        | The current state type (0 = SOFT, 1 = HARD).
   last\_state\_type         | Number        | The previous state type (0 = SOFT, 1 = HARD).
@@ -606,6 +607,8 @@ Runtime Attributes:
   state                     | Number        | The current state (0 = UP, 1 = DOWN).
   last\_state               | Number        | The previous state (0 = UP, 1 = DOWN).
   last\_hard\_state         | Number        | The last hard state (0 = UP, 1 = DOWN).
+  last_state_up             | Number        | When the last UP state occurred (as a UNIX timestamp).
+  last_state_down           | Number        | When the last DOWN state occurred (as a UNIX timestamp).
 
 
 
@@ -1206,6 +1209,7 @@ Runtime Attributes:
   Name                      | Type          | Description
   --------------------------|---------------|-----------------
   next\_check               | Number        | When the next check occurs (as a UNIX timestamp).
+  last\_check               | Number        | When the last check occured (as a UNIX timestamp).
   check\_attempt            | Number        | The current check attempt number.
   state\_type               | Number        | The current state type (0 = SOFT, 1 = HARD).
   last\_state\_type         | Number        | The previous state type (0 = SOFT, 1 = HARD).
@@ -1221,6 +1225,10 @@ Runtime Attributes:
   state                     | Number        | The current state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
   last\_state               | Number        | The previous state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
   last\_hard\_state         | Number        | The last hard state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN).
+  last_state_ok             | Number        | When the last OK state occurred (as a UNIX timestamp).
+  last_state_warning        | Number        | When the last WARNING state occurred (as a UNIX timestamp).
+  last_state_critical       | Number        | When the last CRITICAL state occurred (as a UNIX timestamp).
+  last_state_unknown        | Number        | When the last UNKNOWN state occurred (as a UNIX timestamp).
 
 
 ## <a id="objecttype-servicegroup"></a> ServiceGroup
index d37c61355ac92abf7d50871536cdd410983d231d..21ff13b9e89bff74c67c5bf3ac14e56ee7b05e08 100644 (file)
@@ -344,11 +344,17 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
        tie(host, service) = GetHostService(checkable);
 
        if (service) {
-               fp << "\t" << "current_state=" << service->GetState() << "\n"
-                  << "\t" << "last_hard_state=" << service->GetLastHardState() << "\n";
+               fp << "\t" "current_state=" << service->GetState() << "\n"
+                     "\t" "last_hard_state=" << service->GetLastHardState() << "\n"
+                     "\t" "last_time_ok=" << static_cast<int>(service->GetLastStateOK()) << "\n"
+                     "\t" "last_time_warn=" << static_cast<int>(service->GetLastStateWarning()) << "\n"
+                     "\t" "last_time_critical=" << static_cast<int>(service->GetLastStateCritical()) << "\n"
+                     "\t" "last_time_unknown=" << static_cast<int>(service->GetLastStateUnknown()) << "\n";
        } else {
-               fp << "\t" << "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
-                  << "\t" << "last_hard_state=" << host->GetLastHardState() << "\n";
+               fp << "\t" "current_state=" << CompatUtility::GetHostCurrentState(host) << "\n"
+                     "\t" "last_hard_state=" << host->GetLastHardState() << "\n"
+                     "\t" "last_time_up=" << static_cast<int>(host->GetLastStateUp()) << "\n"
+                     "\t" "last_time_down=" << static_cast<int>(host->GetLastStateDown()) << "\n";
        }
 
        fp << "\t" "state_type=" << checkable->GetStateType() << "\n"
@@ -366,10 +372,6 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
              "\t" "max_attempts=" << checkable->GetMaxCheckAttempts() << "\n"
              "\t" "last_state_change=" << static_cast<long>(checkable->GetLastStateChange()) << "\n"
              "\t" "last_hard_state_change=" << static_cast<long>(checkable->GetLastHardStateChange()) << "\n"
-             "\t" "last_time_ok=" << static_cast<int>(checkable->GetLastStateOK()) << "\n"
-             "\t" "last_time_warn=" << static_cast<int>(checkable->GetLastStateWarning()) << "\n"
-             "\t" "last_time_critical=" << static_cast<int>(checkable->GetLastStateCritical()) << "\n"
-             "\t" "last_time_unknown=" << static_cast<int>(checkable->GetLastStateUnknown()) << "\n"
              "\t" "last_update=" << static_cast<long>(time(NULL)) << "\n"
              "\t" "notifications_enabled=" << CompatUtility::GetCheckableNotificationsEnabled(checkable) << "\n"
              "\t" "active_checks_enabled=" << CompatUtility::GetCheckableActiveChecksEnabled(checkable) << "\n"
index da1bbd7ec0dade889796f8bc5e50cb7c6b1967d2..17c213191ad22f7cc39ee220ef33eb768435ccd4 100644 (file)
@@ -185,7 +185,7 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
                        recovery = true; // NOT OK -> SOFT/HARD OK
 
                ResetNotificationNumbers();
-               SetLastStateOK(Utility::GetTime());
+               SaveLastState(ServiceOK, Utility::GetTime());
 
                /* update reachability for child objects in OK state */
                if (!children.empty())
@@ -203,19 +203,8 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig
                        attempt = old_attempt;
                }
 
-               switch (cr->GetState()) {
-                       case ServiceOK:
-                               /* Nothing to do here. */
-                               break;
-                       case ServiceWarning:
-                               SetLastStateWarning(Utility::GetTime());
-                               break;
-                       case ServiceCritical:
-                               SetLastStateCritical(Utility::GetTime());
-                               break;
-                       case ServiceUnknown:
-                               SetLastStateUnknown(Utility::GetTime());
-                               break;
+               if (cr->GetState() != ServiceOK) {
+                       SaveLastState(cr->GetState(), Utility::GetTime());
                }
 
                /* update reachability for child objects in NOT-OK state */
index 58e90a9cbbe501aad8d2481dc8164c8b5444dae7..cced848d77004bb9bb632a73b6f72bd76b445b92 100644 (file)
@@ -92,8 +92,9 @@ public:
        void UpdateNextCheck(void);
 
        bool HasBeenChecked(void) const;
+       virtual double GetLastCheck(void) const override;
 
-       double GetLastCheck(void) const;
+       virtual void SaveLastState(ServiceState state, double timestamp) = 0;
 
        static void UpdateStatistics(const CheckResult::Ptr& cr, CheckableType type);
 
index 433de6509fe891da2b39477e229bc6041e5241de..51ef774250bcc4877951db7a813cf1505f751ba6 100644 (file)
@@ -101,16 +101,16 @@ abstract class Checkable : CustomVarObject
        [state] int check_attempt {
                default {{{ return 1; }}}
        };
-       [state, enum] ServiceState state_raw {
+       [state, enum, no_user_view, no_user_modify] ServiceState state_raw {
                default {{{ return ServiceUnknown; }}}
        };
        [state, enum] StateType state_type {
                default {{{ return StateTypeSoft; }}}
        };
-       [state, enum] ServiceState last_state_raw {
+       [state, enum, no_user_view, no_user_modify] ServiceState last_state_raw {
                default {{{ return ServiceUnknown; }}}
        };
-       [state, enum] ServiceState last_hard_state_raw {
+       [state, enum, no_user_view, no_user_modify] ServiceState last_hard_state_raw {
                default {{{ return ServiceUnknown; }}}
        };
        [state, enum] StateType last_state_type {
@@ -126,10 +126,6 @@ abstract class Checkable : CustomVarObject
        [state] double last_hard_state_change {
                default {{{ return Application::GetStartTime(); }}}
        };
-       [state] double last_state_ok (LastStateOK);
-       [state] double last_state_warning;
-       [state] double last_state_critical;
-       [state] double last_state_unknown;
        [state] double last_state_unreachable;
        [state] bool last_in_downtime;
        [state] bool force_next_check;
@@ -144,6 +140,9 @@ abstract class Checkable : CustomVarObject
        [no_storage, protected] bool flapping {
                get {{{ return false; }}}
        };
+       [no_storage] double last_check {
+               get;
+       };
 
        [config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
                navigate {{{
index 7cecf285a2a5e107569f156a413f3f86656d4c80..1f3f9a4ee69379a52bd73a02c6f37cbb612512e6 100644 (file)
@@ -173,17 +173,12 @@ HostState Host::GetLastHardState(void) const
        return CalculateState(GetLastHardStateRaw());
 }
 
-double Host::GetLastStateUp(void) const
+void Host::SaveLastState(ServiceState state, double timestamp)
 {
-       if (GetLastStateOK() > GetLastStateWarning())
-               return GetLastStateOK();
-       else
-               return GetLastStateWarning();
-}
-
-double Host::GetLastStateDown(void) const
-{
-       return GetLastStateCritical();
+       if (state == ServiceOK || state == ServiceWarning)
+               SetLastStateUp(timestamp);
+       else if (state == ServiceCritical)
+               SetLastStateDown(timestamp);
 }
 
 HostState Host::StateFromString(const String& state)
index 8afa9dae5a6b33c481f6c58363e813b11266c13f..3c25c8a47c12d9b63249c99db0c5f3fff71e3330 100644 (file)
@@ -54,8 +54,8 @@ public:
        virtual HostState GetState(void) const override;
        virtual HostState GetLastState(void) const override;
        virtual HostState GetLastHardState(void) const override;
-       double GetLastStateUp(void) const;
-       double GetLastStateDown(void) const;
+
+       virtual void SaveLastState(ServiceState state, double timestamp);
 
        static HostState StateFromString(const String& state);
        static String StateToString(HostState state);
index 37af4343771cb54684c6d621862374f2ad0ca37a..41998f30a115a9131a52b593e6ca33203b2c526d 100644 (file)
@@ -52,7 +52,8 @@ class Host : Checkable
        [enum, no_storage] HostState last_hard_state {
                get;
        };
-
+       [state] double last_state_up;
+       [state] double last_state_down;
 };
 
 }
index 35a83e9719326933039547739ad2be02c368e631..b4d778186e4b8e17351a7cb03b46e4d18cc1a8a8 100644 (file)
@@ -117,6 +117,18 @@ Host::Ptr Service::GetHost(void) const
        return m_Host;
 }
 
+void Service::SaveLastState(ServiceState state, double timestamp)
+{
+       if (state == ServiceOK)
+               SetLastStateOK(timestamp);
+       else if (state == ServiceWarning)
+               SetLastStateWarning(timestamp);
+       else if (state == ServiceCritical)
+               SetLastStateCritical(timestamp);
+       else if (state == ServiceUnknown)
+               SetLastStateUnknown(timestamp);
+}
+
 ServiceState Service::StateFromString(const String& state)
 {
        if (state == "OK")
index c863699ecb4b22180336c6628cfa54cbbb89fac5..dfe7b9c37a471cfd5df3e469e7670f06d73553fa 100644 (file)
@@ -45,6 +45,8 @@ public:
 
        virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Value *result) const override;
 
+       virtual void SaveLastState(ServiceState state, double timestamp);
+
        static ServiceState StateFromString(const String& state);
        static String StateToString(ServiceState state);
 
index 224e5fc58031b9d4c7048cfcad7e7d215b7eb8ca..82d15dcaa02e6f741e43e28b07abb5e45ece74ba 100644 (file)
@@ -74,6 +74,10 @@ class Service : Checkable < ServiceNameComposer
                        return GetLastHardStateRaw();
                }}}
        };
+       [state] double last_state_ok (LastStateOK);
+       [state] double last_state_warning;
+       [state] double last_state_critical;
+       [state] double last_state_unknown;
 };
 
 }