Module: check_mk
Branch: master
Commit: 8ea1be1ba02eae06fa9950a3d0fcb777a1f4c386
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8ea1be1ba02eaeā¦
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Mar 31 06:15:12 2015 +0200
Revert "Fixed pnp graph detection for nagios based installations"
This reverts commit 7a5de593014c9d909f3cdfecf69073dd390893e8.
Conflicts:
livestatus/src/module.c
---
livestatus/src/module.c | 9 ++++++---
livestatus/src/pnp4nagios.cc | 31 ++++++++++++++++++-------------
2 files changed, 24 insertions(+), 16 deletions(-)
diff --git a/livestatus/src/module.c b/livestatus/src/module.c
index d54f6ee..7115cd8 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 = 0; // base path for PNP4Nagios graphs
+char g_pnp_path[4096]; // 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,6 +637,9 @@ 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
@@ -728,9 +731,9 @@ void livestatus_parse_arguments(const char *args_orig)
}
}
else if (!strcmp(left, "pnp_path")) {
- g_pnp_path = strndup(right, 4096);
+ strncpy(g_pnp_path, right, sizeof(g_pnp_path) - 1);
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
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 ae1dd2e..e001c06 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,23 +51,28 @@ int pnpgraph_present(const char *host, const char *service)
if (!g_pnp_path[0])
return -1;
- string path = g_pnp_path;
- char *cleaned_up;
- cleaned_up = cleanup_pnpname(strdup(host));
- path += cleaned_up;
- free(cleaned_up);
- path += "/";
+ 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;
+ strcpy(path, g_pnp_path);
+ char *end = path + strlen(path);
+ strcpy(end, host);
+ cleanup_pnpname(end);
+ strcat(end, "/");
+ end = end + strlen(end);
if (service) {
- cleaned_up = cleanup_pnpname(strdup(service));
- path += cleaned_up;
- path += ".xml";
- free(cleaned_up);
+ strcat(end, service);
+ cleanup_pnpname(end);
+ strcat(end, ".xml");
}
else
- path += "_HOST_.xml";
+ strcat(end, "_HOST_.xml");
- if (0 == access(path.c_str(), R_OK))
+ if (0 == access(path, R_OK))
return 1;
else
return 0;