2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2016-08-08 06:51:20 -04:00
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
#include "methods/exceptionchecktask.hpp"
|
|
|
|
|
#include "base/utility.hpp"
|
|
|
|
|
#include "base/convert.hpp"
|
|
|
|
|
#include "base/function.hpp"
|
|
|
|
|
#include "base/logger.hpp"
|
|
|
|
|
#include "base/exception.hpp"
|
|
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
2018-08-07 07:55:41 -04:00
|
|
|
REGISTER_FUNCTION_NONCONST(Internal, ExceptionCheck, &ExceptionCheckTask::ScriptFunc, "checkable:cr:resolvedMacros:useResolvedMacros");
|
2016-08-08 06:51:20 -04:00
|
|
|
|
2018-01-30 05:26:07 -05:00
|
|
|
void ExceptionCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
2017-12-19 09:50:05 -05:00
|
|
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
2016-08-08 06:51:20 -04:00
|
|
|
{
|
2018-02-21 07:42:58 -05:00
|
|
|
REQUIRE_NOT_NULL(checkable);
|
|
|
|
|
REQUIRE_NOT_NULL(cr);
|
2018-01-30 05:26:07 -05:00
|
|
|
|
2016-08-08 06:51:20 -04:00
|
|
|
if (resolvedMacros && !useResolvedMacros)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-07-20 10:29:26 -04:00
|
|
|
ScriptError scriptError = ScriptError("Test") << boost::errinfo_api_function("Test");
|
|
|
|
|
|
|
|
|
|
if (Checkable::ExecuteCommandProcessFinishedHandler) {
|
|
|
|
|
double now = Utility::GetTime();
|
|
|
|
|
ProcessResult pr;
|
|
|
|
|
pr.PID = -1;
|
|
|
|
|
pr.Output = scriptError.what();
|
|
|
|
|
pr.ExecutionStart = now;
|
|
|
|
|
pr.ExecutionEnd = now;
|
2020-07-22 05:38:41 -04:00
|
|
|
pr.ExitStatus = 3;
|
2020-07-20 10:29:26 -04:00
|
|
|
|
|
|
|
|
Checkable::ExecuteCommandProcessFinishedHandler("", pr);
|
|
|
|
|
} else {
|
|
|
|
|
BOOST_THROW_EXCEPTION(ScriptError("Test") << boost::errinfo_api_function("Test"));
|
|
|
|
|
}
|
2016-08-08 06:51:20 -04:00
|
|
|
}
|