Module: check_mk
Branch: master
Commit: 7a5de593014c9d909f3cdfecf69073dd390893e8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7a5de593014c9d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Mar 24 09:34:16 2015 +0100
Fixed pnp graph detection for nagios based installations
---
livestatus/src/module.c | 11 +++++------
livestatus/src/pnp4nagios.cc | 31 +++++++++++++------------------
2 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/livestatus/src/module.c b/livestatus/src/module.c
index 7115cd8..6118bc2 100644
--- a/livestatus/src/module.c
+++ b/livestatus/src/module.c
@@ -97,7 +97,7 @@ void *g_nagios_handle;
int g_unix_socket = -1;
int g_max_fd_ever = 0;
char g_socket_path[4096];
-char g_pnp_path[4096]; // base path for PNP4Nagios graphs
+char *g_pnp_path = 0; // base path for PNP4Nagios graphs
char g_mk_inventory_path[4096]; // base path of Check_MK inventor files
char g_logfile_path[4096];
int g_debug_level = 0;
@@ -637,9 +637,6 @@ void livestatus_parse_arguments(const char *args_orig)
else
strcpy(slash + 1, "livestatus.log");
- /* there is no default PNP path */
- g_pnp_path[0] = 0;
-
if (!args_orig)
return; // no arguments, use default options
@@ -731,9 +728,11 @@ void livestatus_parse_arguments(const char *args_orig)
}
}
else if (!strcmp(left, "pnp_path")) {
- strncpy(g_pnp_path, right, sizeof(g_pnp_path) - 1);
+ g_pnp_path = strndup(right, 4096);
+ logger(LOG_WARNING, "%s", g_pnp_path);
if (right[strlen(right) - 1] != '/')
- strncat(g_pnp_path, "/", sizeof(g_pnp_path) -
strlen(g_pnp_path) - 1 ); // make sure, that trailing slash is always there
+ strncat(g_pnp_path, "/", sizeof(&g_pnp_path) -
strlen(g_pnp_path) - 1 ); // make sure, that trailing slash is always there
+ logger(LOG_WARNING, "%s", g_pnp_path);
check_path("PNP perfdata directory", g_pnp_path);
}
else if (!strcmp(left, "mk_inventory_path")) {
diff --git a/livestatus/src/pnp4nagios.cc b/livestatus/src/pnp4nagios.cc
index e001c06..ae1dd2e 100644
--- a/livestatus/src/pnp4nagios.cc
+++ b/livestatus/src/pnp4nagios.cc
@@ -32,7 +32,7 @@
#include "pnp4nagios.h"
-extern char g_pnp_path[];
+extern char *g_pnp_path;
char *cleanup_pnpname(char *name)
{
@@ -51,28 +51,23 @@ int pnpgraph_present(const char *host, const char *service)
if (!g_pnp_path[0])
return -1;
- char path[4096];
- size_t needed_size = strlen(g_pnp_path) + strlen(host) + 16;
- if (service)
- needed_size += strlen(service);
- if (needed_size > sizeof(path))
- return -1;
+ string path = g_pnp_path;
+ char *cleaned_up;
+ cleaned_up = cleanup_pnpname(strdup(host));
+ path += cleaned_up;
+ free(cleaned_up);
+ path += "/";
- strcpy(path, g_pnp_path);
- char *end = path + strlen(path);
- strcpy(end, host);
- cleanup_pnpname(end);
- strcat(end, "/");
- end = end + strlen(end);
if (service) {
- strcat(end, service);
- cleanup_pnpname(end);
- strcat(end, ".xml");
+ cleaned_up = cleanup_pnpname(strdup(service));
+ path += cleaned_up;
+ path += ".xml";
+ free(cleaned_up);
}
else
- strcat(end, "_HOST_.xml");
+ path += "_HOST_.xml";
- if (0 == access(path, R_OK))
+ if (0 == access(path.c_str(), R_OK))
return 1;
else
return 0;