From 23c47dd430eed2dd7e75413a8da61ffe193abb2e Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 21 Mar 2014 17:57:24 +0100 Subject: [PATCH] Make host 'check' attribute available in legacy interfaces. Fixes #5764 --- components/compat/statusdatawriter.cpp | 5 +++- components/db_ido_mysql/schema/mysql.sql | 1 + .../db_ido_mysql/schema/upgrade/0.0.9.sql | 2 ++ components/db_ido_pgsql/schema/pgsql.sql | 1 + .../db_ido_pgsql/schema/upgrade/0.0.9.sql | 2 ++ components/livestatus/hoststable.cpp | 18 +++++++++++++ components/livestatus/hoststable.h | 2 +- doc/6.12-schemas.md | 25 +++++++++++++------ lib/db_ido/hostdbobject.cpp | 1 + test/livestatus/queries/host/host | 2 +- 10 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 components/db_ido_mysql/schema/upgrade/0.0.9.sql create mode 100644 components/db_ido_pgsql/schema/upgrade/0.0.9.sql diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index c61b55dbe..a786ab50a 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -207,8 +207,11 @@ void StatusDataWriter::DumpHostStatus(std::ostream& fp, const Host::Ptr& host) Service::Ptr hc = host->GetCheckService(); ObjectLock olock(hc); - if (hc) + if (hc) { + /* only dump status data information for Classic UI */ + fp << "\t" "check_service=" << hc->GetShortName() << "\n"; DumpServiceStatusAttrs(fp, hc, CompatTypeHost); + } /* ugly but cgis parse only that */ fp << "\t" "last_time_up=" << host->GetLastStateUp() << "\n" diff --git a/components/db_ido_mysql/schema/mysql.sql b/components/db_ido_mysql/schema/mysql.sql index 080898dcd..724b1dddb 100644 --- a/components/db_ido_mysql/schema/mysql.sql +++ b/components/db_ido_mysql/schema/mysql.sql @@ -1398,6 +1398,7 @@ ALTER TABLE icinga_servicechecks ADD COLUMN endpoint_object_id bigint default NU ALTER TABLE icinga_statehistory ADD COLUMN endpoint_object_id bigint default NULL; ALTER TABLE icinga_systemcommands ADD COLUMN endpoint_object_id bigint default NULL; +ALTER TABLE icinga_hosts ADD COLUMN check_service_object_id bigint default NULL; -- ----------------------------------------- -- add index (delete) diff --git a/components/db_ido_mysql/schema/upgrade/0.0.9.sql b/components/db_ido_mysql/schema/upgrade/0.0.9.sql new file mode 100644 index 000000000..d0fa61510 --- /dev/null +++ b/components/db_ido_mysql/schema/upgrade/0.0.9.sql @@ -0,0 +1,2 @@ + +ALTER TABLE icinga_hosts ADD COLUMN check_service_object_id bigint default NULL; diff --git a/components/db_ido_pgsql/schema/pgsql.sql b/components/db_ido_pgsql/schema/pgsql.sql index c30e9e50d..88bed2839 100644 --- a/components/db_ido_pgsql/schema/pgsql.sql +++ b/components/db_ido_pgsql/schema/pgsql.sql @@ -1426,6 +1426,7 @@ ALTER TABLE icinga_servicechecks ADD COLUMN endpoint_object_id bigint default NU ALTER TABLE icinga_statehistory ADD COLUMN endpoint_object_id bigint default NULL; ALTER TABLE icinga_systemcommands ADD COLUMN endpoint_object_id bigint default NULL; +ALTER TABLE icinga_hosts ADD COLUMN check_service_object_id bigint default NULL; -- ----------------------------------------- -- add index (delete) diff --git a/components/db_ido_pgsql/schema/upgrade/0.0.9.sql b/components/db_ido_pgsql/schema/upgrade/0.0.9.sql new file mode 100644 index 000000000..d0fa61510 --- /dev/null +++ b/components/db_ido_pgsql/schema/upgrade/0.0.9.sql @@ -0,0 +1,2 @@ + +ALTER TABLE icinga_hosts ADD COLUMN check_service_object_id bigint default NULL; diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index e5d5d5a8c..8f3ecc738 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -157,6 +157,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "services", Column(&HostsTable::ServicesAccessor, objectAccessor)); table->AddColumn(prefix + "services_with_state", Column(&HostsTable::ServicesWithStateAccessor, objectAccessor)); table->AddColumn(prefix + "services_with_info", Column(&HostsTable::ServicesWithInfoAccessor, objectAccessor)); + table->AddColumn(prefix + "check_service", Column(&HostsTable::CheckServiceAccessor, objectAccessor)); } String HostsTable::GetName(void) const @@ -1854,3 +1855,20 @@ Value HostsTable::ServicesWithInfoAccessor(const Value& row) return services; } +Value HostsTable::CheckServiceAccessor(const Value& row) +{ + Host::Ptr host = static_cast(row); + + if (!host) + return Empty; + + Service::Ptr hc = host->GetCheckService(); + + Array::Ptr services = make_shared(); + + if (!hc) + return Empty; + + return hc->GetShortName(); +} + diff --git a/components/livestatus/hoststable.h b/components/livestatus/hoststable.h index 77cfc4ee1..8ce1520e5 100644 --- a/components/livestatus/hoststable.h +++ b/components/livestatus/hoststable.h @@ -141,9 +141,9 @@ protected: static Value GroupsAccessor(const Value& row); static Value ContactGroupsAccessor(const Value& row); static Value ServicesAccessor(const Value& row); - static Value ServicesWithStateAccessor(const Value& row); static Value ServicesWithInfoAccessor(const Value& row); + static Value CheckServiceAccessor(const Value& row); }; } diff --git a/doc/6.12-schemas.md b/doc/6.12-schemas.md index 425957af5..ecc9ead6a 100644 --- a/doc/6.12-schemas.md +++ b/doc/6.12-schemas.md @@ -1,6 +1,15 @@ ## Schemas +### Status Data + +Changes require newest Icinga Classic UI releases. + + Object | Key + ------------|-------------- + hoststatus | check_service + + ### DB IDO There is a detailed documentation for the Icinga IDOUtils 1.x @@ -27,13 +36,14 @@ New tables: `endpoints`, `endpointstatus` New columns: - Table | Column | Type | Default | Description - --------------------|--------------------|----------|---------|------------- - all status/history | endpoint_object_id | bigint | NULL | FK: objects table - servicestatus | check_source | TEXT | NULL | node name where check was executed - hoststatus | check_source | TEXT | NULL | node name where check was executed - statehistory | check_source | TEXT | NULL | node name where check was executed - logentries | object_id | bigint | NULL | FK: objects table (service associated with column) + Table | Column | Type | Default | Description + --------------------|-------------------------|----------|---------|------------- + all status/history | endpoint_object_id | bigint | NULL | FK: objects table + servicestatus | check_source | TEXT | NULL | node name where check was executed + hoststatus | check_source | TEXT | NULL | node name where check was executed + statehistory | check_source | TEXT | NULL | node name where check was executed + logentries | object_id | bigint | NULL | FK: objects table (service associated with column) + hosts | check_service_object_id | bigint | NULL | FK: objects table (service associated with column) @@ -175,5 +185,6 @@ New columns: Table | Column ----------|-------------- services | check_source + hosts | check_service downtimes | triggers downtimes | trigger_time diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index a26a0b61c..2d8692378 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -51,6 +51,7 @@ Dictionary::Ptr HostDbObject::GetConfigFields(void) const fields->Set("address6", CompatUtility::GetHostAddress6(host)); if (service) { + fields->Set("check_service_object_id", service); fields->Set("check_command_object_id", service->GetCheckCommand()); fields->Set("check_command_args", Empty); fields->Set("eventhandler_command_object_id", service->GetEventCommand()); diff --git a/test/livestatus/queries/host/host b/test/livestatus/queries/host/host index 4390fa91d..c869598c5 100644 --- a/test/livestatus/queries/host/host +++ b/test/livestatus/queries/host/host @@ -1,4 +1,4 @@ GET hosts -Columns: name parents childs +Columns: name parents childs check_service ResponseHeader: fixed16