Module: check_mk
Branch: master
Commit: 2715f1b9d5d6dd31d9e2c1026111bdd15c5903cb
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2715f1b9d5d6dd…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Jun 27 17:42:41 2013 +0200
livestatus: staleness for hosts
---
ChangeLog | 3 +-
livestatus/src/HostSpecialDoubleColumn.cc | 44 ++++++++++++++++++++++++++
livestatus/src/HostSpecialDoubleColumn.h | 44 ++++++++++++++++++++++++++
livestatus/src/Makefile.am | 2 +-
livestatus/src/ServiceSpecialDoubleColumn.cc | 1 -
livestatus/src/TableHosts.cc | 4 +++
6 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index bcd44af..644e5e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,7 +11,8 @@
* Predictive monitoring: correctly handle spaces in variable names (thanks
to Karl Golland)
* New man page browser for console (cmk -m)
- * livestatus: new service column staleness: indicator outdated service checks
+ * livestatus: new service column staleness: indicator for outdated service checks
+ * livestatus: new host column staleness: indicator for outdated host checks
Checks & Agents:
* esx_hostystem multipath: criticize standby paths only if not equal to active paths
diff --git a/livestatus/src/HostSpecialDoubleColumn.cc
b/livestatus/src/HostSpecialDoubleColumn.cc
new file mode 100644
index 0000000..37b127d
--- /dev/null
+++ b/livestatus/src/HostSpecialDoubleColumn.cc
@@ -0,0 +1,44 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+// +------------------------------------------------------------------+
+//
+// This file is part of Check_MK.
+// The official homepage is at
http://mathias-kettner.de/check_mk.
+//
+// check_mk is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation in version 2. check_mk is distributed
+// in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+// out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+// PARTICULAR PURPOSE. See the GNU General Public License for more de-
+// ails. You should have received a copy of the GNU General Public
+// License along with GNU Make; see the file COPYING. If not, write
+// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+#include "HostSpecialDoubleColumn.h"
+#include "nagios.h"
+#include "logger.h"
+#include "time.h"
+
+double HostSpecialDoubleColumn::getValue(void *data)
+{
+ data = shiftPointer(data);
+ if (!data) return 0;
+
+ host *hst = (host *)data;
+
+ switch (_type) {
+ case HSDC_STALENESS:
+ {
+ return (time(0) - hst->last_check) / ((hst->check_interval == 0 ? 1 :
hst->check_interval) * 60);
+ }
+ }
+ return -1; // Never reached
+}
diff --git a/livestatus/src/HostSpecialDoubleColumn.h
b/livestatus/src/HostSpecialDoubleColumn.h
new file mode 100644
index 0000000..8e7ba20
--- /dev/null
+++ b/livestatus/src/HostSpecialDoubleColumn.h
@@ -0,0 +1,44 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+// +------------------------------------------------------------------+
+//
+// This file is part of Check_MK.
+// The official homepage is at
http://mathias-kettner.de/check_mk.
+//
+// check_mk is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation in version 2. check_mk is distributed
+// in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+// out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+// PARTICULAR PURPOSE. See the GNU General Public License for more de-
+// ails. You should have received a copy of the GNU General Public
+// License along with GNU Make; see the file COPYING. If not, write
+// to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+// Boston, MA 02110-1301 USA.
+
+#ifndef ServiceSpecialDoubleColumn_h
+#define ServiceSpecialDoubleColumn_h
+
+#include "config.h"
+#include "DoubleColumn.h"
+
+#define HSDC_STALENESS 1
+
+class HostSpecialDoubleColumn : public DoubleColumn
+{
+ int _type;
+
+public:
+ HostSpecialDoubleColumn(string name, string description, int hsdc_type, int
indirect)
+ : DoubleColumn(name, description, indirect) , _type(hsdc_type) {}
+ double getValue(void *data);
+};
+
+#endif // ServiceSpecialDoubleColumn_h
+
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index 24d8f0a..1cba24b 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -43,7 +43,7 @@ livestatus_so_SOURCES = \
Query.cc ServiceContactsColumn.cc ServicegroupsColumn.cc ServicelistColumn.cc \
ServicelistColumnFilter.cc ServicelistStateColumn.cc store.cc Store.cc \
StringColumn.cc StringColumnFilter.cc strutil.cc Table.cc TableColumns.cc \
- TableCommands.cc TableContacts.cc TableDownComm.cc TableHostgroups.cc \
+ HostSpecialDoubleColumn.cc TableCommands.cc TableContacts.cc TableDownComm.cc
TableHostgroups.cc \
ServiceSpecialDoubleColumn.cc TableHosts.cc TableServicegroups.cc TableServices.cc
TableStatus.cc \
LogEntry.cc LogCache.cc Logfile.cc TableStateHistory.cc TableLog.cc TableTimeperiods.cc
TableContactgroups.cc \
ContactgroupsMemberColumn.cc OffsetStringMacroColumn.cc
OffsetStringServiceMacroColumn.cc \
diff --git a/livestatus/src/ServiceSpecialDoubleColumn.cc
b/livestatus/src/ServiceSpecialDoubleColumn.cc
index 46ae447..3e135c8 100644
--- a/livestatus/src/ServiceSpecialDoubleColumn.cc
+++ b/livestatus/src/ServiceSpecialDoubleColumn.cc
@@ -36,7 +36,6 @@ double ServiceSpecialDoubleColumn::getValue(void *data)
switch (_type) {
case SSDC_STALENESS:
{
- time_t last_check = svc->last_check;
bool is_cmk_passive = !strncmp(svc->check_command_ptr->name,
"check_mk-", 9);
time_t check_result_age = time(0) - svc->last_check;
diff --git a/livestatus/src/TableHosts.cc b/livestatus/src/TableHosts.cc
index 51a6a04..8539abd 100644
--- a/livestatus/src/TableHosts.cc
+++ b/livestatus/src/TableHosts.cc
@@ -44,6 +44,7 @@
#include "HostgroupsColumn.h"
#include "ContactgroupsColumn.h"
#include "HostSpecialIntColumn.h"
+#include "HostSpecialDoubleColumn.h"
#include "tables.h"
#include "auth.h"
@@ -301,6 +302,9 @@ void TableHosts::addColumns(Table *table, string prefix, int
indirect_offset)
table->addColumn(new HostSpecialIntColumn(prefix + "pnpgraph_present",
"Whether there is a PNP4Nagios graph present for this host
(0/1)", HSIC_PNP_GRAPH_PRESENT, indirect_offset));
+ table->addColumn(new HostSpecialDoubleColumn(prefix + "staleness",
+ "Staleness indicator for this host", HSDC_STALENESS,
indirect_offset));
+
table->addColumn(new HostgroupsColumn(prefix + "groups",
"A list of all host groups this host is in", (char
*)(&hst.hostgroups_ptr) - ref, indirect_offset));
table->addColumn(new ContactgroupsColumn(prefix + "contact_groups",