mirror of https://github.com/Icinga/icinga2.git
Use ExecuteOverride to override the command
This commit is contained in:
parent
d7dadbfc66
commit
9c4a3aed1b
|
@ -686,14 +686,24 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
|
||||||
CheckCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(CheckCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);
|
CheckCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(CheckCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return ApiActions::CreateResult(404, "Can't find a valid " + command_type + " for '" + resolved_command + "'.");
|
return ApiActions::CreateResult(404, "Can't find a valid " + command_type + " for '" + resolved_command + "'.");
|
||||||
else
|
else {
|
||||||
|
CheckCommand::ExecuteOverride = cmd;
|
||||||
|
Defer resetCheckCommandOverride([]() {
|
||||||
|
CheckCommand::ExecuteOverride = nullptr;
|
||||||
|
});
|
||||||
cmd->Execute(checkable, cr, execMacros, false);
|
cmd->Execute(checkable, cr, execMacros, false);
|
||||||
|
}
|
||||||
} else if (command_type == "EventCommand") {
|
} else if (command_type == "EventCommand") {
|
||||||
EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(EventCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);
|
EventCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(EventCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
return ApiActions::CreateResult(404, "Can't find a valid " + command_type + " for '" + resolved_command + "'.");
|
return ApiActions::CreateResult(404, "Can't find a valid " + command_type + " for '" + resolved_command + "'.");
|
||||||
else
|
else {
|
||||||
|
EventCommand::ExecuteOverride = cmd;
|
||||||
|
Defer resetCheckCommandOverride([]() {
|
||||||
|
EventCommand::ExecuteOverride = nullptr;
|
||||||
|
});
|
||||||
cmd->Execute(checkable, execMacros, false);
|
cmd->Execute(checkable, execMacros, false);
|
||||||
|
}
|
||||||
} else if (command_type == "NotificationCommand") {
|
} else if (command_type == "NotificationCommand") {
|
||||||
NotificationCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(NotificationCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);
|
NotificationCommand::Ptr cmd = GetSingleObjectByNameUsingPermissions(NotificationCommand::GetTypeName(), resolved_command, ActionsHandler::AuthenticatedApiUser);
|
||||||
if (!cmd)
|
if (!cmd)
|
||||||
|
@ -731,6 +741,11 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object,
|
||||||
return ApiActions::CreateResult(404, "Can't find a valid notification for '" + resolved_notification + "'.");
|
return ApiActions::CreateResult(404, "Can't find a valid notification for '" + resolved_notification + "'.");
|
||||||
execParams->Set("notification", notification->GetName());
|
execParams->Set("notification", notification->GetName());
|
||||||
|
|
||||||
|
NotificationCommand::ExecuteOverride = cmd;
|
||||||
|
Defer resetCheckCommandOverride([]() {
|
||||||
|
NotificationCommand::ExecuteOverride = nullptr;
|
||||||
|
});
|
||||||
|
|
||||||
cmd->Execute(notification, user, cr, NotificationType::NotificationCustom,
|
cmd->Execute(notification, user, cr, NotificationType::NotificationCustom,
|
||||||
ActionsHandler::AuthenticatedApiUser->GetName(), "", execMacros, false);
|
ActionsHandler::AuthenticatedApiUser->GetName(), "", execMacros, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(CheckCommand);
|
REGISTER_TYPE(CheckCommand);
|
||||||
|
|
||||||
|
thread_local CheckCommand::Ptr CheckCommand::ExecuteOverride;
|
||||||
|
|
||||||
void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
void CheckCommand::Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
DECLARE_OBJECT(CheckCommand);
|
DECLARE_OBJECT(CheckCommand);
|
||||||
DECLARE_OBJECTNAME(CheckCommand);
|
DECLARE_OBJECTNAME(CheckCommand);
|
||||||
|
|
||||||
|
static thread_local CheckCommand::Ptr ExecuteOverride;
|
||||||
|
|
||||||
virtual void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
virtual void Execute(const Checkable::Ptr& checkable, const CheckResult::Ptr& cr,
|
||||||
const Dictionary::Ptr& resolvedMacros = nullptr,
|
const Dictionary::Ptr& resolvedMacros = nullptr,
|
||||||
bool useResolvedMacros = false);
|
bool useResolvedMacros = false);
|
||||||
|
|
|
@ -7,6 +7,8 @@ using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(EventCommand);
|
REGISTER_TYPE(EventCommand);
|
||||||
|
|
||||||
|
thread_local EventCommand::Ptr EventCommand::ExecuteOverride;
|
||||||
|
|
||||||
void EventCommand::Execute(const Checkable::Ptr& checkable,
|
void EventCommand::Execute(const Checkable::Ptr& checkable,
|
||||||
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
DECLARE_OBJECT(EventCommand);
|
DECLARE_OBJECT(EventCommand);
|
||||||
DECLARE_OBJECTNAME(EventCommand);
|
DECLARE_OBJECTNAME(EventCommand);
|
||||||
|
|
||||||
|
static thread_local EventCommand::Ptr ExecuteOverride;
|
||||||
|
|
||||||
virtual void Execute(const Checkable::Ptr& checkable,
|
virtual void Execute(const Checkable::Ptr& checkable,
|
||||||
const Dictionary::Ptr& resolvedMacros = nullptr,
|
const Dictionary::Ptr& resolvedMacros = nullptr,
|
||||||
bool useResolvedMacros = false);
|
bool useResolvedMacros = false);
|
||||||
|
|
|
@ -7,6 +7,8 @@ using namespace icinga;
|
||||||
|
|
||||||
REGISTER_TYPE(NotificationCommand);
|
REGISTER_TYPE(NotificationCommand);
|
||||||
|
|
||||||
|
thread_local NotificationCommand::Ptr NotificationCommand::ExecuteOverride;
|
||||||
|
|
||||||
Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification,
|
Dictionary::Ptr NotificationCommand::Execute(const Notification::Ptr& notification,
|
||||||
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type,
|
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type,
|
||||||
const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
|
const String& author, const String& comment, const Dictionary::Ptr& resolvedMacros,
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
DECLARE_OBJECT(NotificationCommand);
|
DECLARE_OBJECT(NotificationCommand);
|
||||||
DECLARE_OBJECTNAME(NotificationCommand);
|
DECLARE_OBJECTNAME(NotificationCommand);
|
||||||
|
|
||||||
|
static thread_local NotificationCommand::Ptr ExecuteOverride;
|
||||||
|
|
||||||
virtual Dictionary::Ptr Execute(const intrusive_ptr<Notification>& notification,
|
virtual Dictionary::Ptr Execute(const intrusive_ptr<Notification>& notification,
|
||||||
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type,
|
const User::Ptr& user, const CheckResult::Ptr& cr, const NotificationType& type,
|
||||||
const String& author, const String& comment,
|
const String& author, const String& comment,
|
||||||
|
|
|
@ -28,7 +28,11 @@ void ClusterCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRe
|
||||||
if (resolvedMacros && !useResolvedMacros)
|
if (resolvedMacros && !useResolvedMacros)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
CheckCommand::Ptr command;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
command = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
command = checkable->GetCheckCommand();
|
||||||
String commandName = command->GetName();
|
String commandName = command->GetName();
|
||||||
|
|
||||||
ApiListener::Ptr listener = ApiListener::GetInstance();
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
||||||
|
|
|
@ -21,7 +21,11 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
ApiListener::Ptr listener = ApiListener::GetInstance();
|
ApiListener::Ptr listener = ApiListener::GetInstance();
|
||||||
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
CheckCommand::Ptr command;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
command = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
command = checkable->GetCheckCommand();
|
||||||
String commandName = command->GetName();
|
String commandName = command->GetName();
|
||||||
|
|
||||||
if (!listener) {
|
if (!listener) {
|
||||||
|
|
|
@ -22,7 +22,11 @@ void DummyCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
|
||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
CheckCommand::Ptr command;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
command = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
command = checkable->GetCheckCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
|
|
|
@ -26,7 +26,11 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
CheckCommand::Ptr command;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
command = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
command = checkable->GetCheckCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
|
|
|
@ -22,7 +22,11 @@ void PluginCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
CheckCommand::Ptr commandObj;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
commandObj = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
commandObj = checkable->GetCheckCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
|
|
|
@ -21,7 +21,11 @@ void PluginEventTask::ScriptFunc(const Checkable::Ptr& checkable,
|
||||||
{
|
{
|
||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
|
|
||||||
EventCommand::Ptr commandObj = checkable->GetEventCommand();
|
EventCommand::Ptr commandObj;
|
||||||
|
if (EventCommand::ExecuteOverride)
|
||||||
|
commandObj = EventCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
commandObj = checkable->GetEventCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
|
|
|
@ -25,7 +25,11 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
|
||||||
REQUIRE_NOT_NULL(notification);
|
REQUIRE_NOT_NULL(notification);
|
||||||
REQUIRE_NOT_NULL(user);
|
REQUIRE_NOT_NULL(user);
|
||||||
|
|
||||||
NotificationCommand::Ptr commandObj = notification->GetCommand();
|
NotificationCommand::Ptr commandObj;
|
||||||
|
if (NotificationCommand::ExecuteOverride)
|
||||||
|
commandObj = NotificationCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
commandObj = notification->GetCommand();
|
||||||
|
|
||||||
auto type = static_cast<NotificationType>(itype);
|
auto type = static_cast<NotificationType>(itype);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,11 @@ void RandomCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckRes
|
||||||
+ ". Icinga 2 has been running for " + Utility::FormatDuration(uptime)
|
+ ". Icinga 2 has been running for " + Utility::FormatDuration(uptime)
|
||||||
+ ". Version: " + Application::GetAppVersion();
|
+ ". Version: " + Application::GetAppVersion();
|
||||||
|
|
||||||
CheckCommand::Ptr command = checkable->GetCheckCommand();
|
CheckCommand::Ptr command;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
command = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
command = checkable->GetCheckCommand();
|
||||||
String commandName = command->GetName();
|
String commandName = command->GetName();
|
||||||
ServiceState state = static_cast<ServiceState>(Utility::Random() % 4);
|
ServiceState state = static_cast<ServiceState>(Utility::Random() % 4);
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,11 @@ void SleepCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const CheckResu
|
||||||
REQUIRE_NOT_NULL(checkable);
|
REQUIRE_NOT_NULL(checkable);
|
||||||
REQUIRE_NOT_NULL(cr);
|
REQUIRE_NOT_NULL(cr);
|
||||||
|
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
CheckCommand::Ptr commandObj;
|
||||||
|
if (CheckCommand::ExecuteOverride)
|
||||||
|
commandObj = CheckCommand::ExecuteOverride;
|
||||||
|
else
|
||||||
|
commandObj = checkable->GetCheckCommand();
|
||||||
|
|
||||||
Host::Ptr host;
|
Host::Ptr host;
|
||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
|
|
Loading…
Reference in New Issue