MCPcopy Create free account
hub / github.com/Icinga/icinga2 / ExecuteCommand

Method ExecuteCommand

lib/icinga/apiactions.cpp:692–1009  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

690};
691
692Dictionary::Ptr ApiActions::ExecuteCommand(
693 const ConfigObject::Ptr& object,
694 const ApiUser::Ptr& apiUser,
695 const Dictionary::Ptr& params
696)
697{
698 ApiListener::Ptr listener = ApiListener::GetInstance();
699
700 if (!listener)
701 BOOST_THROW_EXCEPTION(std::invalid_argument("No ApiListener instance configured."));
702
703 /* Get command_type */
704 String command_type = "EventCommand";
705
706 if (params->Contains("command_type"))
707 command_type = HttpUtility::GetLastParameter(params, "command_type");
708
709 /* Validate command_type */
710 if (command_type != "EventCommand" && command_type != "CheckCommand" && command_type != "NotificationCommand")
711 return ApiActions::CreateResult(400, "Invalid command_type '" + command_type + "'.");
712
713 Checkable::Ptr checkable = dynamic_pointer_cast<Checkable>(object);
714
715 if (!checkable)
716 return ApiActions::CreateResult(404, "Can't start a command execution for a non-existent object.");
717
718 /* Get TTL param */
719 if (!params->Contains("ttl"))
720 return ApiActions::CreateResult(400, "Parameter ttl is required.");
721
722 double ttl = HttpUtility::GetLastParameter(params, "ttl");
723
724 if (ttl <= 0)
725 return ApiActions::CreateResult(400, "Parameter ttl must be greater than 0.");
726
727 ObjectLock oLock (checkable);
728
729 Host::Ptr host;
730 Service::Ptr service;
731 tie(host, service) = GetHostService(checkable);
732
733 String endpoint = "$command_endpoint$";
734
735 if (params->Contains("endpoint"))
736 endpoint = HttpUtility::GetLastParameter(params, "endpoint");
737
738 MacroProcessor::ResolverList resolvers;
739 Value macros;
740
741 if (params->Contains("macros")) {
742 macros = HttpUtility::GetLastParameter(params, "macros");
743 if (macros.IsObjectType<Dictionary>()) {
744 resolvers.emplace_back("override", macros);
745 } else {
746 return ApiActions::CreateResult(400, "Parameter macros must be a dictionary.");
747 }
748 }
749

Callers

nothing calls this directly

Calls 13

CanAccessObjectMethod · 0.80
GetWaitGroupMethod · 0.80
RelayMessageMethod · 0.80
GetEndpointsMethod · 0.80
ContainsMethod · 0.45
GetZoneMethod · 0.45
GetCommandEndpointMethod · 0.45
GetNameMethod · 0.45
ExecuteMethod · 0.45
SetMethod · 0.45
IsEmptyMethod · 0.45
GetParentMethod · 0.45

Tested by

no test coverage detected