From: Michael Friedrich Date: Thu, 11 Jul 2013 09:47:32 +0000 (+0200) Subject: livestatus: add commandstable name/line X-Git-Tag: v0.0.3~862 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=96e1935fb483a322b322bd6edee8b9cb1c7ae3e9;p=icinga2 livestatus: add commandstable name/line requires conversion of commandline (plain text or array). refs #4372 --- diff --git a/components/livestatus/commandstable.cpp b/components/livestatus/commandstable.cpp index 703292bc6..ecbcfb91d 100644 --- a/components/livestatus/commandstable.cpp +++ b/components/livestatus/commandstable.cpp @@ -23,7 +23,10 @@ #include "icinga/eventcommand.h" #include "icinga/notificationcommand.h" #include "base/dynamictype.h" +#include "base/objectlock.h" +#include "base/convert.h" #include +#include using namespace icinga; using namespace livestatus; @@ -60,12 +63,46 @@ void CommandsTable::FetchRows(const AddRowFunction& addRowFn) Value CommandsTable::NameAccessor(const Value& row) { - /* TODO */ - return Value(); + String buf; + Command::Ptr command = static_cast(row); + + if (command->GetType() == DynamicType::GetByName("CheckCommand")) + buf += "check_"; + if (command->GetType() == DynamicType::GetByName("NotificationCommand")) + buf += "notification_"; + if (command->GetType() == DynamicType::GetByName("EventCommand")) + buf += "event_"; + + buf += command->GetName(); + + return buf; } Value CommandsTable::LineAccessor(const Value& row) { - /* TODO */ - return Value(); + String buf; + Command::Ptr command = static_cast(row); + + Value commandLine = command->GetCommandLine(); + + if (commandLine.IsObjectType()) { + Array::Ptr args = commandLine; + + ObjectLock olock(args); + String arg; + BOOST_FOREACH(arg, args) { + // This is obviously incorrect for non-trivial cases. + String argitem = " \"" + arg + "\""; + boost::algorithm::replace_all(argitem, "\n", "\\n"); + buf += argitem; + } + } else if (!commandLine.IsEmpty()) { + String args = Convert::ToString(commandLine); + boost::algorithm::replace_all(args, "\n", "\\n"); + buf += args; + } else { + buf += ""; + } + + return buf; }