Fix multi line handling for compat check results

When a multi line result is submitted via the command pipe, any multi line
output is escaped to a actual string '\n', because any external command only
can be a single line.

Example:
  [1432735140] PROCESS_SERVICE_CHECK_RESULT;host;service;3;Test1\nTest2|test=1

We need to unescape this values, just like we use to escape multi line output
for IDO and status.dat.

fixes #9324

Signed-off-by: Michael Friedrich <michael.friedrich@netways.de>
This commit is contained in:
Markus Frosch 2015-05-27 16:05:10 +02:00 committed by Michael Friedrich
parent cfbe82d841
commit 47c8b5e347
4 changed files with 13 additions and 2 deletions

View File

@ -17,6 +17,7 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
******************************************************************************/
#include "icinga/compatutility.hpp"
#include "compat/checkresultreader.hpp"
#include "compat/checkresultreader.tcpp"
#include "icinga/service.hpp"
@ -134,7 +135,8 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
}
CheckResult::Ptr result = new CheckResult();
std::pair<String, Value> co = PluginUtility::ParseCheckOutput(attrs["output"]);
String output = CompatUtility::UnEscapeString(attrs["output"]);
std::pair<String, Value> co = PluginUtility::ParseCheckOutput(output);
result->SetOutput(co.first);
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));

View File

@ -728,6 +728,13 @@ String CompatUtility::EscapeString(const String& str)
return result;
}
String CompatUtility::UnEscapeString(const String& str)
{
String result = str;
boost::algorithm::replace_all(result, "\\n", "\n");
return result;
}
std::pair<unsigned long, unsigned long> CompatUtility::ConvertTimestamp(double time)
{
unsigned long time_sec = static_cast<long>(time);

View File

@ -118,6 +118,7 @@ public:
static int MapExternalCommandType(const String& name);
static String EscapeString(const String& str);
static String UnEscapeString(const String& str);
private:
CompatUtility(void);

View File

@ -354,7 +354,8 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std:
int exitStatus = Convert::ToDouble(arguments[2]);
CheckResult::Ptr result = new CheckResult();
std::pair<String, String> co = PluginUtility::ParseCheckOutput(arguments[3]);
String output = CompatUtility::UnEscapeString(arguments[3]);
std::pair<String, String> co = PluginUtility::ParseCheckOutput(output);
result->SetOutput(co.first);
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
result->SetState(PluginUtility::ExitStatusToState(exitStatus));