Report failed agent checks to the master

fixes #8257
This commit is contained in:
Gunnar Beutner 2015-02-05 15:36:17 +01:00
parent 2d5112c878
commit 0605b76e7a
1 changed files with 23 additions and 3 deletions

View File

@ -1583,10 +1583,30 @@ Value ApiEvents::ExecuteCommandAPIHandler(const MessageOrigin& origin, const Dic
Dictionary::Ptr macros = params->Get("macros"); Dictionary::Ptr macros = params->Get("macros");
if (command_type == "check_command") if (command_type == "check_command") {
host->ExecuteCheck(macros, true); try {
else if (command_type == "event_command") 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); host->ExecuteEventHandler(macros, true);
}
return Empty; return Empty;
} }