From da394b2ab03f5cb47297eeca3967313953127322 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Tue, 20 Jul 2021 11:10:26 +0200 Subject: [PATCH] Implement scheduling_source attribute (#6326) * Implement scheduling_source attribute This implements the attribute `scheduling_source` for hosts and services to show which endpoint is running the scheduler for the check. refs #4814 --- doc/08-advanced-topics.md | 1 + lib/icinga/apiactions.cpp | 1 + lib/icinga/checkable-check.cpp | 3 +++ lib/icinga/checkresult.ti | 1 + lib/icinga/host.cpp | 3 +++ lib/icinga/service.cpp | 4 +++- 6 files changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/08-advanced-topics.md b/doc/08-advanced-topics.md index a06defcaf..34330ed9e 100644 --- a/doc/08-advanced-topics.md +++ b/doc/08-advanced-topics.md @@ -1180,6 +1180,7 @@ to represent its internal state. The following types are exposed via the [API](1 output | String | The check output. performance\_data | Array | Array of [performance data values](08-advanced-topics.md#advanced-value-types-perfdatavalue). check\_source | String | Name of the node executing the check. + scheduling\_source | String | Name of the node scheduling the check. state | Number | The current state (0 = OK, 1 = WARNING, 2 = CRITICAL, 3 = UNKNOWN). command | Value | Array of command with shell-escaped arguments or command line string. execution\_start | Timestamp | Check execution start time (as a UNIX timestamp). diff --git a/lib/icinga/apiactions.cpp b/lib/icinga/apiactions.cpp index 3f18c1fc4..70cc4a6c4 100644 --- a/lib/icinga/apiactions.cpp +++ b/lib/icinga/apiactions.cpp @@ -104,6 +104,7 @@ Dictionary::Ptr ApiActions::ProcessCheckResult(const ConfigObject::Ptr& object, cr->SetExecutionEnd(HttpUtility::GetLastParameter(params, "execution_end")); cr->SetCheckSource(HttpUtility::GetLastParameter(params, "check_source")); + cr->SetSchedulingSource(HttpUtility::GetLastParameter(params, "scheduling_source")); Value perfData = params->Get("performance_data"); diff --git a/lib/icinga/checkable-check.cpp b/lib/icinga/checkable-check.cpp index b9ffe19e6..782899990 100644 --- a/lib/icinga/checkable-check.cpp +++ b/lib/icinga/checkable-check.cpp @@ -118,6 +118,9 @@ void Checkable::ProcessCheckResult(const CheckResult::Ptr& cr, const MessageOrig if (cr->GetExecutionEnd() == 0) cr->SetExecutionEnd(now); + if (!origin || origin->IsLocal()) + cr->SetSchedulingSource(IcingaApplication::GetInstance()->GetNodeName()); + Endpoint::Ptr command_endpoint = GetCommandEndpoint(); if (cr->GetCheckSource().IsEmpty()) { diff --git a/lib/icinga/checkresult.ti b/lib/icinga/checkresult.ti index 6fe49ae94..6739d9af2 100644 --- a/lib/icinga/checkresult.ti +++ b/lib/icinga/checkresult.ti @@ -61,6 +61,7 @@ class CheckResult }; [state] String check_source; + [state] String scheduling_source; [state] double ttl; [state] Dictionary::Ptr vars_before; diff --git a/lib/icinga/host.cpp b/lib/icinga/host.cpp index 6cddc5feb..36149d3dc 100644 --- a/lib/icinga/host.cpp +++ b/lib/icinga/host.cpp @@ -320,6 +320,9 @@ bool Host::ResolveMacro(const String& macro, const CheckResult::Ptr&, Value *res } else if (macro == "check_source") { *result = cr->GetCheckSource(); return true; + } else if (macro == "scheduling_source") { + *result = cr->GetSchedulingSource(); + return true; } } diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp index 9d3495667..8f625672a 100644 --- a/lib/icinga/service.cpp +++ b/lib/icinga/service.cpp @@ -267,6 +267,9 @@ bool Service::ResolveMacro(const String& macro, const CheckResult::Ptr& cr, Valu } else if (macro == "check_source") { *result = cr->GetCheckSource(); return true; + } else if (macro == "scheduling_source") { + *result = cr->GetSchedulingSource(); + return true; } } @@ -282,4 +285,3 @@ std::pair icinga::GetHostService(const Checkable::Ptr& else return std::make_pair(static_pointer_cast(checkable), nullptr); } -