diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 1b0dab1e5..cff760c80 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -33,6 +33,7 @@ #include "icinga/eventcommand.hpp" #include "icinga/notificationcommand.hpp" #include "icinga/timeperiod.hpp" +#include "icinga/pluginutility.hpp" #include "remote/zone.hpp" #include "base/json.hpp" #include "base/logger.hpp" @@ -664,8 +665,10 @@ Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable) if (cr) { attrs->Set("output", CompatUtility::GetCheckResultOutput(cr)); attrs->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr)); - attrs->Set("performance_data", JsonEncode(cr->GetPerformanceData())); - attrs->Set("command", JsonEncode(cr->GetCommand())); + if (cr->GetPerformanceData()) + attrs->Set("performance_data", PluginUtility::FormatPerfdata(cr->GetPerformanceData())); + if (!cr->GetCommand().IsEmpty()) + attrs->Set("commandline", FormatCommandLine(cr->GetCommand())); attrs->Set("execution_time", cr->CalculateExecutionTime()); attrs->Set("latency", cr->CalculateLatency()); } @@ -707,7 +710,6 @@ Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable) return attrs; } - std::vector RedisWriter::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride) diff --git a/lib/redis/rediswriter-utility.cpp b/lib/redis/rediswriter-utility.cpp index 87146622a..62b5e35f2 100644 --- a/lib/redis/rediswriter-utility.cpp +++ b/lib/redis/rediswriter-utility.cpp @@ -36,6 +36,8 @@ #include #include #include +#include + using namespace icinga; @@ -48,6 +50,33 @@ String RedisWriter::FormatCheckSumBinary(const String& str) return output; } + +String RedisWriter::FormatCommandLine(const Value& commandLine) +{ + String result; + if (commandLine.IsObjectType()) { + Array::Ptr args = commandLine; + bool first = true; + + ObjectLock olock(args); + for (const Value& arg : args) { + String token = "'" + Convert::ToString(arg) + "'"; + + if (first) + first = false; + else + result += String(1, ' '); + + result += token; + } + } else if (!commandLine.IsEmpty()) { + result = commandLine; + boost::algorithm::replace_all(result, "\'", "\\'"); + } + + return result; +} + static Value l_DefaultEnv = "production"; String RedisWriter::GetEnvironment() diff --git a/lib/redis/rediswriter.hpp b/lib/redis/rediswriter.hpp index 5f7031634..3e5df9e84 100644 --- a/lib/redis/rediswriter.hpp +++ b/lib/redis/rediswriter.hpp @@ -83,6 +83,7 @@ private: /* utilities */ static String FormatCheckSumBinary(const String& str); + static String FormatCommandLine(const Value& commandLine); static String GetObjectIdentifier(const ConfigObject::Ptr& object); static String GetEnvironment(); @@ -99,7 +100,6 @@ private: static String GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj); static void MakeTypeChecksums(const ConfigObject::Ptr& object, std::set& propertiesBlacklist, Dictionary::Ptr& checkSums); - static void StateChangeHandler(const ConfigObject::Ptr &object); static void VersionChangedHandler(const ConfigObject::Ptr& object); static void DowntimeChangedHandler(const Downtime::Ptr& downtime);