mirror of https://github.com/Icinga/icinga2.git
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:
parent
faf0865a94
commit
11574e0bf1
|
@ -17,6 +17,7 @@
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "icinga/compatutility.hpp"
|
||||||
#include "compat/checkresultreader.hpp"
|
#include "compat/checkresultreader.hpp"
|
||||||
#include "icinga/service.hpp"
|
#include "icinga/service.hpp"
|
||||||
#include "icinga/pluginutility.hpp"
|
#include "icinga/pluginutility.hpp"
|
||||||
|
@ -133,7 +134,8 @@ void CheckResultReader::ProcessCheckResultFile(const String& path) const
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckResult::Ptr result = new CheckResult();
|
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->SetOutput(co.first);
|
||||||
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
||||||
result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));
|
result->SetState(PluginUtility::ExitStatusToState(Convert::ToLong(attrs["return_code"])));
|
||||||
|
|
|
@ -728,6 +728,13 @@ String CompatUtility::EscapeString(const String& str)
|
||||||
return result;
|
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)
|
std::pair<unsigned long, unsigned long> CompatUtility::ConvertTimestamp(double time)
|
||||||
{
|
{
|
||||||
unsigned long time_sec = static_cast<long>(time);
|
unsigned long time_sec = static_cast<long>(time);
|
||||||
|
|
|
@ -118,6 +118,7 @@ public:
|
||||||
static int MapExternalCommandType(const String& name);
|
static int MapExternalCommandType(const String& name);
|
||||||
|
|
||||||
static String EscapeString(const String& str);
|
static String EscapeString(const String& str);
|
||||||
|
static String UnEscapeString(const String& str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CompatUtility(void);
|
CompatUtility(void);
|
||||||
|
|
|
@ -354,7 +354,8 @@ void ExternalCommandProcessor::ProcessServiceCheckResult(double time, const std:
|
||||||
|
|
||||||
int exitStatus = Convert::ToDouble(arguments[2]);
|
int exitStatus = Convert::ToDouble(arguments[2]);
|
||||||
CheckResult::Ptr result = new CheckResult();
|
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->SetOutput(co.first);
|
||||||
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
result->SetPerformanceData(PluginUtility::SplitPerfdata(co.second));
|
||||||
result->SetState(PluginUtility::ExitStatusToState(exitStatus));
|
result->SetState(PluginUtility::ExitStatusToState(exitStatus));
|
||||||
|
|
Loading…
Reference in New Issue