From 6d5339574a9b185ac0d8555baaaa0b3a13f77d7b Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Fri, 15 Mar 2013 13:29:41 +0100 Subject: [PATCH] Fix perfdata macros. --- lib/icinga/service-check.cpp | 2 +- lib/icinga/service.cpp | 11 +++++++---- lib/icinga/service.h | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/icinga/service-check.cpp b/lib/icinga/service-check.cpp index f5fe1117f..0ca50cb8b 100644 --- a/lib/icinga/service-check.cpp +++ b/lib/icinga/service-check.cpp @@ -468,7 +468,7 @@ void Service::ProcessCheckResult(const Dictionary::Ptr& cr) olock.Unlock(); /* Update macros - these are used by event handlers and notifications. */ - cr->Set("macros", CalculateAllMacros()); + cr->Set("macros", CalculateAllMacros(cr)); cr->Seal(); diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index cd37f0f91..a7a545a63 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -429,7 +429,7 @@ set Service::GetParentServices(void) const /** * @threadsafety Always. */ -Dictionary::Ptr Service::CalculateDynamicMacros(void) const +Dictionary::Ptr Service::CalculateDynamicMacros(const Dictionary::Ptr& crOverride) const { Dictionary::Ptr macros = boost::make_shared(); @@ -453,8 +453,11 @@ Dictionary::Ptr Service::CalculateDynamicMacros(void) const cr = GetLastCheckResult(); } + if (crOverride) + cr = crOverride; + if (cr) { - ASSERT(cr->IsSealed()); + ASSERT(crOverride || cr->IsSealed()); macros->Set("SERVICELATENCY", Service::CalculateLatency(cr)); macros->Set("SERVICEEXECUTIONTIME", Service::CalculateExecutionTime(cr)); @@ -470,14 +473,14 @@ Dictionary::Ptr Service::CalculateDynamicMacros(void) const return macros; } -Dictionary::Ptr Service::CalculateAllMacros(void) const +Dictionary::Ptr Service::CalculateAllMacros(const Dictionary::Ptr& crOverride) const { vector macroDicts; macroDicts.push_back(GetMacros()); Host::Ptr host = GetHost(); - macroDicts.push_back(CalculateDynamicMacros()); + macroDicts.push_back(CalculateDynamicMacros(crOverride)); if (host) { macroDicts.push_back(host->GetMacros()); diff --git a/lib/icinga/service.h b/lib/icinga/service.h index 328483153..08ba0caea 100644 --- a/lib/icinga/service.h +++ b/lib/icinga/service.h @@ -95,8 +95,8 @@ public: String GetHostName(void) const; String GetShortName(void) const; - Dictionary::Ptr CalculateDynamicMacros(void) const; - Dictionary::Ptr CalculateAllMacros(void) const; + Dictionary::Ptr CalculateDynamicMacros(const Dictionary::Ptr& crOverride = Dictionary::Ptr()) const; + Dictionary::Ptr CalculateAllMacros(const Dictionary::Ptr& crOverride = Dictionary::Ptr()) const; set GetParentHosts(void) const; set GetParentServices(void) const;