Skip to content

Commit

Permalink
Truncate several macros if a notification command line gets too big t…
Browse files Browse the repository at this point in the history
…o run

Namely $host.output$, $service.output$ and $notification.comment$.
  • Loading branch information
Al2Klimov committed Nov 9, 2023
1 parent f7e73f3 commit 91cd8e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/icinga/pluginutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ using namespace icinga;
void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable,
const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int timeout,
const std::function<void(const Value& commandLine, const ProcessResult&)>& callback)
const std::function<void(const Value& commandLine, const ProcessResult&)>& callback,
const Array::Ptr& safeToTruncate)
{
Value raw_command = commandObj->GetCommandLine();
Dictionary::Ptr raw_arguments = commandObj->GetArguments();
Expand Down Expand Up @@ -74,7 +75,7 @@ void PluginUtility::ExecuteCommand(const Command::Ptr& commandObj, const Checkab
if (resolvedMacros && !useResolvedMacros)
return;

Process::Ptr process = new Process(Process::PrepareCommand(command), envMacros);
Process::Ptr process = new Process(Process::PrepareCommand(command), envMacros, safeToTruncate);

process->SetTimeout(timeout);
process->SetAdjustPriority(true);
Expand Down
3 changes: 2 additions & 1 deletion lib/icinga/pluginutility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class PluginUtility
static void ExecuteCommand(const Command::Ptr& commandObj, const Checkable::Ptr& checkable,
const CheckResult::Ptr& cr, const MacroProcessor::ResolverList& macroResolvers,
const Dictionary::Ptr& resolvedMacros, bool useResolvedMacros, int timeout,
const std::function<void(const Value& commandLine, const ProcessResult&)>& callback = std::function<void(const Value& commandLine, const ProcessResult&)>());
const std::function<void(const Value& commandLine, const ProcessResult&)>& callback = std::function<void(const Value& commandLine, const ProcessResult&)>(),
const Array::Ptr& safeToTruncate = nullptr);

static ServiceState ExitStatusToState(int exitStatus);
static std::pair<String, String> ParseCheckOutput(const String& output);
Expand Down
20 changes: 19 additions & 1 deletion lib/methods/pluginnotificationtask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,26 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
callback = [checkable](const Value& commandline, const ProcessResult& pr) { ProcessFinishedHandler(checkable, commandline, pr); };
}

Array::Ptr safeToTruncate = new Array();

auto hostCr (host->GetLastCheckResult());

if (hostCr) {
safeToTruncate->Add(hostCr->GetOutput());
}

if (service) {
auto cr (service->GetLastCheckResult());

if (cr) {
safeToTruncate->Add(cr->GetOutput());
}
}

safeToTruncate->Add(comment);

PluginUtility::ExecuteCommand(commandObj, checkable, cr, resolvers,
resolvedMacros, useResolvedMacros, timeout, callback);
resolvedMacros, useResolvedMacros, timeout, callback, safeToTruncate);
}

void PluginNotificationTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, const Value& commandLine, const ProcessResult& pr)
Expand Down

0 comments on commit 91cd8e1

Please sign in to comment.