From 0605b76e7abd280f9b826246407a1670151553aa Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 5 Feb 2015 15:36:17 +0100 Subject: [PATCH] Report failed agent checks to the master fixes #8257 --- lib/icinga/apievents.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/icinga/apievents.cpp b/lib/icinga/apievents.cpp index 53048524e..c38284f54 100644 --- a/lib/icinga/apievents.cpp +++ b/lib/icinga/apievents.cpp @@ -1583,10 +1583,30 @@ Value ApiEvents::ExecuteCommandAPIHandler(const MessageOrigin& origin, const Dic Dictionary::Ptr macros = params->Get("macros"); - if (command_type == "check_command") - host->ExecuteCheck(macros, true); - else if (command_type == "event_command") + if (command_type == "check_command") { + try { + host->ExecuteCheck(macros, true); + } catch (const std::exception& ex) { + CheckResult::Ptr cr = new CheckResult(); + cr->SetState(ServiceUnknown); + + String output = "Exception occured while checking '" + host->GetName() + "': " + DiagnosticInformation(ex); + cr->SetOutput(output); + + double now = Utility::GetTime(); + cr->SetScheduleStart(now); + cr->SetScheduleEnd(now); + cr->SetExecutionStart(now); + cr->SetExecutionEnd(now); + + Dictionary::Ptr message = MakeCheckResultMessage(host, cr); + listener->SyncSendMessage(endpoint, message); + + Log(LogCritical, "checker", output); + } + } else if (command_type == "event_command") { host->ExecuteEventHandler(macros, true); + } return Empty; }