From e33befabfb87016f7caeda43314cd75cc27b6427 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 25 Mar 2024 11:53:57 +0100 Subject: [PATCH 1/2] Make ProcessResult#ExitStatus and CheckResult#exit_status 64-bit ints so that they can hold Windows exit codes like 3221225477 (>2147483647). --- lib/base/process.hpp | 3 ++- lib/icinga/checkresult.ti | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/base/process.hpp b/lib/base/process.hpp index d83ba6ee7..7cbcbe129 100644 --- a/lib/base/process.hpp +++ b/lib/base/process.hpp @@ -5,6 +5,7 @@ #include "base/i2-base.hpp" #include "base/dictionary.hpp" +#include #include #include #include @@ -25,7 +26,7 @@ struct ProcessResult pid_t PID; double ExecutionStart; double ExecutionEnd; - long ExitStatus; + int_fast64_t ExitStatus; String Output; }; diff --git a/lib/icinga/checkresult.ti b/lib/icinga/checkresult.ti index 09312dc12..bee2cbd0b 100644 --- a/lib/icinga/checkresult.ti +++ b/lib/icinga/checkresult.ti @@ -1,5 +1,7 @@ /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ +#include + library icinga; namespace icinga @@ -50,7 +52,7 @@ class CheckResult [state] Timestamp execution_end; [state] Value command; - [state] int exit_status; + [state] int_fast64_t exit_status; [state, enum] ServiceState "state"; [state, enum] ServiceState previous_hard_state; From bb13e98ca5c78d1023203ca5e2d19e3749a5973a Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 25 Mar 2024 12:11:17 +0100 Subject: [PATCH 2/2] PluginCheckTask::ProcessFinishedHandler(): warn about exit codes outside 0..3 in the plugin output as well, in addition to the warning log. --- lib/methods/pluginchecktask.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/methods/pluginchecktask.cpp b/lib/methods/pluginchecktask.cpp index b4749fbfd..1a3df8105 100644 --- a/lib/methods/pluginchecktask.cpp +++ b/lib/methods/pluginchecktask.cpp @@ -10,6 +10,7 @@ #include "base/utility.hpp" #include "base/process.hpp" #include "base/convert.hpp" +#include using namespace icinga; @@ -66,15 +67,22 @@ void PluginCheckTask::ProcessFinishedHandler(const Checkable::Ptr& checkable, co Checkable::CurrentConcurrentChecks.fetch_sub(1); Checkable::DecreasePendingChecks(); + String output = pr.Output.Trim(); + if (pr.ExitStatus > 3) { Process::Arguments parguments = Process::PrepareCommand(commandLine); Log(LogWarning, "PluginCheckTask") << "Check command for object '" << checkable->GetName() << "' (PID: " << pr.PID << ", arguments: " << Process::PrettyPrintArguments(parguments) << ") terminated with exit code " << pr.ExitStatus << ", output: " << pr.Output; - } - String output = pr.Output.Trim(); + std::stringstream crOutput; + + crOutput << ""; + + output += crOutput.str(); + } std::pair co = PluginUtility::ParseCheckOutput(output); cr->SetCommand(commandLine);