diff --git a/components/livestatus/commandstable.cpp b/components/livestatus/commandstable.cpp index 6861b7f77..6f5d3d22b 100644 --- a/components/livestatus/commandstable.cpp +++ b/components/livestatus/commandstable.cpp @@ -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(row); + + if (!command) + return Empty; + + Dictionary::Ptr vars; + + { + ObjectLock olock(command); + vars = CompatUtility::GetCustomAttributeConfig(command); + } + + if (!vars) + return Empty; + + Array::Ptr cv = make_shared(); + + 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(row); + + if (!command) + return Empty; + + Dictionary::Ptr vars; + + { + ObjectLock olock(command); + vars = CompatUtility::GetCustomAttributeConfig(command); + } + + if (!vars) + return Empty; + + Array::Ptr cv = make_shared(); + + 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(row); + + if (!command) + return Empty; + + Dictionary::Ptr vars; + + { + ObjectLock olock(command); + vars = CompatUtility::GetCustomAttributeConfig(command); + } + + if (!vars) + return Empty; + + Array::Ptr cv = make_shared(); + + String key; + Value value; + BOOST_FOREACH(tie(key, value), vars) { + Array::Ptr key_val = make_shared(); + key_val->Add(key); + key_val->Add(value); + cv->Add(key_val); + } + + return cv; +} diff --git a/components/livestatus/commandstable.h b/components/livestatus/commandstable.h index 59469bf73..67e5a4f74 100644 --- a/components/livestatus/commandstable.h +++ b/components/livestatus/commandstable.h @@ -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 index 000000000..2e8715271 --- /dev/null +++ b/test/livestatus/queries/command/command @@ -0,0 +1,4 @@ +GET commands +Columns: name line custom_variables +ResponseHeader: fixed16 +