From: Gunnar Beutner Date: Fri, 18 Oct 2013 09:29:31 +0000 (+0200) Subject: Implement HOSTDURATIONSEC and SERVICEDURATIONSEC macros. X-Git-Tag: v0.0.3~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cbf82e1cb83c2b2c8f7898d82b25c175311bf710;p=icinga2 Implement HOSTDURATIONSEC and SERVICEDURATIONSEC macros. --- diff --git a/doc/3.03-macros.md b/doc/3.03-macros.md index db9e74354..df595eb64 100644 --- a/doc/3.03-macros.md +++ b/doc/3.03-macros.md @@ -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. diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 386114944..fb36c11ae 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -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(); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 6caa1aa5f..5092640ec 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -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) {