Module: check_mk
Branch: master
Commit: 68aa067ddced1910744330279877a59b118b4bae
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=68aa067ddced19…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Jun 26 15:17:48 2011 +0200
Livestatus: new hosts column filename
It returns the value of the custom variable _FILENAME
---
ChangeLog | 1 +
livestatus/src/CustomVarsExplicitColumn.cc | 44 ++++++++++++++++++++++++
livestatus/src/CustomVarsExplicitColumn.h | 50 ++++++++++++++++++++++++++++
livestatus/src/Makefile.am | 2 +-
livestatus/src/TableHosts.cc | 7 ++++
5 files changed, 103 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 92bd478..5e2d238 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -50,6 +50,7 @@
* Column aggregation (Stats) now also works for perf_data
* hosts, services & contacts: new column custom_variables (this is
a dictionary of all custom variables)
+ * new column 'filename' in table host (value of variable _FILENAME)
* Updated Python-API to most current version
1.1.11i1:
diff --git a/livestatus/src/CustomVarsExplicitColumn.cc b/livestatus/src/CustomVarsExplicitColumn.cc
new file mode 100644
index 0000000..80bd29a
--- /dev/null
+++ b/livestatus/src/CustomVarsExplicitColumn.cc
@@ -0,0 +1,44 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | 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 "CustomVarsExplicitColumn.h"
+
+char *CustomVarsExplicitColumn::getValue(void *data)
+{
+ customvariablesmember *cvm = getCVM(data);
+ while (cvm) {
+ if (cvm->variable_name == _varname)
+ return cvm->variable_value;
+ cvm = cvm->next;
+ }
+ return (char *)"";
+}
+
+customvariablesmember *CustomVarsExplicitColumn::getCVM(void *data)
+{
+ if (!data) return 0;
+ data = shiftPointer(data);
+ if (!data) return 0;
+ return *(customvariablesmember **)((char *)data + _offset);
+}
diff --git a/livestatus/src/CustomVarsExplicitColumn.h b/livestatus/src/CustomVarsExplicitColumn.h
new file mode 100644
index 0000000..3300195
--- /dev/null
+++ b/livestatus/src/CustomVarsExplicitColumn.h
@@ -0,0 +1,50 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | 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 CustomVarsExplicitColumn_h
+#define CustomVarsExplicitColumn_h
+
+#include "StringColumn.h"
+#include "nagios.h"
+
+using namespace std;
+
+
+class CustomVarsExplicitColumn : public StringColumn
+{
+ int _offset; // within data structure (differs from host/service)
+ std::string _varname;
+
+public:
+ CustomVarsExplicitColumn(string name, string description, int offset, int indirect_offset, char *varname)
+ : StringColumn(name, description, indirect_offset), _offset(offset), _varname(varname) {}
+ char *getValue(void *data);
+private:
+ customvariablesmember *getCVM(void *data);
+};
+
+
+#endif // CustomVarsExplicitColumn_h
+
+
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index abd1280..9c38a67 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -28,7 +28,7 @@ unixcat_LDADD = -lpthread
pkglib_LIBRARIES = livestatus.so
livestatus_so_SOURCES = \
- AndingFilter.cc ClientQueue.cc Column.cc ColumnsColumn.cc \
+ AndingFilter.cc ClientQueue.cc Column.cc ColumnsColumn.cc CustomVarsExplicitColumn.cc \
ContactsColumn.cc CustomVarsColumn.cc CustomVarsFilter.cc DoubleColumn.cc \
DoubleColumnFilter.cc DowntimeOrComment.cc DownCommColumn.cc EmptyColumn.cc \
Filter.cc GlobalCountersColumn.cc HostContactsColumn.cc HostgroupsColumn.cc \
diff --git a/livestatus/src/TableHosts.cc b/livestatus/src/TableHosts.cc
index 7b622ca..3af4998 100644
--- a/livestatus/src/TableHosts.cc
+++ b/livestatus/src/TableHosts.cc
@@ -37,6 +37,7 @@
#include "HostContactsColumn.h"
#include "DownCommColumn.h"
#include "CustomVarsColumn.h"
+#include "CustomVarsExplicitColumn.h"
#include "HostlistColumn.h"
#include "ServicelistColumn.h"
#include "ServicelistStateColumn.h"
@@ -253,6 +254,12 @@ void TableHosts::addColumns(Table *table, string prefix, int indirect_offset)
table->addColumn(new CustomVarsColumn(prefix + "custom_variables",
"A dictionary of the custom variables", (char *)(&hst.custom_variables) - ref, indirect_offset, CVT_DICT));
+ // Add direct access to the custom macro _FILENAME. In a future version of Livestatus
+ // this will probably be configurable so access to further custom variable can be
+ // added, such that those variables are presented like ordinary Nagios columns.
+ table->addColumn(new CustomVarsExplicitColumn(prefix + "filename",
+ "The value of the custom variable FILENAME", (char *)(&hst.custom_variables) - ref, indirect_offset, "FILENAME"));
+
table->addColumn(new HostlistColumn(prefix + "parents",
"A list of all direct parents of the host", (char *)(&hst.parent_hosts) - ref, indirect_offset, false));
table->addColumn(new HostlistColumn(prefix + "childs",