From 7a4fa25a494cc11c6c09085d6f0f23cd3dbaada1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Sat, 10 May 2014 21:57:01 +0200 Subject: [PATCH] Livestatus: Add 'check_source' to hosts table. Fixes #6185 --- components/livestatus/hoststable.cpp | 16 ++++++++++++++++ components/livestatus/hoststable.h | 1 + doc/9-appendix.md | 1 + test/livestatus/queries/host/check | 4 ++++ 4 files changed, 22 insertions(+) create mode 100644 test/livestatus/queries/host/check diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 679cb0bfc..deb1c9efe 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_source", Column(&HostsTable::CheckSourceAccessor, objectAccessor)); table->AddColumn(prefix + "is_reachable", Column(&HostsTable::IsReachableAccessor, objectAccessor)); } @@ -1483,6 +1484,21 @@ Value HostsTable::ServicesWithInfoAccessor(const Value& row) return services; } +Value HostsTable::CheckSourceAccessor(const Value& row) +{ + Host::Ptr host = static_cast(row); + + if (!host) + return Empty; + + CheckResult::Ptr cr = host->GetLastCheckResult(); + + if (cr) + return cr->GetCheckSource(); + + return Empty; +} + Value HostsTable::IsReachableAccessor(const Value& row) { Host::Ptr host = static_cast(row); diff --git a/components/livestatus/hoststable.h b/components/livestatus/hoststable.h index 047e05476..dc5bddede 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 CheckSourceAccessor(const Value& row); static Value IsReachableAccessor(const Value& row); }; diff --git a/doc/9-appendix.md b/doc/9-appendix.md index 9c81c02c9..22582f089 100644 --- a/doc/9-appendix.md +++ b/doc/9-appendix.md @@ -505,6 +505,7 @@ New columns: ----------|-------------- hosts | is_reachable services | is_reachable + hosts | check_source services | check_source downtimes | triggers downtimes | trigger_time diff --git a/test/livestatus/queries/host/check b/test/livestatus/queries/host/check new file mode 100644 index 000000000..bf4c216e6 --- /dev/null +++ b/test/livestatus/queries/host/check @@ -0,0 +1,4 @@ +GET hosts +Columns: name plugin_output check_source +ResponseHeader: fixed16 +