ExternalCommandProcessor::RegisterCommand(): allow callback to take a CheckResultProducer::Ptr

This commit is contained in:
Alexander A. Klimov 2025-04-02 15:34:55 +02:00
parent ade302a08b
commit 8dfa24fcec
2 changed files with 13 additions and 1 deletions

View File

@ -115,6 +115,16 @@ void ExternalCommandProcessor::RegisterCommand(const String& command, const Exte
GetCommands()[command] = eci;
}
void ExternalCommandProcessor::RegisterCommand(const String& command, const ExternalCommandCallbackLite& callback, size_t minArgs, size_t maxArgs)
{
RegisterCommand(
command,
[callback](const CheckResultProducer::Ptr&, double time, const std::vector<String>& args) { callback(time, args); },
minArgs,
maxArgs
);
}
void ExternalCommandProcessor::RegisterCommands()
{
RegisterCommand("PROCESS_HOST_CHECK_RESULT", &ExternalCommandProcessor::ProcessHostCheckResult, 3);

View File

@ -13,7 +13,8 @@
namespace icinga
{
typedef std::function<void (double, const std::vector<String>& arguments)> ExternalCommandCallback;
typedef std::function<void(const CheckResultProducer::Ptr&, double, const std::vector<String>& arguments)> ExternalCommandCallback;
typedef std::function<void(double, const std::vector<String>& arguments)> ExternalCommandCallbackLite;
struct ExternalCommandInfo
{
@ -158,6 +159,7 @@ private:
static void ChangeCustomCommandVarInternal(const Command::Ptr& command, const String& name, const Value& value);
static void RegisterCommand(const String& command, const ExternalCommandCallback& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX);
static void RegisterCommand(const String& command, const ExternalCommandCallbackLite& callback, size_t minArgs = 0, size_t maxArgs = UINT_MAX);
static void RegisterCommands();
static std::mutex& GetMutex();