diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp index 2ad7c0eb9..8a146e3b4 100644 --- a/components/livestatus/hoststable.cpp +++ b/components/livestatus/hoststable.cpp @@ -150,6 +150,7 @@ void HostsTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "num_services_hard_unknown", Column(&HostsTable::NumServicesHardUnknownAccessor, objectAccessor)); table->AddColumn(prefix + "hard_state", Column(&HostsTable::HardStateAccessor, objectAccessor)); table->AddColumn(prefix + "pnpgraph_present", Column(&HostsTable::PnpgraphPresentAccessor, objectAccessor)); + table->AddColumn(prefix + "staleness", Column(&HostsTable::StalenessAccessor, objectAccessor)); table->AddColumn(prefix + "groups", Column(&HostsTable::GroupsAccessor, objectAccessor)); table->AddColumn(prefix + "contact_groups", Column(&HostsTable::ContactGroupsAccessor, objectAccessor)); table->AddColumn(prefix + "services", Column(&HostsTable::ServicesAccessor, objectAccessor)); @@ -1563,7 +1564,15 @@ Value HostsTable::PnpgraphPresentAccessor(const Value& row) Value HostsTable::StalenessAccessor(const Value& row) { - /* TODO time since last check normalized on the check_interval */ + /* use hostcheck service */ + Service::Ptr hc = static_cast(row)->GetHostCheckService(); + + if (!hc) + return Empty; + + if (hc->HasBeenChecked() && hc->GetLastCheck() > 0) + return (Utility::GetTime() - hc->GetLastCheck()) / (hc->GetCheckInterval() * 3600); + return Empty; } diff --git a/components/livestatus/servicestable.cpp b/components/livestatus/servicestable.cpp index 5a499f190..c384f4313 100644 --- a/components/livestatus/servicestable.cpp +++ b/components/livestatus/servicestable.cpp @@ -100,6 +100,7 @@ void ServicesTable::AddColumns(Table *table, const String& prefix, table->AddColumn(prefix + "modified_attributes", Column(&ServicesTable::ModifiedAttributesAccessor, objectAccessor)); table->AddColumn(prefix + "modified_attributes_list", Column(&ServicesTable::ModifiedAttributesListAccessor, objectAccessor)); table->AddColumn(prefix + "pnpgraph_present", Column(&ServicesTable::PnpgraphPresentAccessor, objectAccessor)); + table->AddColumn(prefix + "staleness", Column(&ServicesTable::StalenessAccessor, objectAccessor)); table->AddColumn(prefix + "check_interval", Column(&ServicesTable::CheckIntervalAccessor, objectAccessor)); table->AddColumn(prefix + "retry_interval", Column(&ServicesTable::RetryIntervalAccessor, objectAccessor)); table->AddColumn(prefix + "notification_interval", Column(&ServicesTable::NotificationIntervalAccessor, objectAccessor)); @@ -650,6 +651,16 @@ Value ServicesTable::PnpgraphPresentAccessor(const Value& row) return Empty; } +Value ServicesTable::StalenessAccessor(const Value& row) +{ + Service::Ptr service = static_cast(row); + + if (service->HasBeenChecked() && service->GetLastCheck() > 0) + return (Utility::GetTime() - service->GetLastCheck()) / (service->GetCheckInterval() * 3600); + + return Empty; +} + Value ServicesTable::CheckIntervalAccessor(const Value& row) { return (static_cast(row)->GetCheckInterval() / 60.0); diff --git a/components/livestatus/servicestable.h b/components/livestatus/servicestable.h index 53f6135a7..618367987 100644 --- a/components/livestatus/servicestable.h +++ b/components/livestatus/servicestable.h @@ -105,6 +105,7 @@ protected: static Value ModifiedAttributesAccessor(const Value& row); static Value ModifiedAttributesListAccessor(const Value& row); static Value PnpgraphPresentAccessor(const Value& row); + static Value StalenessAccessor(const Value& row); static Value CheckIntervalAccessor(const Value& row); static Value RetryIntervalAccessor(const Value& row); static Value NotificationIntervalAccessor(const Value& row);