diff --git a/components/compat/statusdatawriter.cpp b/components/compat/statusdatawriter.cpp index fda98fe4b..e84b87980 100644 --- a/components/compat/statusdatawriter.cpp +++ b/components/compat/statusdatawriter.cpp @@ -394,7 +394,8 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl "\t" "last_notification=" << CompatUtility::GetCheckableNotificationLastNotification(checkable) << "\n" "\t" "next_notification=" << CompatUtility::GetCheckableNotificationNextNotification(checkable) << "\n" "\t" "current_notification_number=" << CompatUtility::GetCheckableNotificationNotificationNumber(checkable) << "\n" - "\t" "modified_attributes=" << checkable->GetModifiedAttributes() << "\n"; + "\t" "modified_attributes=" << checkable->GetModifiedAttributes() << "\n" + "\t" "is_reachable=" << CompatUtility::GetCheckableIsReachable(checkable) << "\n"; } void StatusDataWriter::DumpServiceStatus(std::ostream& fp, const Service::Ptr& service) diff --git a/components/db_ido_mysql/schema/mysql.sql b/components/db_ido_mysql/schema/mysql.sql index a462e2a55..bf97f3138 100644 --- a/components/db_ido_mysql/schema/mysql.sql +++ b/components/db_ido_mysql/schema/mysql.sql @@ -747,6 +747,7 @@ CREATE TABLE IF NOT EXISTS icinga_hoststatus ( normal_check_interval double default '0', retry_check_interval double default '0', check_timeperiod_object_id bigint unsigned default 0, + is_reachable smallint default 0, PRIMARY KEY (hoststatus_id), UNIQUE KEY object_id (host_object_id) ) ENGINE=InnoDB COMMENT='Current host status information'; @@ -1230,6 +1231,7 @@ CREATE TABLE IF NOT EXISTS icinga_servicestatus ( normal_check_interval double default '0', retry_check_interval double default '0', check_timeperiod_object_id bigint unsigned default 0, + is_reachable smallint default 0, PRIMARY KEY (servicestatus_id), UNIQUE KEY object_id (service_object_id) ) ENGINE=InnoDB COMMENT='Current service status information'; @@ -1404,7 +1406,6 @@ 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) @@ -1599,6 +1600,6 @@ CREATE INDEX commenthistory_delete_idx ON icinga_commenthistory (instance_id, co -- ----------------------------------------- -- set dbversion -- ----------------------------------------- -INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.11.0', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.11.0', modify_time=NOW(); +INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.11.3', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.11.3', modify_time=NOW(); diff --git a/components/db_ido_mysql/schema/upgrade/0.0.11.sql b/components/db_ido_mysql/schema/upgrade/0.0.11.sql new file mode 100644 index 000000000..49c7cfe7a --- /dev/null +++ b/components/db_ido_mysql/schema/upgrade/0.0.11.sql @@ -0,0 +1,13 @@ + + +-- ----------------------------------------- +-- #6094 +-- ----------------------------------------- + +ALTER TABLE icinga_hoststatus ADD COLUMN is_reachable smallint(6) DEFAULT NULL; +ALTER TABLE icinga_servicestatus ADD COLUMN is_reachable smallint(6) DEFAULT NULL; + +-- ----------------------------------------- +-- set dbversion +-- ----------------------------------------- +INSERT INTO icinga_dbversion (name, version, create_time, modify_time) VALUES ('idoutils', '1.11.3', NOW(), NOW()) ON DUPLICATE KEY UPDATE version='1.11.3', modify_time=NOW(); diff --git a/components/db_ido_pgsql/schema/pgsql.sql b/components/db_ido_pgsql/schema/pgsql.sql index f568ca8cc..dd1789f8a 100644 --- a/components/db_ido_pgsql/schema/pgsql.sql +++ b/components/db_ido_pgsql/schema/pgsql.sql @@ -773,6 +773,7 @@ CREATE TABLE icinga_hoststatus ( normal_check_interval double precision default 0, retry_check_interval double precision default 0, check_timeperiod_object_id bigint default 0, + is_reachable INTEGER default 0, CONSTRAINT PK_hoststatus_id PRIMARY KEY (hoststatus_id) , CONSTRAINT UQ_hoststatus UNIQUE (host_object_id) ) ; @@ -1256,6 +1257,7 @@ CREATE TABLE icinga_servicestatus ( normal_check_interval double precision default 0, retry_check_interval double precision default 0, check_timeperiod_object_id bigint default 0, + is_reachable INTEGER default 0, CONSTRAINT PK_servicestatus_id PRIMARY KEY (servicestatus_id) , CONSTRAINT UQ_servicestatus UNIQUE (service_object_id) ) ; @@ -1432,7 +1434,6 @@ 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) @@ -1628,5 +1629,5 @@ CREATE INDEX commenthistory_delete_idx ON icinga_commenthistory (instance_id, co -- set dbversion -- ----------------------------------------- -SELECT updatedbversion('1.11.0'); +SELECT updatedbversion('1.11.3'); diff --git a/components/db_ido_pgsql/schema/upgrade/0.0.11.sql b/components/db_ido_pgsql/schema/upgrade/0.0.11.sql new file mode 100644 index 000000000..d27fed37a --- /dev/null +++ b/components/db_ido_pgsql/schema/upgrade/0.0.11.sql @@ -0,0 +1,14 @@ + + +-- ----------------------------------------- +-- #6094 +-- ----------------------------------------- + +ALTER TABLE icinga_hoststatus ADD COLUMN is_reachable INTEGER default 0; +ALTER TABLE icinga_servicestatus ADD COLUMN is_reachable INTEGER default 0; + +-- ----------------------------------------- +-- set dbversion +-- ----------------------------------------- + +SELECT updatedbversion('1.11.3'); diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 4d619c6e7..679cb0bfc 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 + "is_reachable", Column(&HostsTable::IsReachableAccessor, objectAccessor)); } String HostsTable::GetName(void) const @@ -1481,3 +1482,13 @@ Value HostsTable::ServicesWithInfoAccessor(const Value& row) return services; } + +Value HostsTable::IsReachableAccessor(const Value& row) +{ + Host::Ptr host = static_cast(row); + + if (!host) + return Empty; + + return host->IsReachable(); +} diff --git a/components/livestatus/hoststable.h b/components/livestatus/hoststable.h index 1c821c2df..047e05476 100644 --- a/components/livestatus/hoststable.h +++ b/components/livestatus/hoststable.h @@ -140,6 +140,7 @@ protected: static Value ServicesAccessor(const Value& row); static Value ServicesWithStateAccessor(const Value& row); static Value ServicesWithInfoAccessor(const Value& row); + static Value IsReachableAccessor(const Value& row); }; } diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 037850852..98c32106a 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -127,6 +127,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "groups", Column(&ServicesTable::GroupsAccessor, objectAccessor)); table->AddColumn(prefix + "contact_groups", Column(&ServicesTable::ContactGroupsAccessor, objectAccessor)); table->AddColumn(prefix + "check_source", Column(&ServicesTable::CheckSourceAccessor, objectAccessor)); + table->AddColumn(prefix + "is_reachable", Column(&ServicesTable::IsReachableAccessor, objectAccessor)); HostsTable::AddColumns(table, "host_", boost::bind(&ServicesTable::HostAccessor, _1, objectAccessor)); } @@ -1167,4 +1168,12 @@ Value ServicesTable::CheckSourceAccessor(const Value& row) return Empty; } +Value ServicesTable::IsReachableAccessor(const Value& row) +{ + Service::Ptr service = static_cast(row); + if (!service) + return Empty; + + return service->IsReachable(); +} diff --git a/components/livestatus/servicestable.h b/components/livestatus/servicestable.h index 2ef22f3cc..4662628bf 100644 --- a/components/livestatus/servicestable.h +++ b/components/livestatus/servicestable.h @@ -124,6 +124,7 @@ protected: static Value GroupsAccessor(const Value& row); static Value ContactGroupsAccessor(const Value& row); static Value CheckSourceAccessor(const Value& row); + static Value IsReachableAccessor(const Value& row); }; } diff --git a/doc/9-appendix.md b/doc/9-appendix.md index 2b58b07c8..92d713ff4 100644 --- a/doc/9-appendix.md +++ b/doc/9-appendix.md @@ -488,6 +488,8 @@ New columns: Table | Column ----------|-------------- + hosts | is_reachable + services | is_reachable services | check_source downtimes | triggers downtimes | trigger_time diff --git a/lib/db_ido/hostdbobject.cpp b/lib/db_ido/hostdbobject.cpp index 9b88bc6b5..6fd0cfb67 100644 --- a/lib/db_ido/hostdbobject.cpp +++ b/lib/db_ido/hostdbobject.cpp @@ -167,6 +167,7 @@ Dictionary::Ptr HostDbObject::GetStatusFields(void) const fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(host)); fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(host)); fields->Set("check_timeperiod_object_id", host->GetCheckPeriod()); + fields->Set("is_reachable", CompatUtility::GetCheckableIsReachable(host)); return fields; } diff --git a/lib/db_ido/servicedbobject.cpp b/lib/db_ido/servicedbobject.cpp index 7b3434807..68946b2a9 100644 --- a/lib/db_ido/servicedbobject.cpp +++ b/lib/db_ido/servicedbobject.cpp @@ -161,6 +161,7 @@ Dictionary::Ptr ServiceDbObject::GetStatusFields(void) const fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(service)); fields->Set("check_timeperiod_object_id", service->GetCheckPeriod()); fields->Set("modified_service_attributes", service->GetModifiedAttributes()); + fields->Set("is_reachable", CompatUtility::GetCheckableIsReachable(service)); return fields; } diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index eac272aa2..218a4fcbc 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -216,6 +216,11 @@ int CompatUtility::GetCheckableIsFlapping(const Checkable::Ptr& checkable) return (checkable->IsFlapping() ? 1 : 0); } +int CompatUtility::GetCheckableIsReachable(const Checkable::Ptr& checkable) +{ + return (checkable->IsReachable() ? 1 : 0); +} + String CompatUtility::GetCheckablePercentStateChange(const Checkable::Ptr& checkable) { return Convert::ToString(checkable->GetFlappingCurrent()); diff --git a/lib/icinga/compatutility.h b/lib/icinga/compatutility.h index f7b6e7d13..f51e845cf 100644 --- a/lib/icinga/compatutility.h +++ b/lib/icinga/compatutility.h @@ -59,6 +59,7 @@ public: static int GetCheckableEventHandlerEnabled(const Checkable::Ptr& checkable); static int GetCheckableFlapDetectionEnabled(const Checkable::Ptr& checkable); static int GetCheckableIsFlapping(const Checkable::Ptr& checkable); + static int GetCheckableIsReachable(const Checkable::Ptr& checkable); static String GetCheckablePercentStateChange(const Checkable::Ptr& checkable); static int GetCheckableProcessPerformanceData(const Checkable::Ptr& checkable); diff --git a/test/livestatus/queries/host/state b/test/livestatus/queries/host/state index 0eff60449..ba59c9e92 100644 --- a/test/livestatus/queries/host/state +++ b/test/livestatus/queries/host/state @@ -1,4 +1,4 @@ GET hosts -Columns: name last_state_change last_hard_state_change last_time_up last_time_down last_time_unreachable staleness +Columns: name last_state_change last_hard_state_change last_time_up last_time_down last_time_unreachable staleness is_reachable ResponseHeader: fixed16 diff --git a/test/livestatus/queries/service/state b/test/livestatus/queries/service/state index ecc448590..65bf5f70d 100644 --- a/test/livestatus/queries/service/state +++ b/test/livestatus/queries/service/state @@ -1,4 +1,4 @@ GET services -Columns: description host_name last_state_change last_hard_state_change last_time_ok last_time_warning last_time_critical last_time_unknown staleness +Columns: description host_name last_state_change last_hard_state_change last_time_ok last_time_warning last_time_critical last_time_unknown staleness is_reachable ResponseHeader: fixed16