Module: check_mk
Branch: master
Commit: 07d996490798bcf8f2440a5ab18d0b0956e0d62a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=07d996490798bc…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Oct 31 10:49:55 2018 +0100
mk_logwatch: extract functions mk_vardir and mk_confdir
Change-Id: Ibb2166379d5ed3236a1b2a081c41a7694c19b20e
---
agents/plugins/mk_logwatch | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/agents/plugins/mk_logwatch b/agents/plugins/mk_logwatch
index 98ac5f0..eb27781 100755
--- a/agents/plugins/mk_logwatch
+++ b/agents/plugins/mk_logwatch
@@ -29,6 +29,7 @@
import glob
import os
import re
+import shutil
import sys
import time
@@ -122,28 +123,28 @@ else:
tty_normal = ''
debug = False
+
# The configuration file and status file are searched
# in the directory named by the environment variable
# LOGWATCH_DIR. If that is not set, MK_CONFDIR is used.
# If that is not set either, the current directory ist
# used.
-logwatch_dir = os.getenv("LOGWATCH_DIR")
-if logwatch_dir:
- mk_confdir = logwatch_dir
- mk_vardir = logwatch_dir
-else:
- mk_confdir = os.getenv("MK_CONFDIR") or "."
- mk_vardir = os.getenv("MK_VARDIR") or os.getenv("MK_STATEDIR") or
"."
+def mk_vardir():
+ return os.getenv("LOGWATCH_DIR") or os.getenv("MK_VARDIR") or
os.getenv("MK_STATEDIR") or "."
-sys.stdout.write("<<<logwatch>>>\n")
-config_filename = mk_confdir + "/logwatch.cfg"
-config_dir = mk_confdir + "/logwatch.d/*.cfg"
+def mk_confdir():
+ return os.getenv("LOGWATCH_DIR") or os.getenv("MK_CONFDIR") or
"."
+
+
+config_filename = mk_confdir() + "/logwatch.cfg"
+config_dir = mk_confdir() + "/logwatch.d/*.cfg"
+
+sys.stdout.write("<<<logwatch>>>\n")
# Copy the last known state from the logwatch.state when there is no status_filename
yet.
-if not os.path.exists(status_filename()) and os.path.exists("%s/logwatch.state"
% mk_vardir):
- import shutil
- shutil.copy("%s/logwatch.state" % mk_vardir, status_filename())
+if not os.path.exists(status_filename()) and os.path.exists("%s/logwatch.state"
% mk_vardir()):
+ shutil.copy("%s/logwatch.state" % mk_vardir(), status_filename())
def status_filename():
@@ -153,10 +154,10 @@ def status_filename():
# $REMOTE not set and not a tty -> logwatch.state
remote_hostname = os.getenv("REMOTE", "").replace(":",
"_")
if remote_hostname != "":
- return "%s/logwatch.state.%s" % (mk_vardir, remote_hostname)
+ return "%s/logwatch.state.%s" % (mk_vardir(), remote_hostname)
if sys.stdout.isatty():
- return "%s/logwatch.state.local" % mk_vardir
- return "%s/logwatch.state" % mk_vardir
+ return "%s/logwatch.state.local" % mk_vardir()
+ return "%s/logwatch.state" % mk_vardir()
def os_type():