Module: check_mk
Branch: master
Commit: 5cc3f0135cc47eacdd035b7b5174091cf5bfcc48
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5cc3f0135cc47e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon May 2 14:36:47 2016 +0200
New Livestatus command for removing mk_logwatch logfiles
---
livestatus/src/Store.cc | 23 ++++++++++++++++++++++-
livestatus/src/Store.h | 1 +
livestatus/src/mk_logwatch.cc | 23 ++++++++++++++++++++++-
livestatus/src/mk_logwatch.h | 1 +
4 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/livestatus/src/Store.cc b/livestatus/src/Store.cc
index e293188..05e783b 100644
--- a/livestatus/src/Store.cc
+++ b/livestatus/src/Store.cc
@@ -34,6 +34,7 @@
#include "global_counters.h"
#include "logger.h"
#include "strutil.h"
+#include "mk_logwatch.h"
// TODO(sp): Remove this hack.
#ifdef EXTERN
@@ -180,7 +181,9 @@ bool Store::answerRequest(InputBuffer *input, OutputBuffer *output) {
}
void Store::answerCommandRequest(const char *command) {
- logger(LOG_WARNING, "Das Kommando ist [%s]", command);
+ if (answerLogwatchCommandRequest(command))
+ return;
+
lock_guard<mutex> lg(_command_mutex);
#ifdef NAGIOS4
process_external_command1((char *)command);
@@ -191,6 +194,24 @@ void Store::answerCommandRequest(const char *command) {
#endif
}
+bool Store::answerLogwatchCommandRequest(const char *command) {
+ // Handle special command "[1462191638]
MK_LOGWATCH_ACKNOWLEDGE;host123;\var\log\syslog"
+ if (strlen(command) >= 37 &&
+ command[0] == '[' &&
+ command[11] == ']' &&
+ !strncmp(command + 13, "MK_LOGWATCH_ACKNOWLEDGE;", 24)) {
+ const char *host_name_begin = command + 37;
+ const char *host_name_end = strchr(host_name_begin, ';');
+ if (!host_name_end)
+ return false;
+ std::string host_name(host_name_begin, host_name_end - host_name_begin);
+ std::string file_name(host_name_end + 1);
+ mk_logwatch_acknowledge(host_name, file_name);
+ return true;
+ }
+ return false;
+}
+
void Store::answerGetRequest(const list<string> &lines, OutputBuffer *output,
const char *tablename) {
output->reset();
diff --git a/livestatus/src/Store.h b/livestatus/src/Store.h
index b1b8f72..e5079ce 100644
--- a/livestatus/src/Store.h
+++ b/livestatus/src/Store.h
@@ -94,6 +94,7 @@ private:
void answerGetRequest(const std::list<std::string> &lines, OutputBuffer *,
const char *);
void answerCommandRequest(const char *);
+ bool answerLogwatchCommandRequest(const char *);
};
#endif // Store_h
diff --git a/livestatus/src/mk_logwatch.cc b/livestatus/src/mk_logwatch.cc
index 3b6d805..7be473b 100644
--- a/livestatus/src/mk_logwatch.cc
+++ b/livestatus/src/mk_logwatch.cc
@@ -23,7 +23,9 @@
// Boston, MA 02110-1301 USA.
-
+#include <stdio.h>
+#include <string.h>
+#include "logger.h"
#include "mk_logwatch.h"
#include "pnp4nagios.h"
@@ -36,3 +38,22 @@ std::string mk_logwatch_path_of_host(const char *host_name)
path += pnp_cleanup(host_name);
return path;
}
+
+void mk_logwatch_acknowledge(const std::string &host_name, const std::string
&file_name)
+{
+ if (file_name.find('/') != std::string::npos) {
+ logger(LOG_WARNING, "Invalid character / in mk_logfile filename '%s'
of host '%s'", file_name.c_str(), host_name.c_str());
+ return;
+ }
+
+ std::string path(MK_LOGWATCH_PATH);
+ if (path == "")
+ return;
+ path += pnp_cleanup(host_name);
+ path += "/";
+ path += file_name;
+
+ int r = remove(path.c_str());
+ if (r != 0)
+ logger(LOG_WARNING, "Cannot acknowledge mk_logfile file '%s' of host
'%s': %s", file_name.c_str(), host_name.c_str(), strerror(errno));
+}
diff --git a/livestatus/src/mk_logwatch.h b/livestatus/src/mk_logwatch.h
index 9ee8201..856bab0 100644
--- a/livestatus/src/mk_logwatch.h
+++ b/livestatus/src/mk_logwatch.h
@@ -37,6 +37,7 @@ extern char g_mk_logwatch_path[];
#endif
std::string mk_logwatch_path_of_host(const char *);
+void mk_logwatch_acknowledge(const std::string &host_name, const std::string
&file_name);
#endif // mk_logwatch_h