mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Revert "Implement the 'evaluate-macros' API action"
This reverts commit 851135d3a1643dd978453198b3f2523ccf6356e9. fixes #13091
This commit is contained in:
parent
35ce166bd2
commit
23e30ccb67
@ -1134,31 +1134,6 @@ Example:
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
### <a id="icinga2-api-actions-evaluate-macros"></a> evaluate-macros
|
|
||||||
|
|
||||||
Evaluates a macro string in the context of a specific host or service.
|
|
||||||
|
|
||||||
Send a `POST` request to the URL endpoint `/v1/actions/evaluate-macros`.
|
|
||||||
|
|
||||||
Parameter | Type | Description
|
|
||||||
--------------|-----------|--------------
|
|
||||||
query | string | **Required.** The macro string that should be evaluated.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
$ curl -k -s -u root:icinga -H 'Accept: application/json' -X POST 'https://localhost:5665/v1/actions/evaluate-macros' \
|
|
||||||
-d '{ "host": "icinga2-client1.localdomain", "query": "$host.name$" }' | python -m json.tool
|
|
||||||
{
|
|
||||||
"results": [
|
|
||||||
{
|
|
||||||
"code": 200.0,
|
|
||||||
"status": "Evaluated macros.",
|
|
||||||
"result": "icinga2-client1.localdomain",
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## <a id="icinga2-api-event-streams"></a> Event Streams
|
## <a id="icinga2-api-event-streams"></a> Event Streams
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ REGISTER_APIACTION(remove_downtime, "Service;Host;Downtime", &ApiActions::Remove
|
|||||||
REGISTER_APIACTION(shutdown_process, "", &ApiActions::ShutdownProcess);
|
REGISTER_APIACTION(shutdown_process, "", &ApiActions::ShutdownProcess);
|
||||||
REGISTER_APIACTION(restart_process, "", &ApiActions::RestartProcess);
|
REGISTER_APIACTION(restart_process, "", &ApiActions::RestartProcess);
|
||||||
REGISTER_APIACTION(generate_ticket, "", &ApiActions::GenerateTicket);
|
REGISTER_APIACTION(generate_ticket, "", &ApiActions::GenerateTicket);
|
||||||
REGISTER_APIACTION(evaluate_macros, "Service;Host", &ApiActions::EvaluateMacros);
|
|
||||||
|
|
||||||
Dictionary::Ptr ApiActions::CreateResult(int code, const String& status,
|
Dictionary::Ptr ApiActions::CreateResult(int code, const String& status,
|
||||||
const Dictionary::Ptr& additional)
|
const Dictionary::Ptr& additional)
|
||||||
@ -445,39 +444,3 @@ Dictionary::Ptr ApiActions::GenerateTicket(const ConfigObject::Ptr&,
|
|||||||
return ApiActions::CreateResult(200, "Generated PKI ticket '" + ticket + "' for common name '"
|
return ApiActions::CreateResult(200, "Generated PKI ticket '" + ticket + "' for common name '"
|
||||||
+ cn + "'.", additional);
|
+ cn + "'.", additional);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary::Ptr ApiActions::EvaluateMacros(const ConfigObject::Ptr& object,
|
|
||||||
const Dictionary::Ptr& params)
|
|
||||||
{
|
|
||||||
Checkable::Ptr checkable = static_pointer_cast<Checkable>(object);
|
|
||||||
|
|
||||||
if (!checkable)
|
|
||||||
return ApiActions::CreateResult(404, "Cannot evaluate macros without a host/service object.");
|
|
||||||
|
|
||||||
if (!params->Contains("query"))
|
|
||||||
return ApiActions::CreateResult(403, "A macro string must be specified.");
|
|
||||||
|
|
||||||
String query = HttpUtility::GetLastParameter(params, "query");
|
|
||||||
|
|
||||||
CheckCommand::Ptr commandObj = checkable->GetCheckCommand();
|
|
||||||
|
|
||||||
Host::Ptr host;
|
|
||||||
Service::Ptr service;
|
|
||||||
tie(host, service) = GetHostService(checkable);
|
|
||||||
|
|
||||||
MacroProcessor::ResolverList resolvers;
|
|
||||||
if (service)
|
|
||||||
resolvers.push_back(std::make_pair("service", service));
|
|
||||||
resolvers.push_back(std::make_pair("host", host));
|
|
||||||
resolvers.push_back(std::make_pair("command", commandObj));
|
|
||||||
resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
|
|
||||||
|
|
||||||
Dictionary::Ptr additional = new Dictionary();
|
|
||||||
|
|
||||||
CheckResult::Ptr cr = checkable->GetLastCheckResult();
|
|
||||||
|
|
||||||
additional->Set("result", MacroProcessor::ResolveMacros(query,
|
|
||||||
resolvers, cr));
|
|
||||||
|
|
||||||
return ApiActions::CreateResult(200, "Evaluated macros.", additional);
|
|
||||||
}
|
|
||||||
|
@ -46,7 +46,6 @@ public:
|
|||||||
static Dictionary::Ptr ShutdownProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
static Dictionary::Ptr ShutdownProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||||
static Dictionary::Ptr RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
static Dictionary::Ptr RestartProcess(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||||
static Dictionary::Ptr GenerateTicket(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
static Dictionary::Ptr GenerateTicket(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
||||||
static Dictionary::Ptr EvaluateMacros(const ConfigObject::Ptr& object, const Dictionary::Ptr& params);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Dictionary::Ptr CreateResult(int code, const String& status, const Dictionary::Ptr& additional = Dictionary::Ptr());
|
static Dictionary::Ptr CreateResult(int code, const String& status, const Dictionary::Ptr& additional = Dictionary::Ptr());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user