Livestatus: Add application variables to status table.

Refs #5855
This commit is contained in:
Michael Friedrich 2014-04-04 17:45:23 +02:00
parent fb5d0f3907
commit 31d54b2760
4 changed files with 74 additions and 0 deletions

View File

@ -96,6 +96,10 @@ void StatusTable::AddColumns(Table *table, const String& prefix,
table->AddColumn(prefix + "livestatus_active_connections", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "livestatus_active_connections", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livestatus_queued_connections", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "livestatus_queued_connections", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livestatus_threads", Column(&Table::ZeroAccessor, objectAccessor)); table->AddColumn(prefix + "livestatus_threads", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_names", Column(&StatusTable::CustomVariableNamesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_values", Column(&StatusTable::CustomVariableValuesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variables", Column(&StatusTable::CustomVariablesAccessor, objectAccessor));
} }
String StatusTable::GetName(void) const String StatusTable::GetName(void) const
@ -202,3 +206,60 @@ Value StatusTable::LivestatusActiveConnectionsAccessor(const Value&)
{ {
return LivestatusListener::GetClientsConnected(); return LivestatusListener::GetClientsConnected();
} }
Value StatusTable::CustomVariableNamesAccessor(const Value& row)
{
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
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 StatusTable::CustomVariableValuesAccessor(const Value& row)
{
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
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 StatusTable::CustomVariablesAccessor(const Value&)
{
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
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

@ -63,6 +63,9 @@ protected:
static Value ProgramVersionAccessor(const Value& row); static Value ProgramVersionAccessor(const Value& row);
static Value LivestatusVersionAccessor(const Value& row); static Value LivestatusVersionAccessor(const Value& row);
static Value LivestatusActiveConnectionsAccessor(const Value& row); static Value LivestatusActiveConnectionsAccessor(const Value& row);
static Value CustomVariableNamesAccessor(const Value& row);
static Value CustomVariableValuesAccessor(const Value& row);
static Value CustomVariablesAccessor(const Value& row);
}; };
} }

View File

@ -12,6 +12,7 @@ Changes require newest Icinga Classic UI releases.
> **Note** > **Note**
> >
> Command definitions get custom variables from 'vars' dictionary. > Command definitions get custom variables from 'vars' dictionary.
> Programstatus object gets custom variables from 'IcingaVars' constant.
### <a id="schema-db-ido"></a> DB IDO ### <a id="schema-db-ido"></a> DB IDO
@ -51,6 +52,7 @@ New columns:
> **Note** > **Note**
> >
> Additional command custom variables populated from 'vars' dictionary. > Additional command custom variables populated from 'vars' dictionary.
> Additional global custom variables populated from 'IcingaVars' constant (object_id is NULL).
### <a id="schema-livestatus"></a> Livestatus ### <a id="schema-livestatus"></a> Livestatus
@ -197,7 +199,11 @@ New columns:
commands | custom_variable_names commands | custom_variable_names
commands | custom_variable_values commands | custom_variable_values
commands | custom_variables commands | custom_variables
status | custom_variable_names
status | custom_variable_values
status | custom_variables
> **Note** > **Note**
> >
> Command custom variables reflect the local 'vars' dictionary. > Command custom variables reflect the local 'vars' dictionary.
> Status custom variables reflect the global 'IcingaVars' constant.

View File

@ -0,0 +1,4 @@
GET status
Columns: custom_variables
ResponseHeader: fixed16