Module: check_mk
Branch: master
Commit: 7b62855f7817216263cd04f535df53b7d3044ef3
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7b62855f781721…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Aug 16 16:54:20 2011 +0200
Livestatus: tried to fix timeperiod problem
---
livestatus/src/TimeperiodsCache.cc | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/livestatus/src/TimeperiodsCache.cc b/livestatus/src/TimeperiodsCache.cc
index 96007ec..b00815a 100644
--- a/livestatus/src/TimeperiodsCache.cc
+++ b/livestatus/src/TimeperiodsCache.cc
@@ -56,11 +56,13 @@ void TimeperiodsCache::update(time_t now)
return;
}
- _cache_time = minutes;
-
// Loop over all timeperiods and compute if we are
- // currently in
+ // currently in. Detect the case where no time periods
+ // are known (yet!). This might be the case when a timed
+ // event broker message arrives *before* the start of the
+ // event loop.
timeperiod *tp = timeperiod_list;
+ int num_periods = 0;
while (tp) {
bool is_in = 0 == check_time_against_period(now, tp);
@@ -76,7 +78,13 @@ void TimeperiodsCache::update(time_t now)
}
tp = tp->next;
+ num_periods++;
}
+ if (num_periods > 0)
+ _cache_time = minutes;
+ else
+ logger(LG_INFO, "Timeperiod cache not updated, there are no timeperiods (yet)");
+
pthread_mutex_unlock(&_cache_lock);
}
Module: check_mk
Branch: master
Commit: 9b0a27252143050f529f12bcf3cd522a4cc49dbf
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9b0a2725214305…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Aug 16 11:36:46 2011 +0200
Livestatus: new column contact_groups in hosts and services
thanks to a patch of Matthew Kent
---
ChangeLog | 2 +
livestatus/src/ContactgroupsColumn.cc | 84 +++++++++++++++++++++++++++++++++
livestatus/src/ContactgroupsColumn.h | 51 ++++++++++++++++++++
livestatus/src/Makefile.am | 3 +-
livestatus/src/TableHosts.cc | 3 +
livestatus/src/TableServices.cc | 3 +
6 files changed, 145 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4a6c8bd..feccecc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -108,6 +108,8 @@
* FIX: fix compile problem on Debian unstable (Thanks to Sven Velt)
* Column aggregation (Stats) now also works for perf_data
* New configuration variable data_encoding and full UTF-8 support.
+ * New column contact_groups in table hosts and services (thanks to
+ Matthew Kent)
1.1.11i1:
Core, Setup, etc.:
diff --git a/livestatus/src/ContactgroupsColumn.cc b/livestatus/src/ContactgroupsColumn.cc
new file mode 100644
index 0000000..0c68ac4
--- /dev/null
+++ b/livestatus/src/ContactgroupsColumn.cc
@@ -0,0 +1,84 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2010 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 "ContactgroupsColumn.h"
+#include "nagios.h"
+#include "Query.h"
+
+contactgroupsmember *ContactgroupsColumn::getData(void *data)
+{
+ if (data) {
+ data = shiftPointer(data);
+ if (data)
+ return *(contactgroupsmember **)((char *)data + _offset);
+ }
+ return 0;
+}
+
+void ContactgroupsColumn::output(void *data, Query *query)
+{
+ query->outputBeginList();
+ contactgroupsmember *cgm = getData(data);
+ if (cgm) {
+ bool first = true;
+ while (cgm) {
+ contactgroup *cg = (contactgroup *)cgm->group_ptr;
+ if (!first)
+ query->outputListSeparator();
+ else
+ first = false;
+ query->outputString(cg->group_name);
+ cgm = cgm->next;
+ }
+ }
+ query->outputEndList();
+}
+
+void *ContactgroupsColumn::getNagiosObject(char *name)
+{
+ return find_contactgroup(name);
+}
+
+bool ContactgroupsColumn::isNagiosMember(void *data, void *nagobject)
+{
+ if (!nagobject || !data)
+ return false;
+
+ // data is already shifted (_indirect_offset is taken into account)
+ // But _offset needs still to be accounted for
+ contactgroupsmember *cgm = *(contactgroupsmember **)((char *)data + _offset);
+
+ while (cgm) {
+ if (cgm->group_ptr == nagobject)
+ return true;
+ cgm = cgm->next;
+ }
+ return false;
+}
+
+bool ContactgroupsColumn::isEmpty(void *data)
+{
+ contactgroupsmember *cgm = *(contactgroupsmember **)((char *)data + _offset);
+ return cgm == 0;
+}
diff --git a/livestatus/src/ContactgroupsColumn.h b/livestatus/src/ContactgroupsColumn.h
new file mode 100644
index 0000000..96aacc2
--- /dev/null
+++ b/livestatus/src/ContactgroupsColumn.h
@@ -0,0 +1,51 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2010 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 ContactgroupsColumn_h
+#define ContactgroupsColumn_h
+
+#include "config.h"
+
+#include "ListColumn.h"
+#include "nagios.h"
+
+class ContactgroupsColumn : public ListColumn
+{
+ int _offset;
+public:
+ ContactgroupsColumn(string name, string description, int offset, int indirect_offset)
+ : ListColumn(name, description, indirect_offset), _offset(offset) {}
+ int type() { return COLTYPE_LIST; }
+ void output(void *, Query *);
+ void *getNagiosObject(char *name); // return pointer to contact group
+ bool isNagiosMember(void *data, void *nagobject);
+ bool isEmpty(void *data);
+private:
+ contactgroupsmember *getData(void *);
+};
+
+
+
+#endif // ContactgroupsColumn_h
+
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index 9c38a67..c0117dc 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -46,7 +46,8 @@ livestatus_so_SOURCES = \
ContactgroupsMemberColumn.cc OffsetStringMacroColumn.cc OffsetStringServiceMacroColumn.cc \
OffsetStringHostMacroColumn.cc StatsColumn.cc IntAggregator.cc CountAggregator.cc \
DoubleAggregator.cc AttributelistColumn.cc AttributelistFilter.cc \
- global_counters.c module.c logger.c waittriggers.c TimeperiodsCache.cc pnp4nagios.cc
+ global_counters.c module.c logger.c waittriggers.c TimeperiodsCache.cc pnp4nagios.cc \
+ ContactgroupsColumn.cc
livestatus_so_CXXFLAGS = -I$(top_srcdir)/nagios -fPIC
livestatus_so_CFLAGS = $(livestatus_so_CXXFLAGS)
diff --git a/livestatus/src/TableHosts.cc b/livestatus/src/TableHosts.cc
index 3af4998..0241aab 100644
--- a/livestatus/src/TableHosts.cc
+++ b/livestatus/src/TableHosts.cc
@@ -42,6 +42,7 @@
#include "ServicelistColumn.h"
#include "ServicelistStateColumn.h"
#include "HostgroupsColumn.h"
+#include "ContactgroupsColumn.h"
#include "HostSpecialIntColumn.h"
#include "tables.h"
@@ -298,6 +299,8 @@ void TableHosts::addColumns(Table *table, string prefix, int 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",
+ "A list of all contact groups this host is in", (char *)(&hst.contact_groups) - ref, indirect_offset));
table->addColumn(new ServicelistColumn(prefix + "services",
"A list of all services of the host", (char *)(&hst.services) - ref, indirect_offset, false, 0));
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index 2eb5cfd..05993ba 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -41,6 +41,7 @@
#include "DownCommColumn.h"
#include "CustomVarsColumn.h"
#include "ServicegroupsColumn.h"
+#include "ContactgroupsColumn.h"
#include "tables.h"
#include "auth.h"
#include "strutil.h"
@@ -366,6 +367,8 @@ void TableServices::addColumns(Table *table, string prefix, int indirect_offset,
table->addColumn(new ServicegroupsColumn(prefix + "groups",
"A list of all service groups the service is in", (char *)(&svc.servicegroups_ptr) - ref, indirect_offset));
+ table->addColumn(new ContactgroupsColumn(prefix + "contact_groups",
+ "A list of all contact groups this service is in", (char *)(&svc.contact_groups) - ref, indirect_offset));
}