diff --git a/components/livestatus/statustable.cpp b/components/livestatus/statustable.cpp index ccd64caf1..77a27f381 100644 --- a/components/livestatus/statustable.cpp +++ b/components/livestatus/statustable.cpp @@ -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_queued_connections", 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 @@ -202,3 +206,60 @@ Value StatusTable::LivestatusActiveConnectionsAccessor(const Value&) { return LivestatusListener::GetClientsConnected(); } + +Value StatusTable::CustomVariableNamesAccessor(const Value& row) +{ + Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars(); + + 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 StatusTable::CustomVariableValuesAccessor(const Value& row) +{ + Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars(); + + 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 StatusTable::CustomVariablesAccessor(const Value&) +{ + Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars(); + + 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/statustable.h b/components/livestatus/statustable.h index f79254b2c..68d910b04 100644 --- a/components/livestatus/statustable.h +++ b/components/livestatus/statustable.h @@ -63,6 +63,9 @@ protected: static Value ProgramVersionAccessor(const Value& row); static Value LivestatusVersionAccessor(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); }; } diff --git a/doc/6.12-schemas.md b/doc/6.12-schemas.md index 7955e8bbd..80955b35b 100644 --- a/doc/6.12-schemas.md +++ b/doc/6.12-schemas.md @@ -12,6 +12,7 @@ Changes require newest Icinga Classic UI releases. > **Note** > > Command definitions get custom variables from 'vars' dictionary. +> Programstatus object gets custom variables from 'IcingaVars' constant. ### DB IDO @@ -51,6 +52,7 @@ New columns: > **Note** > > Additional command custom variables populated from 'vars' dictionary. +> Additional global custom variables populated from 'IcingaVars' constant (object_id is NULL). ### Livestatus @@ -197,7 +199,11 @@ New columns: commands | custom_variable_names commands | custom_variable_values commands | custom_variables + status | custom_variable_names + status | custom_variable_values + status | custom_variables > **Note** > > Command custom variables reflect the local 'vars' dictionary. +> Status custom variables reflect the global 'IcingaVars' constant. diff --git a/test/livestatus/queries/status/custom b/test/livestatus/queries/status/custom new file mode 100644 index 000000000..1c8821d9d --- /dev/null +++ b/test/livestatus/queries/status/custom @@ -0,0 +1,4 @@ +GET status +Columns: custom_variables +ResponseHeader: fixed16 +