From aefda9f124228f6488676686b3041a8dac764b44 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Tue, 9 Jul 2013 17:15:38 +0200 Subject: [PATCH] livestatus: add contact*, status, service table attributes comments and downtimes require special object treatment -> linked to services? refs #4372 --- components/livestatus/commentstable.cpp | 112 +++++- components/livestatus/commentstable.h | 12 + components/livestatus/contactgroupstable.cpp | 7 +- components/livestatus/contactgroupstable.h | 1 + components/livestatus/contactstable.cpp | 125 +++++- components/livestatus/contactstable.h | 16 +- components/livestatus/downtimestable.cpp | 121 +++++- components/livestatus/downtimestable.h | 12 + components/livestatus/servicestable.cpp | 22 +- components/livestatus/statustable.cpp | 391 ++++++++++++++++--- components/livestatus/statustable.h | 50 +++ 11 files changed, 781 insertions(+), 88 deletions(-) diff --git a/components/livestatus/commentstable.cpp b/components/livestatus/commentstable.cpp index 777d7f75b..9aed6b441 100644 --- a/components/livestatus/commentstable.cpp +++ b/components/livestatus/commentstable.cpp @@ -35,17 +35,17 @@ CommentsTable::CommentsTable(void) void CommentsTable::AddColumns(Table *table, const String& prefix, const Column::ObjectAccessor& objectAccessor) { - table->AddColumn(prefix + "author", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "comment", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "id", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "entry_time", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "type", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "is_service", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "persistent", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "source", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "entry_type", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "expires", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "expire_time", Column(&Table::EmptyStringAccessor, objectAccessor)); + table->AddColumn(prefix + "author", Column(&CommentsTable::AuthorAccessor, objectAccessor)); + table->AddColumn(prefix + "comment", Column(&CommentsTable::CommentAccessor, objectAccessor)); + table->AddColumn(prefix + "id", Column(&CommentsTable::IdAccessor, objectAccessor)); + table->AddColumn(prefix + "entry_time", Column(&CommentsTable::EntryTimeAccessor, objectAccessor)); + table->AddColumn(prefix + "type", Column(&CommentsTable::TypeAccessor, objectAccessor)); + table->AddColumn(prefix + "is_service", Column(&CommentsTable::IsServiceAccessor, objectAccessor)); + table->AddColumn(prefix + "persistent", Column(&CommentsTable::PersistentAccessor, objectAccessor)); + table->AddColumn(prefix + "source", Column(&CommentsTable::SourceAccessor, objectAccessor)); + table->AddColumn(prefix + "entry_type", Column(&CommentsTable::EntryTypeAccessor, objectAccessor)); + table->AddColumn(prefix + "expires", Column(&CommentsTable::ExpiresAccessor, objectAccessor)); + table->AddColumn(prefix + "expire_time", Column(&CommentsTable::ExpireTimeAccessor, objectAccessor)); // TODO: Join services table. } @@ -72,3 +72,93 @@ void CommentsTable::FetchRows(const AddRowFunction& addRowFn) } } } + +Value CommentsTable::AuthorAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("author"); + */ +} + +Value CommentsTable::CommentAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("text"); + */ +} + +Value CommentsTable::IdAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("legacy_id"); + */ +} + +Value CommentsTable::EntryTimeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("entry_time"); + */ +} + +Value CommentsTable::TypeAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value CommentsTable::IsServiceAccessor(const Object::Ptr& object) +{ + /* + Service::Ptr svc = Service::GetOwnerByCommentID(row); + + return (svc->IsHostCheck() ? 0 : 1); + */ +} + +Value CommentsTable::PersistentAccessor(const Object::Ptr& object) +{ + /* TODO - always 1 */ + return 1; +} + +Value CommentsTable::SourceAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value CommentsTable::EntryTypeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("entry_type"); + */ +} + +Value CommentsTable::ExpiresAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("expires"); + */ +} + +Value CommentsTable::ExpireTimeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr comment = Service::GetCommentByID(row); + + return comment->Get("expire_time"); + */ +} diff --git a/components/livestatus/commentstable.h b/components/livestatus/commentstable.h index b47d36493..8e00b2ce1 100644 --- a/components/livestatus/commentstable.h +++ b/components/livestatus/commentstable.h @@ -44,6 +44,18 @@ public: protected: virtual void FetchRows(const AddRowFunction& addRowFn); + + static Value AuthorAccessor(const Object::Ptr& object); + static Value CommentAccessor(const Object::Ptr& object); + static Value IdAccessor(const Object::Ptr& object); + static Value EntryTimeAccessor(const Object::Ptr& object); + static Value TypeAccessor(const Object::Ptr& object); + static Value IsServiceAccessor(const Object::Ptr& object); + static Value PersistentAccessor(const Object::Ptr& object); + static Value SourceAccessor(const Object::Ptr& object); + static Value EntryTypeAccessor(const Object::Ptr& object); + static Value ExpiresAccessor(const Object::Ptr& object); + static Value ExpireTimeAccessor(const Object::Ptr& object); }; } diff --git a/components/livestatus/contactgroupstable.cpp b/components/livestatus/contactgroupstable.cpp index 309bba856..02f9fb553 100644 --- a/components/livestatus/contactgroupstable.cpp +++ b/components/livestatus/contactgroupstable.cpp @@ -34,7 +34,7 @@ void ContactGroupsTable::AddColumns(Table *table, const String& prefix, const Column::ObjectAccessor& objectAccessor) { table->AddColumn(prefix + "name", Column(&ContactGroupsTable::NameAccessor, objectAccessor)); - table->AddColumn(prefix + "alias", Column(&ContactGroupsTable::NameAccessor, objectAccessor)); + table->AddColumn(prefix + "alias", Column(&ContactGroupsTable::AliasAccessor, objectAccessor)); table->AddColumn(prefix + "members", Column(&ContactGroupsTable::MembersAccessor, objectAccessor)); } @@ -55,6 +55,11 @@ Value ContactGroupsTable::NameAccessor(const Object::Ptr& object) return static_pointer_cast(object)->GetName(); } +Value ContactGroupsTable::AliasAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetName(); +} + Value ContactGroupsTable::MembersAccessor(const Object::Ptr& object) { Array::Ptr members = boost::make_shared(); diff --git a/components/livestatus/contactgroupstable.h b/components/livestatus/contactgroupstable.h index 247a68942..abc9061bf 100644 --- a/components/livestatus/contactgroupstable.h +++ b/components/livestatus/contactgroupstable.h @@ -46,6 +46,7 @@ protected: virtual void FetchRows(const AddRowFunction& addRowFn); static Value NameAccessor(const Object::Ptr& object); + static Value AliasAccessor(const Object::Ptr& object); static Value MembersAccessor(const Object::Ptr& object); }; diff --git a/components/livestatus/contactstable.cpp b/components/livestatus/contactstable.cpp index a46cae893..54be7ef53 100644 --- a/components/livestatus/contactstable.cpp +++ b/components/livestatus/contactstable.cpp @@ -35,20 +35,20 @@ void ContactsTable::AddColumns(Table *table, const String& prefix, { table->AddColumn(prefix + "name", Column(&ContactsTable::NameAccessor, objectAccessor)); table->AddColumn(prefix + "alias", Column(&ContactsTable::NameAccessor, objectAccessor)); - table->AddColumn(prefix + "email", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "pager", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "host_notification_period", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "service_notification_period", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "can_submit_commands", Column(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "host_notifications_enabled", Column(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "service_notifications_enabled", Column(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "in_host_notification_period", Column(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "in_service_notification_period", Column(&Table::OneAccessor, objectAccessor)); - table->AddColumn(prefix + "custom_variable_names", Column(&Table::EmptyArrayAccessor, objectAccessor)); - table->AddColumn(prefix + "custom_variable_values", Column(&Table::EmptyArrayAccessor, objectAccessor)); - table->AddColumn(prefix + "custom_variables", Column(&Table::EmptyDictionaryAccessor, objectAccessor)); - table->AddColumn(prefix + "modified_attributes", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "modified_attributes_list", Column(&Table::EmptyArrayAccessor, objectAccessor)); + table->AddColumn(prefix + "email", Column(&ContactsTable::EmailAccessor, objectAccessor)); + table->AddColumn(prefix + "pager", Column(&ContactsTable::PagerAccessor, objectAccessor)); + table->AddColumn(prefix + "host_notification_period", Column(&ContactsTable::HostNotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "service_notification_period", Column(&ContactsTable::ServiceNotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "can_submit_commands", Column(&ContactsTable::CanSubmitCommandsAccessor, objectAccessor)); + table->AddColumn(prefix + "host_notifications_enabled", Column(&ContactsTable::HostNotificationsEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "service_notifications_enabled", Column(&ContactsTable::ServiceNotificationsEnabledAccessor, objectAccessor)); + table->AddColumn(prefix + "in_host_notification_period", Column(&ContactsTable::InHostNotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "in_service_notification_period", Column(&ContactsTable::InServiceNotificationPeriodAccessor, objectAccessor)); + table->AddColumn(prefix + "custom_variable_names", Column(&ContactsTable::CustomVariableNamesAccessor, objectAccessor)); + table->AddColumn(prefix + "custom_variable_values", Column(&ContactsTable::CustomVariableValuesAccessor, objectAccessor)); + table->AddColumn(prefix + "custom_variables", Column(&ContactsTable::CustomVariablesAccessor, objectAccessor)); + table->AddColumn(prefix + "modified_attributes", Column(&ContactsTable::ModifiedAttributesAccessor, objectAccessor)); + table->AddColumn(prefix + "modified_attributes_list", Column(&ContactsTable::ModifiedAttributesListAccessor, objectAccessor)); } String ContactsTable::GetName(void) const @@ -67,3 +67,100 @@ Value ContactsTable::NameAccessor(const Object::Ptr& object) { return static_pointer_cast(object)->GetName(); } + +Value ContactsTable::AliasAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetDisplayName(); +} + +Value ContactsTable::EmailAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr macros = static_pointer_cast(object)->GetMacros(); + + if (!macros) + return Value(); + + return macros->Get("email"); +} + +Value ContactsTable::PagerAccessor(const Object::Ptr& object) +{ + Dictionary::Ptr macros = static_pointer_cast(object)->GetMacros(); + + if (!macros) + return Value(); + + return macros->Get("pager"); +} + +Value ContactsTable::HostNotificationPeriodAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::ServiceNotificationPeriodAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::CanSubmitCommandsAccessor(const Object::Ptr& object) +{ + /* TODO - default 1*/ + return 1; +} + +Value ContactsTable::HostNotificationsEnabledAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::ServiceNotificationsEnabledAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::InHostNotificationPeriodAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::InServiceNotificationPeriodAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::CustomVariableNamesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::CustomVariableValuesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::CustomVariablesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value ContactsTable::ModifiedAttributesAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value ContactsTable::ModifiedAttributesListAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} diff --git a/components/livestatus/contactstable.h b/components/livestatus/contactstable.h index 673a61d38..941898b28 100644 --- a/components/livestatus/contactstable.h +++ b/components/livestatus/contactstable.h @@ -46,7 +46,21 @@ protected: virtual void FetchRows(const AddRowFunction& addRowFn); static Value NameAccessor(const Object::Ptr& object); - static Value MembersAccessor(const Object::Ptr& object); + static Value AliasAccessor(const Object::Ptr& object); + static Value EmailAccessor(const Object::Ptr& object); + static Value PagerAccessor(const Object::Ptr& object); + static Value HostNotificationPeriodAccessor(const Object::Ptr& object); + static Value ServiceNotificationPeriodAccessor(const Object::Ptr& object); + static Value CanSubmitCommandsAccessor(const Object::Ptr& object); + static Value HostNotificationsEnabledAccessor(const Object::Ptr& object); + static Value ServiceNotificationsEnabledAccessor(const Object::Ptr& object); + static Value InHostNotificationPeriodAccessor(const Object::Ptr& object); + static Value InServiceNotificationPeriodAccessor(const Object::Ptr& object); + static Value CustomVariableNamesAccessor(const Object::Ptr& object); + static Value CustomVariableValuesAccessor(const Object::Ptr& object); + static Value CustomVariablesAccessor(const Object::Ptr& object); + static Value ModifiedAttributesAccessor(const Object::Ptr& object); + static Value ModifiedAttributesListAccessor(const Object::Ptr& object); }; } diff --git a/components/livestatus/downtimestable.cpp b/components/livestatus/downtimestable.cpp index 0db77a6df..38f2f3484 100644 --- a/components/livestatus/downtimestable.cpp +++ b/components/livestatus/downtimestable.cpp @@ -35,17 +35,17 @@ DowntimesTable::DowntimesTable(void) void DowntimesTable::AddColumns(Table *table, const String& prefix, const Column::ObjectAccessor& objectAccessor) { - table->AddColumn(prefix + "author", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "comment", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "id", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "entry_time", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "type", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "is_service", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "start_time", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "end_time", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "fixed", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "duration", Column(&Table::EmptyStringAccessor, objectAccessor)); - table->AddColumn(prefix + "triggered_by", Column(&Table::EmptyStringAccessor, objectAccessor)); + table->AddColumn(prefix + "author", Column(&DowntimesTable::AuthorAccessor, objectAccessor)); + table->AddColumn(prefix + "comment", Column(&DowntimesTable::CommentAccessor, objectAccessor)); + table->AddColumn(prefix + "id", Column(&DowntimesTable::IdAccessor, objectAccessor)); + table->AddColumn(prefix + "entry_time", Column(&DowntimesTable::EntryTimeAccessor, objectAccessor)); + table->AddColumn(prefix + "type", Column(&DowntimesTable::TypeAccessor, objectAccessor)); + table->AddColumn(prefix + "is_service", Column(&DowntimesTable::IsServiceAccessor, objectAccessor)); + table->AddColumn(prefix + "start_time", Column(&DowntimesTable::StartTimeAccessor, objectAccessor)); + table->AddColumn(prefix + "end_time", Column(&DowntimesTable::EndTimeAccessor, objectAccessor)); + table->AddColumn(prefix + "fixed", Column(&DowntimesTable::FixedAccessor, objectAccessor)); + table->AddColumn(prefix + "duration", Column(&DowntimesTable::DurationAccessor, objectAccessor)); + table->AddColumn(prefix + "triggered_by", Column(&DowntimesTable::TriggeredByAccessor, objectAccessor)); // TODO: Join services table. } @@ -72,3 +72,102 @@ void DowntimesTable::FetchRows(const AddRowFunction& addRowFn) } } } + +Value DowntimesTable::AuthorAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("author"); + */ +} + +Value DowntimesTable::CommentAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("comment"); + */ +} + +Value DowntimesTable::IdAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("legacy_id"); + */ +} + +Value DowntimesTable::EntryTimeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("entry_time"); + */ +} + +Value DowntimesTable::TypeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + // 1 .. active, 0 .. pending + return (Service::IsDowntimeActive(downtime) ? 1 : 0); + */ +} + +Value DowntimesTable::IsServiceAccessor(const Object::Ptr& object) +{ + /* + Service::Ptr svc = Service::GetOwnerByDowntimeID(row); + + return (svc->IsHostCheck() ? 0 : 1); + */ +} + +Value DowntimesTable::StartTimeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("start_time"); + */ +} + +Value DowntimesTable::EndTimeAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("end_time"); + */ +} + +Value DowntimesTable::FixedAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("fixed"); + */ +} + +Value DowntimesTable::DurationAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("duration"); + */ +} + +Value DowntimesTable::TriggeredByAccessor(const Object::Ptr& object) +{ + /* + Dictionary::Ptr downtime = Service::GetDowntimeByID(row); + + return downtime->Get("triggered_by"); + */ +} diff --git a/components/livestatus/downtimestable.h b/components/livestatus/downtimestable.h index e14bb29e0..d79a5f98a 100644 --- a/components/livestatus/downtimestable.h +++ b/components/livestatus/downtimestable.h @@ -44,6 +44,18 @@ public: protected: virtual void FetchRows(const AddRowFunction& addRowFn); + + static Value AuthorAccessor(const Object::Ptr& object); + static Value CommentAccessor(const Object::Ptr& object); + static Value IdAccessor(const Object::Ptr& object); + static Value EntryTimeAccessor(const Object::Ptr& object); + static Value TypeAccessor(const Object::Ptr& object); + static Value IsServiceAccessor(const Object::Ptr& object); + static Value StartTimeAccessor(const Object::Ptr& object); + static Value EndTimeAccessor(const Object::Ptr& object); + static Value FixedAccessor(const Object::Ptr& object); + static Value DurationAccessor(const Object::Ptr& object); + static Value TriggeredByAccessor(const Object::Ptr& object); }; } diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index cdc076536..d3b045a56 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -571,6 +571,7 @@ Value ServicesTable::InNotificationPeriodAccessor(const Object::Ptr& object) Value ServicesTable::ContactsAccessor(const Object::Ptr& object) { /* TODO - host->service->notifications->users */ +/* std::set allUsers; std::set users; @@ -586,7 +587,7 @@ Value ServicesTable::ContactsAccessor(const Object::Ptr& object) std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin())); } } - +*/ return Value(); } @@ -634,6 +635,25 @@ Value ServicesTable::CustomVariableValuesAccessor(const Object::Ptr& object) Value ServicesTable::CustomVariablesAccessor(const Object::Ptr& object) { + /* + Service::Ptr svc = static_pointer_cast(object); + + Dictionary::Ptr custom = svc->Get("custom"); + + if (!custom) + return Value(); + + Dictionary::Ptr customvars = custom->ShallowClone(); + customvars->Remove("notes"); + customvars->Remove("action_url"); + customvars->Remove("notes_url"); + customvars->Remove("icon_image"); + customvars->Remove("icon_image_alt"); + customvars->Remove("statusmap_image"); + customvars->Remove("2d_coords"); + + return customvars; + */ /* TODO */ return Value(); } diff --git a/components/livestatus/statustable.cpp b/components/livestatus/statustable.cpp index c36e1153d..68df3a9e0 100644 --- a/components/livestatus/statustable.cpp +++ b/components/livestatus/statustable.cpp @@ -18,6 +18,8 @@ ******************************************************************************/ #include "livestatus/statustable.h" +#include "icinga/icingaapplication.h" +#include "icinga/cib.h" #include using namespace icinga; @@ -31,65 +33,65 @@ StatusTable::StatusTable(void) void StatusTable::AddColumns(Table *table, const String& prefix, const Column::ObjectAccessor& objectAccessor) { - table->AddColumn(prefix + "neb_callbacks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "neb_callbacks_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "neb_callbacks", Column(&StatusTable::NebCallbacksAccessor, objectAccessor)); + table->AddColumn(prefix + "neb_callbacks_rate", Column(&StatusTable::NebCallbacksRateAccessor, objectAccessor)); - table->AddColumn(prefix + "requests", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "requests_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "requests", Column(&StatusTable::RequestsAccessor, objectAccessor)); + table->AddColumn(prefix + "requests_rate", Column(&StatusTable::RequestsRateAccessor, objectAccessor)); - table->AddColumn(prefix + "connections", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "connections_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "connections", Column(&StatusTable::ConnectionsAccessor, objectAccessor)); + table->AddColumn(prefix + "connections_rate", Column(&StatusTable::ConnectionsRateAccessor, objectAccessor)); - table->AddColumn(prefix + "service_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "service_checks_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "service_checks", Column(&StatusTable::ServiceChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "service_checks_rate", Column(&StatusTable::ServiceChecksRateAccessor, objectAccessor)); - table->AddColumn(prefix + "host_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "host_checks_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "host_checks", Column(&StatusTable::HostChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "host_checks_rate", Column(&StatusTable::HostChecksRateAccessor, objectAccessor)); - table->AddColumn(prefix + "forks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "forks_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "forks", Column(&StatusTable::ForksAccessor, objectAccessor)); + table->AddColumn(prefix + "forks_rate", Column(&StatusTable::ForksRateAccessor, objectAccessor)); - table->AddColumn(prefix + "log_messages", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "log_messages_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "log_messages", Column(&StatusTable::LogMessagesAccessor, objectAccessor)); + table->AddColumn(prefix + "log_messages_rate", Column(&StatusTable::LogMessagesRateAccessor, objectAccessor)); - table->AddColumn(prefix + "external_commands", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "external_commands_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "external_commands", Column(&StatusTable::ExternalCommandsAccessor, objectAccessor)); + table->AddColumn(prefix + "external_commands_rate", Column(&StatusTable::ExternalCommandsRateAccessor, objectAccessor)); - table->AddColumn(prefix + "livechecks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "livechecks_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "livechecks", Column(&StatusTable::LivechecksAccessor, objectAccessor)); + table->AddColumn(prefix + "livechecks_rate", Column(&StatusTable::LivechecksRateAccessor, objectAccessor)); - table->AddColumn(prefix + "livecheck_overflows", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "livecheck_overflows_rate", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "livecheck_overflows", Column(&StatusTable::LivecheckOverflowsAccessor, objectAccessor)); + table->AddColumn(prefix + "livecheck_overflows_rate", Column(&StatusTable::LivecheckOverflowsRateAccessor, objectAccessor)); - table->AddColumn(prefix + "nagios_pid", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "enable_notifications", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "execute_service_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "accept_passive_service_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "execute_host_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "accept_passive_host_checks", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "enable_event_handlers", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "obsess_over_services", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "obsess_over_hosts", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "check_service_freshness", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "check_host_freshness", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "enable_flap_detection", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "process_performance_data", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "check_external_commands", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "program_start", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "last_command_check", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "last_log_rotation", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "interval_length", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "num_hosts", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "num_services", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "program_version", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "external_command_buffer_slots", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "external_command_buffer_usage", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "external_command_buffer_max", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "cached_log_messages", Column(&Table::ZeroAccessor, objectAccessor)); - table->AddColumn(prefix + "livestatus_version", 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_threads", Column(&Table::ZeroAccessor, objectAccessor)); + table->AddColumn(prefix + "nagios_pid", Column(&StatusTable::NagiosPidAccessor, objectAccessor)); + table->AddColumn(prefix + "enable_notifications", Column(&StatusTable::EnableNotificationsAccessor, objectAccessor)); + table->AddColumn(prefix + "execute_service_checks", Column(&StatusTable::ExecuteServiceChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "accept_passive_service_checks", Column(&StatusTable::AcceptPassiveServiceChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "execute_host_checks", Column(&StatusTable::ExecuteHostChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "accept_passive_host_checks", Column(&StatusTable::AcceptPassiveHostChecksAccessor, objectAccessor)); + table->AddColumn(prefix + "enable_event_handlers", Column(&StatusTable::EnableEventHandlersAccessor, objectAccessor)); + table->AddColumn(prefix + "obsess_over_services", Column(&StatusTable::ObsessOverHostsAccessor, objectAccessor)); + table->AddColumn(prefix + "obsess_over_hosts", Column(&StatusTable::ObsessOverServicesAccessor, objectAccessor)); + table->AddColumn(prefix + "check_service_freshness", Column(&StatusTable::CheckServiceFreshnessAccessor, objectAccessor)); + table->AddColumn(prefix + "check_host_freshness", Column(&StatusTable::CheckHostFreshnessAccessor, objectAccessor)); + table->AddColumn(prefix + "enable_flap_detection", Column(&StatusTable::EnableFlapDetectionAccessor, objectAccessor)); + table->AddColumn(prefix + "process_performance_data", Column(&StatusTable::ProcessPerformanceDataAccessor, objectAccessor)); + table->AddColumn(prefix + "check_external_commands", Column(&StatusTable::CheckExternalCommandsAccessor, objectAccessor)); + table->AddColumn(prefix + "program_start", Column(&StatusTable::ProgramStartAccessor, objectAccessor)); + table->AddColumn(prefix + "last_command_check", Column(&StatusTable::LastCommandCheckAccessor, objectAccessor)); + table->AddColumn(prefix + "last_log_rotation", Column(&StatusTable::LastLogRotationAccessor, objectAccessor)); + table->AddColumn(prefix + "interval_length", Column(&StatusTable::IntervalLengthAccessor, objectAccessor)); + table->AddColumn(prefix + "num_hosts", Column(&StatusTable::NumHostsAccessor, objectAccessor)); + table->AddColumn(prefix + "num_services", Column(&StatusTable::NumServicesAccessor, objectAccessor)); + table->AddColumn(prefix + "program_version", Column(&StatusTable::ProgramVersionAccessor, objectAccessor)); + table->AddColumn(prefix + "external_command_buffer_slots", Column(&StatusTable::ExternalCommandBufferSlotsAccessor, objectAccessor)); + table->AddColumn(prefix + "external_command_buffer_usage", Column(&StatusTable::ExternalCommandBufferUsageAccessor, objectAccessor)); + table->AddColumn(prefix + "external_command_buffer_max", Column(&StatusTable::ExternalCommandBufferMaxAccessor, objectAccessor)); + table->AddColumn(prefix + "cached_log_messages", Column(&StatusTable::CachedLogMessagesAccessor, objectAccessor)); + table->AddColumn(prefix + "livestatus_version", Column(&StatusTable::LivestatusVersionAccessor, objectAccessor)); + table->AddColumn(prefix + "livestatus_active_connections", Column(&StatusTable::LivestatusActiveConnectionsAccessor, objectAccessor)); + table->AddColumn(prefix + "livestatus_queued_connections", Column(&StatusTable::LivestatusQueuedConnectionsAccessor, objectAccessor)); + table->AddColumn(prefix + "livestatus_threads", Column(&StatusTable::LivestatusThreadsAccessor, objectAccessor)); } String StatusTable::GetName(void) const @@ -104,3 +106,294 @@ void StatusTable::FetchRows(const AddRowFunction& addRowFn) /* Return a fake row. */ addRowFn(obj); } + +Value StatusTable::NebCallbacksAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value StatusTable::NebCallbacksRateAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value StatusTable::RequestsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::RequestsRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ConnectionsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ConnectionsRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ServiceChecksAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ServiceChecksRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::HostChecksAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::HostChecksRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ForksAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ForksRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LogMessagesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LogMessagesRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ExternalCommandsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ExternalCommandsRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivechecksAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivechecksRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivecheckOverflowsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivecheckOverflowsRateAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::NagiosPidAccessor(const Object::Ptr& object) +{ + return Utility::GetPid(); +} + +Value StatusTable::EnableNotificationsAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::ExecuteServiceChecksAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::AcceptPassiveServiceChecksAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::ExecuteHostChecksAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::AcceptPassiveHostChecksAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::EnableEventHandlersAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::ObsessOverServicesAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value StatusTable::ObsessOverHostsAccessor(const Object::Ptr& object) +{ + /* not supported */ + return Value(); +} + +Value StatusTable::CheckServiceFreshnessAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::CheckHostFreshnessAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::EnableFlapDetectionAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::ProcessPerformanceDataAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::CheckExternalCommandsAccessor(const Object::Ptr& object) +{ + /* TODO - enabled by default*/ + return 1; +} + +Value StatusTable::ProgramStartAccessor(const Object::Ptr& object) +{ + return IcingaApplication::GetInstance()->GetStartTime(); +} + +Value StatusTable::LastCommandCheckAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LastLogRotationAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::IntervalLengthAccessor(const Object::Ptr& object) +{ + /* hardcoded 60s */ + return 60; +} + +Value StatusTable::NumHostsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::NumServicesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ProgramVersionAccessor(const Object::Ptr& object) +{ + return "2.0"; +} + +Value StatusTable::ExternalCommandBufferSlotsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ExternalCommandBufferUsageAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::ExternalCommandBufferMaxAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::CachedLogMessagesAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivestatusVersionAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivestatusActiveConnectionsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivestatusQueuedConnectionsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} + +Value StatusTable::LivestatusThreadsAccessor(const Object::Ptr& object) +{ + /* TODO */ + return Value(); +} diff --git a/components/livestatus/statustable.h b/components/livestatus/statustable.h index dcde0473d..63e2a8b31 100644 --- a/components/livestatus/statustable.h +++ b/components/livestatus/statustable.h @@ -44,6 +44,56 @@ public: protected: virtual void FetchRows(const AddRowFunction& addRowFn); + + static Value NebCallbacksAccessor(const Object::Ptr& object); + static Value NebCallbacksRateAccessor(const Object::Ptr& object); + static Value RequestsAccessor(const Object::Ptr& object); + static Value RequestsRateAccessor(const Object::Ptr& object); + static Value ConnectionsAccessor(const Object::Ptr& object); + static Value ConnectionsRateAccessor(const Object::Ptr& object); + static Value ServiceChecksAccessor(const Object::Ptr& object); + static Value ServiceChecksRateAccessor(const Object::Ptr& object); + static Value HostChecksAccessor(const Object::Ptr& object); + static Value HostChecksRateAccessor(const Object::Ptr& object); + static Value ForksAccessor(const Object::Ptr& object); + static Value ForksRateAccessor(const Object::Ptr& object); + static Value LogMessagesAccessor(const Object::Ptr& object); + static Value LogMessagesRateAccessor(const Object::Ptr& object); + static Value ExternalCommandsAccessor(const Object::Ptr& object); + static Value ExternalCommandsRateAccessor(const Object::Ptr& object); + static Value LivechecksAccessor(const Object::Ptr& object); + static Value LivechecksRateAccessor(const Object::Ptr& object); + static Value LivecheckOverflowsAccessor(const Object::Ptr& object); + static Value LivecheckOverflowsRateAccessor(const Object::Ptr& object); + static Value NagiosPidAccessor(const Object::Ptr& object); + static Value EnableNotificationsAccessor(const Object::Ptr& object); + static Value ExecuteServiceChecksAccessor(const Object::Ptr& object); + static Value AcceptPassiveServiceChecksAccessor(const Object::Ptr& object); + static Value ExecuteHostChecksAccessor(const Object::Ptr& object); + static Value AcceptPassiveHostChecksAccessor(const Object::Ptr& object); + static Value EnableEventHandlersAccessor(const Object::Ptr& object); + static Value ObsessOverServicesAccessor(const Object::Ptr& object); + static Value ObsessOverHostsAccessor(const Object::Ptr& object); + static Value CheckServiceFreshnessAccessor(const Object::Ptr& object); + static Value CheckHostFreshnessAccessor(const Object::Ptr& object); + static Value EnableFlapDetectionAccessor(const Object::Ptr& object); + static Value ProcessPerformanceDataAccessor(const Object::Ptr& object); + static Value CheckExternalCommandsAccessor(const Object::Ptr& object); + static Value ProgramStartAccessor(const Object::Ptr& object); + static Value LastCommandCheckAccessor(const Object::Ptr& object); + static Value LastLogRotationAccessor(const Object::Ptr& object); + static Value IntervalLengthAccessor(const Object::Ptr& object); + static Value NumHostsAccessor(const Object::Ptr& object); + static Value NumServicesAccessor(const Object::Ptr& object); + static Value ProgramVersionAccessor(const Object::Ptr& object); + static Value ExternalCommandBufferSlotsAccessor(const Object::Ptr& object); + static Value ExternalCommandBufferUsageAccessor(const Object::Ptr& object); + static Value ExternalCommandBufferMaxAccessor(const Object::Ptr& object); + static Value CachedLogMessagesAccessor(const Object::Ptr& object); + static Value LivestatusVersionAccessor(const Object::Ptr& object); + static Value LivestatusActiveConnectionsAccessor(const Object::Ptr& object); + static Value LivestatusQueuedConnectionsAccessor(const Object::Ptr& object); + static Value LivestatusThreadsAccessor(const Object::Ptr& object); }; }