[icinga-checkins] icinga.org: icinga2/master: livestatus: add host/ service staleness indicator

git at icinga.org git at icinga.org
Fri Jul 19 14:19:26 CEST 2013


Module: icinga2
Branch: master
Commit: a991fbe1b656b47eea17e5c9ea90634eab9ff225
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=a991fbe1b656b47eea17e5c9ea90634eab9ff225

Author: Michael Friedrich <michael.friedrich at netways.de>
Date:   Fri Jul 19 14:19:09 2013 +0200

livestatus: add host/service staleness indicator

refs #4372

---

 components/livestatus/hoststable.cpp    |   11 ++++++++++-
 components/livestatus/servicestable.cpp |   11 +++++++++++
 components/livestatus/servicestable.h   |    1 +
 3 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/components/livestatus/hoststable.cpp b/components/livestatus/hoststable.cpp
index 2ad7c0e..8a146e3 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<Host::Ptr>(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 5a499f1..c384f43 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<Service::Ptr>(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<Service::Ptr>(row)->GetCheckInterval() / 60.0);
diff --git a/components/livestatus/servicestable.h b/components/livestatus/servicestable.h
index 53f6135..6183679 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);





More information about the icinga-checkins mailing list