From: Michael Friedrich Date: Sat, 10 May 2014 18:37:09 +0000 (+0200) Subject: Livestatus: Add 'is_reachable' to hosts/services table. X-Git-Tag: v0.0.11~41^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=97d51c42691cb061cda973de515db29adf71611f;p=icinga2 Livestatus: Add 'is_reachable' to hosts/services table. Refs #6094 --- 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/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