]> granicus.if.org Git - icinga2/commitdiff
Implement HOSTDURATIONSEC and SERVICEDURATIONSEC macros.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 18 Oct 2013 09:29:31 +0000 (11:29 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 18 Oct 2013 09:29:49 +0000 (11:29 +0200)
doc/3.03-macros.md
lib/icinga/host.cpp
lib/icinga/service.cpp

index db9e74354b19ad4a4d2ca97fd015c946d5253714..df595eb64a209a5bda07c9d5d56a253e3e7378c0 100644 (file)
@@ -96,6 +96,8 @@ hosts or services:
   LASTHOSTSTATE          | The host's previous state. Can be one of `UNREACHABLE`, `UP` and `DOWN`.
   LASTHOSTSTATEID        | The host's previous state. Can be one of `0` (up), `1` (down) and `2` (unreachable).
   LASTHOSTSTATETYPE      | The host's previous state type. Can be one of `SOFT` and `HARD`.
+  LASTHOSTSTATECHANGE    | The last state change's timestamp.
+  HOSTDURATIONSEC        | The time since the last state change.
   HOSTLATENCY            | The host's check latency.
   HOSTEXECUTIONTIME      | The host's check execution time.
   HOSTOUTPUT             | The last check's output.
@@ -123,6 +125,7 @@ services:
   LASTSERVICESTATEID     | The service's previous state. Can be one of `0` (ok), `1` (warning), `2` (critical) and `3` (unknown).
   LASTSERVICESTATETYPE   | The service's previous state type. Can be one of `SOFT` and `HARD`.
   LASTSERVICESTATECHANGE | The last state change's timestamp.
+  SERVICEDURATIONSEC     | The time since the last state change.
   SERVICELATENCY         | The service's check latency.
   SERVICEEXECUTIONTIME   | The service's check execution time.
   SERVICEOUTPUT          | The last check's output.
index 3861149441f78b5dc89da2fb9928fe0023bc725a..fb36c11ae1a93d4ec82504df3cc53f0d5d9e7fe5 100644 (file)
@@ -609,6 +609,9 @@ bool Host::ResolveMacro(const String& macro, const Dictionary::Ptr&, String *res
                } else if (macro == "LASTHOSTSTATECHANGE") {
                        *result = Convert::ToString((long)hc->GetLastStateChange());
                        return true;
+               } else if (macro == "HOSTDURATIONSEC") {
+                       *result = Convert::ToString((long)(Utility::GetTime() - hc->GetLastStateChange()));
+                       return true;
                }
 
                hccr = hc->GetLastCheckResult();
index 6caa1aa5f6852332e4eaed8cff75d4f154143f56..5092640ecaf5cd0b60d4a03535fd17c1e5ccb319 100644 (file)
@@ -424,6 +424,9 @@ bool Service::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, Strin
        } else if (macro == "LASTSERVICESTATECHANGE") {
                *result = Convert::ToString((long)GetLastStateChange());
                return true;
+       } else if (macro == "SERVICEDURATIONSEC") {
+               *result = Convert::ToString((long)(Utility::GetTime() - GetLastStateChange()));
+               return true;
        }
 
        if (cr) {