Module: check_mk
Branch: master
Commit: 206feb14b6ae05543e24fb4644328cd2f24285a5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=206feb14b6ae05…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Mar 14 13:21:34 2017 +0100
Make the pnp path file-local.
Change-Id: I55e3faa1698934a3e674c0e063412069805a347a
---
livestatus/src/HostSpecialIntColumn.cc | 2 +-
livestatus/src/MonitoringCore.h | 1 +
livestatus/src/ServiceSpecialIntColumn.cc | 3 ++-
livestatus/src/ServiceSpecialIntColumn.h | 9 ++++++---
livestatus/src/TableServices.cc | 4 ++--
livestatus/src/module.cc | 14 +++++++-------
livestatus/src/pnp4nagios.cc | 15 +++++++--------
livestatus/src/pnp4nagios.h | 8 +++++---
8 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/livestatus/src/HostSpecialIntColumn.cc
b/livestatus/src/HostSpecialIntColumn.cc
index 3809a6d..c4e9361 100644
--- a/livestatus/src/HostSpecialIntColumn.cc
+++ b/livestatus/src/HostSpecialIntColumn.cc
@@ -42,7 +42,7 @@ int32_t HostSpecialIntColumn::getValue(void *row, contact * /* auth_user
*/) {
}
case Type::pnp_graph_present:
- return pnpgraph_present(hst->name);
+ return pnpgraph_present(_mc, hst->name);
case Type::mk_inventory_last: {
return mk_inventory_last(_mc->mkInventoryPath() + "/" +
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 270b5d0..304e353 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -53,6 +53,7 @@ public:
virtual std::string mkeventdSocketPath() = 0;
virtual std::string mkLogwatchPath() = 0;
virtual std::string mkInventoryPath() = 0;
+ virtual std::string pnpPath() = 0;
virtual Logger *loggerLivestatus() = 0;
};
diff --git a/livestatus/src/ServiceSpecialIntColumn.cc
b/livestatus/src/ServiceSpecialIntColumn.cc
index 93081db..205322a 100644
--- a/livestatus/src/ServiceSpecialIntColumn.cc
+++ b/livestatus/src/ServiceSpecialIntColumn.cc
@@ -30,7 +30,8 @@ int32_t ServiceSpecialIntColumn::getValue(void *row,
if (auto svc = rowData<service>(row)) {
switch (_type) {
case Type::pnp_graph_present:
- return pnpgraph_present(svc->host_ptr->name, svc->description);
+ return pnpgraph_present(_mc, svc->host_ptr->name,
+ svc->description);
}
}
return 0;
diff --git a/livestatus/src/ServiceSpecialIntColumn.h
b/livestatus/src/ServiceSpecialIntColumn.h
index 1fed1fb..78f1aac 100644
--- a/livestatus/src/ServiceSpecialIntColumn.h
+++ b/livestatus/src/ServiceSpecialIntColumn.h
@@ -30,21 +30,24 @@
#include <string>
#include "IntColumn.h"
#include "nagios.h"
+class MonitoringCore;
class ServiceSpecialIntColumn : public IntColumn {
public:
enum class Type { pnp_graph_present };
ServiceSpecialIntColumn(const std::string& name,
- const std::string& description, Type ssic_type,
- int indirect_offset, int extra_offset,
- int extra_extra_offset)
+ const std::string& description, MonitoringCore* mc,
+ Type ssic_type, int indirect_offset,
+ int extra_offset, int extra_extra_offset)
: IntColumn(name, description, indirect_offset, extra_offset,
extra_extra_offset)
+ , _mc(mc)
, _type(ssic_type) {}
int32_t getValue(void* row, contact* auth_user) override;
private:
+ MonitoringCore* _mc;
Type _type;
};
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index 487707d..aae1daa 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -351,8 +351,8 @@ void TableServices::addColumns(Table *table, const string
&prefix,
table->addColumn(make_unique<ServiceSpecialIntColumn>(
prefix + "pnpgraph_present",
"Whether there is a PNP4Nagios graph present for this service (0/1)",
- ServiceSpecialIntColumn::Type::pnp_graph_present, indirect_offset, -1,
- -1));
+ core, ServiceSpecialIntColumn::Type::pnp_graph_present, indirect_offset,
+ -1, -1));
table->addColumn(make_unique<ServiceSpecialDoubleColumn>(
prefix + "staleness", "The staleness indicator for this
service",
ServiceSpecialDoubleColumn::Type::staleness, indirect_offset, -1, -1));
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 69422ca..d2ccb68 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -102,8 +102,7 @@ void *g_nagios_handle;
int g_unix_socket = -1;
int g_max_fd_ever = 0;
static char fl_socket_path[4096];
-char pnp_path_storage[4096];
-char *g_pnp_path = pnp_path_storage;
+static char fl_pnp_path[4096];
static char fl_mk_inventory_path[4096];
static char fl_mk_logwatch_path[4096];
static char fl_logfile_path[4096];
@@ -607,6 +606,7 @@ public:
string mkeventdSocketPath() override { return fl_mkeventd_socket_path; }
string mkLogwatchPath() override { return fl_mk_logwatch_path; }
string mkInventoryPath() override { return fl_mk_inventory_path; }
+ string pnpPath() override { return fl_pnp_path; }
Logger *loggerLivestatus() override { return fl_logger_livestatus; }
@@ -799,7 +799,7 @@ void livestatus_parse_arguments(const char *args_orig) {
fl_mkeventd_socket_path[0] = 0;
/* there is no default PNP path */
- g_pnp_path[0] = 0;
+ fl_pnp_path[0] = 0;
if (args_orig == nullptr) {
return; // no arguments, use default options
@@ -909,13 +909,13 @@ void livestatus_parse_arguments(const char *args_orig) {
"allowed are strict and loose";
}
} else if (strcmp(left, "pnp_path") == 0) {
- strncpy(g_pnp_path, right, sizeof(pnp_path_storage) - 1);
+ strncpy(fl_pnp_path, right, sizeof(fl_pnp_path) - 1);
// make sure, that trailing slash is always there
if (right[strlen(right) - 1] != '/') {
- strncat(g_pnp_path, "/",
- sizeof(pnp_path_storage) - strlen(g_pnp_path) - 1);
+ strncat(fl_pnp_path, "/",
+ sizeof(fl_pnp_path) - strlen(fl_pnp_path) - 1);
}
- check_path("PNP perfdata directory", g_pnp_path);
+ check_path("PNP perfdata directory", fl_pnp_path);
} else if (strcmp(left, "mk_inventory_path") == 0) {
strncpy(fl_mk_inventory_path, right,
sizeof(fl_mk_inventory_path) - 1);
diff --git a/livestatus/src/pnp4nagios.cc b/livestatus/src/pnp4nagios.cc
index b0c77a8..e7a08b4 100644
--- a/livestatus/src/pnp4nagios.cc
+++ b/livestatus/src/pnp4nagios.cc
@@ -27,16 +27,14 @@
#include "pnp4nagios.h"
#include <cstddef>
#include <system_error>
+#include "MonitoringCore.h"
+
#ifndef CMC
#include "FileSystem.h"
#endif
using std::string;
-// Note: If the path is not empty, it always ends with '/', see
-// livestatus_parse_arguments.
-extern char* g_pnp_path;
-
namespace {
// TODO(sp): Move this to some kind of C++ string utility file.
@@ -56,8 +54,9 @@ string pnp_cleanup(const string& name) {
#ifndef CMC
// TODO(sp) Merge this with Perfdatabase::getPNPXMLPath
-int pnpgraph_present(const string& host, const string& service) {
- fs::path pnp_path = g_pnp_path;
+int pnpgraph_present(MonitoringCore* mc, const string& host,
+ const string& service) {
+ fs::path pnp_path = mc->pnpPath();
if (pnp_path.empty()) {
return -1;
}
@@ -71,9 +70,9 @@ int pnpgraph_present(const string& host, const string& service)
{
#ifdef CMC
// TODO(sp) Merge this with Perfdatabase::getPNPRRDPath
-fs::path rrd_path(const string& host, const string& service,
+fs::path rrd_path(MonitoringCore* mc, const string& host, const string& service,
const string& varname) {
- fs::path pnp_path = g_pnp_path;
+ fs::path pnp_path = mc->pnpPath();
if (pnp_path.empty()) {
return "";
}
diff --git a/livestatus/src/pnp4nagios.h b/livestatus/src/pnp4nagios.h
index 5cfc496..3be82a1 100644
--- a/livestatus/src/pnp4nagios.h
+++ b/livestatus/src/pnp4nagios.h
@@ -27,6 +27,8 @@
#include "config.h" // IWYU pragma: keep
#include <string>
+class MonitoringCore;
+
#ifdef CMC
#include "FileSystem.h"
#endif
@@ -34,7 +36,7 @@
std::string pnp_cleanup(const std::string& name);
#ifndef CMC
-int pnpgraph_present(const std::string& host,
+int pnpgraph_present(MonitoringCore* mc, const std::string& host,
const std::string& service = "_HOST_");
#endif
@@ -42,8 +44,8 @@ int pnpgraph_present(const std::string& host,
// Determines if a RRD database exists and returns its path name. Returns an
// empty string otherwise. This assumes paths created in the PNP4Nagios style
// with storage type MULTIPLE.
-fs::path rrd_path(const std::string& host, const std::string& service,
- const std::string& varname);
+fs::path rrd_path(MonitoringCore* mc, const std::string& host,
+ const std::string& service, const std::string& varname);
#endif
#endif // pnp4nagios_h