Module: check_mk
Branch: master
Commit: a9bf7fc1469cfd85146673988fa9dc6210126538
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a9bf7fc1469cfd…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Jun 27 17:17:02 2013 +0200
livestatus: new service column staleness: indicator outdated service checks
---
ChangeLog | 1 +
livestatus/src/Makefile.am | 2 +-
livestatus/src/ServiceSpecialDoubleColumn.cc | 67 ++++++++++++++++++++++++++
livestatus/src/ServiceSpecialDoubleColumn.h | 44 +++++++++++++++++
livestatus/src/TableServices.cc | 3 ++
5 files changed, 116 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 46fca92..bcd44af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,7 @@
* 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
Checks & Agents:
* esx_hostystem multipath: criticize standby paths only if not equal to active paths
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index e83ee51..24d8f0a 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -44,7 +44,7 @@ livestatus_so_SOURCES = \
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 \
- TableHosts.cc TableServicegroups.cc TableServices.cc TableStatus.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 \
OffsetStringHostMacroColumn.cc StatsColumn.cc IntAggregator.cc CountAggregator.cc \
diff --git a/livestatus/src/ServiceSpecialDoubleColumn.cc
b/livestatus/src/ServiceSpecialDoubleColumn.cc
new file mode 100644
index 0000000..46ae447
--- /dev/null
+++ b/livestatus/src/ServiceSpecialDoubleColumn.cc
@@ -0,0 +1,67 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | 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 "ServiceSpecialDoubleColumn.h"
+#include "nagios.h"
+#include "logger.h"
+#include "time.h"
+
+double ServiceSpecialDoubleColumn::getValue(void *data)
+{
+ data = shiftPointer(data);
+ if (!data) return 0;
+
+ service *svc = (service *)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;
+ service *tmp_svc;
+
+ // check_mk PASSIVE CHECK: Find check-mk service and get its check interval
+ if (is_cmk_passive) {
+ host *host = svc->host_ptr;
+ servicesmember *svc_member = host->services;
+ double check_interval = 1;
+ while (svc_member != 0) {
+ tmp_svc = svc_member->service_ptr;
+ if (!strncmp(tmp_svc->check_command_ptr->name, "check-mk", 9))
{
+ check_interval = tmp_svc->check_interval * 60;
+ return check_result_age / check_interval;
+ }
+ svc_member = svc_member->next;
+ }
+ return 1; // Shouldnt happen! We always except check-mk service
+ }
+ else // Other non-cmk passive and active checks
+ {
+ return check_result_age / ((svc->check_interval == 0 ? 1 :
svc->check_interval) * 60);
+ }
+ }
+ }
+ return -1; // Never reached
+}
diff --git a/livestatus/src/ServiceSpecialDoubleColumn.h
b/livestatus/src/ServiceSpecialDoubleColumn.h
new file mode 100644
index 0000000..668ca6e
--- /dev/null
+++ b/livestatus/src/ServiceSpecialDoubleColumn.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 SSDC_STALENESS 1
+
+class ServiceSpecialDoubleColumn : public DoubleColumn
+{
+ int _type;
+
+public:
+ ServiceSpecialDoubleColumn(string name, string description, int ssdc_type, int
indirect)
+ : DoubleColumn(name, description, indirect) , _type(ssdc_type) {}
+ double getValue(void *data);
+};
+
+#endif // ServiceSpecialDoubleColumn_h
+
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index b962816..111ad8f 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -33,6 +33,7 @@
#include "OffsetTimeperiodColumn.h"
#include "OffsetStringServiceMacroColumn.h"
#include "ServiceSpecialIntColumn.h"
+#include "ServiceSpecialDoubleColumn.h"
#include "AttributelistColumn.h"
#include "TableHosts.h"
#include "TableServicegroups.h"
@@ -308,6 +309,8 @@ void TableServices::addColumns(Table *table, string prefix, int
indirect_offset,
"A list of all modified attributes", (char
*)(&svc.modified_attributes) - ref, indirect_offset, true));
table->addColumn(new ServiceSpecialIntColumn(prefix +
"pnpgraph_present",
"Whether there is a PNP4Nagios graph present for this service
(0/1)", SSIC_PNP_GRAPH_PRESENT, indirect_offset));
+ table->addColumn(new ServiceSpecialDoubleColumn(prefix + "staleness",
+ "The staleness indicator for this service", SSDC_STALENESS,
indirect_offset));
// columns of type double
table->addColumn(new OffsetDoubleColumn(prefix + "check_interval",