Change commandline and performancedata

This commit is contained in:
Jean Flach 2018-12-03 15:47:05 +01:00 committed by Michael Friedrich
parent 3439ea755f
commit 553f6f6ba9
3 changed files with 35 additions and 4 deletions

View File

@ -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<String>
RedisWriter::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType,
const String& typeNameOverride)

View File

@ -36,6 +36,8 @@
#include <map>
#include <utility>
#include <vector>
#include <boost/algorithm/string.hpp>
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>()) {
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()

View File

@ -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<String>& 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);