]> granicus.if.org Git - icinga2/commitdiff
livestatus: add commandstable name/line
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 11 Jul 2013 09:47:32 +0000 (11:47 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 11 Jul 2013 09:47:32 +0000 (11:47 +0200)
requires conversion of commandline (plain text or array).

refs #4372

components/livestatus/commandstable.cpp

index 703292bc65895dd27173246f7a76422a0992d304..ecbcfb91d9b3489aef181f61ae755dd937e3ddf1 100644 (file)
 #include "icinga/eventcommand.h"
 #include "icinga/notificationcommand.h"
 #include "base/dynamictype.h"
+#include "base/objectlock.h"
+#include "base/convert.h"
 #include <boost/foreach.hpp>
+#include <boost/algorithm/string/replace.hpp>
 
 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<Command::Ptr>(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<Command::Ptr>(row);
+
+       Value commandLine = command->GetCommandLine();
+
+       if (commandLine.IsObjectType<Array>()) {
+               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 += "<internal>";
+       }
+
+       return buf;
 }