]> granicus.if.org Git - icinga2/commitdiff
Livestatus: Add command custom variables.
authorMichael Friedrich <michael.friedrich@netways.de>
Fri, 4 Apr 2014 15:32:23 +0000 (17:32 +0200)
committerMichael Friedrich <michael.friedrich@netways.de>
Fri, 4 Apr 2014 15:32:23 +0000 (17:32 +0200)
Refs #5855

components/livestatus/commandstable.cpp
components/livestatus/commandstable.h
test/livestatus/queries/command/command [new file with mode: 0644]

index 6861b7f7764cb8dbebe9ca57ad31bfc51741be34..6f5d3d22bcccacb3201766288a1f9fca05690efc 100644 (file)
@@ -22,6 +22,7 @@
 #include "icinga/checkcommand.h"
 #include "icinga/eventcommand.h"
 #include "icinga/notificationcommand.h"
+#include "icinga/compatutility.h"
 #include "base/dynamictype.h"
 #include "base/objectlock.h"
 #include "base/convert.h"
@@ -40,6 +41,9 @@ void CommandsTable::AddColumns(Table *table, const String& prefix,
 {
        table->AddColumn(prefix + "name", Column(&CommandsTable::NameAccessor, objectAccessor));
        table->AddColumn(prefix + "line", Column(&CommandsTable::LineAccessor, objectAccessor));
+       table->AddColumn(prefix + "custom_variable_names", Column(&CommandsTable::CustomVariableNamesAccessor, objectAccessor));
+       table->AddColumn(prefix + "custom_variable_values", Column(&CommandsTable::CustomVariableValuesAccessor, objectAccessor));
+       table->AddColumn(prefix + "custom_variables", Column(&CommandsTable::CustomVariablesAccessor, objectAccessor));
 }
 
 String CommandsTable::GetName(void) const
@@ -111,3 +115,90 @@ Value CommandsTable::LineAccessor(const Value& row)
 
        return buf;
 }
+
+Value CommandsTable::CustomVariableNamesAccessor(const Value& row)
+{
+       Command::Ptr command = static_cast<Command::Ptr>(row);
+
+       if (!command)
+               return Empty;
+
+       Dictionary::Ptr vars;
+
+       {
+               ObjectLock olock(command);
+               vars = CompatUtility::GetCustomAttributeConfig(command);
+       }
+
+       if (!vars)
+               return Empty;
+
+       Array::Ptr cv = make_shared<Array>();
+
+       String key;
+       Value value;
+       BOOST_FOREACH(tie(key, value), vars) {
+               cv->Add(key);
+       }
+
+       return cv;
+}
+
+Value CommandsTable::CustomVariableValuesAccessor(const Value& row)
+{
+       Command::Ptr command = static_cast<Command::Ptr>(row);
+
+       if (!command)
+               return Empty;
+
+       Dictionary::Ptr vars;
+
+       {
+               ObjectLock olock(command);
+               vars = CompatUtility::GetCustomAttributeConfig(command);
+       }
+
+       if (!vars)
+               return Empty;
+
+       Array::Ptr cv = make_shared<Array>();
+
+       String key;
+       Value value;
+       BOOST_FOREACH(tie(key, value), vars) {
+               cv->Add(value);
+       }
+
+       return cv;
+}
+
+Value CommandsTable::CustomVariablesAccessor(const Value& row)
+{
+       Command::Ptr command = static_cast<Command::Ptr>(row);
+
+       if (!command)
+               return Empty;
+
+       Dictionary::Ptr vars;
+
+       {
+               ObjectLock olock(command);
+               vars = CompatUtility::GetCustomAttributeConfig(command);
+       }
+
+       if (!vars)
+               return Empty;
+
+       Array::Ptr cv = make_shared<Array>();
+
+       String key;
+       Value value;
+       BOOST_FOREACH(tie(key, value), vars) {
+               Array::Ptr key_val = make_shared<Array>();
+               key_val->Add(key);
+               key_val->Add(value);
+               cv->Add(key_val);
+       }
+
+       return cv;
+}
index 59469bf7376db4112163d9b8929e3d1ede538ccb..67e5a4f7463de2345dd043821a545296818487fc 100644 (file)
@@ -47,6 +47,9 @@ protected:
 
        static Value NameAccessor(const Value& row);
        static Value LineAccessor(const Value& row);
+       static Value CustomVariableNamesAccessor(const Value& row);
+       static Value CustomVariableValuesAccessor(const Value& row);
+       static Value CustomVariablesAccessor(const Value& row);
 };
 
 }
diff --git a/test/livestatus/queries/command/command b/test/livestatus/queries/command/command
new file mode 100644 (file)
index 0000000..2e87152
--- /dev/null
@@ -0,0 +1,4 @@
+GET commands
+Columns: name line custom_variables
+ResponseHeader: fixed16
+