Livestatus: Add command custom variables.

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-04 17:32:23 +02:00
parent af621214d4
commit 5030bab4f3
3 changed files with 98 additions and 0 deletions

View 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;
}

View 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);
};
}

View File

@ -0,0 +1,4 @@
GET commands
Columns: name line custom_variables
ResponseHeader: fixed16