Module: check_mk
Branch: master
Commit: 10bca23d6da3b2c3b956b2e6d313a68a7838b664
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=10bca23d6da3b2…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Wed Oct 31 10:56:58 2018 +0100
mk_logwatch: minor refactoring
Move some code from the global namespace to the appropriate place.
Push the remaining global variables to the top of the file.
Change-Id: If4b32b3b2b923bae055f543078a63d94e8366db4
---
agents/plugins/mk_logwatch | 56 +++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 30 deletions(-)
diff --git a/agents/plugins/mk_logwatch b/agents/plugins/mk_logwatch
index eb27781..05100c0 100755
--- a/agents/plugins/mk_logwatch
+++ b/agents/plugins/mk_logwatch
@@ -33,6 +33,23 @@ import shutil
import sys
import time
+if '-d' in sys.argv[1:] or '--debug' in sys.argv[1:]:
+ tty_red = '\033[1;31m'
+ tty_green = '\033[1;32m'
+ tty_yellow = '\033[1;33m'
+ tty_blue = '\033[1;34m'
+ tty_normal = '\033[0m'
+ debug = True
+else:
+ tty_red = ''
+ tty_green = ''
+ tty_yellow = ''
+ tty_blue = ''
+ tty_normal = ''
+ debug = False
+
+pushed_back_line = None
+
# .--MEI-Cleanup---------------------------------------------------------.
# | __ __ _____ ___ ____ _ |
# | | \/ | ____|_ _| / ___| | ___ __ _ _ __ _ _ _ __ |
@@ -108,21 +125,6 @@ class MEIFolderCleaner(object):
pass
#.
-if '-d' in sys.argv[1:] or '--debug' in sys.argv[1:]:
- tty_red = '\033[1;31m'
- tty_green = '\033[1;32m'
- tty_yellow = '\033[1;33m'
- tty_blue = '\033[1;34m'
- tty_normal = '\033[0m'
- debug = True
-else:
- tty_red = ''
- tty_green = ''
- tty_yellow = ''
- tty_blue = ''
- tty_normal = ''
- debug = False
-
# The configuration file and status file are searched
# in the directory named by the environment variable
@@ -137,16 +139,6 @@ 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()):
- shutil.copy("%s/logwatch.state" % mk_vardir(), status_filename())
-
-
def status_filename():
# Determine the name of the state file
# $REMOTE set -> logwatch.state.$REMOTE
@@ -191,6 +183,8 @@ def parse_pattern(level, pattern, line):
def read_config():
+ config_filename = mk_confdir() + "/logwatch.cfg"
+
config_lines = []
try:
config_lines += [
@@ -202,6 +196,7 @@ def read_config():
raise
# Add config from a logwatch.d folder
+ config_dir = mk_confdir() + "/logwatch.d/*.cfg"
for config_file in glob.glob(config_dir):
config_lines += [
line.rstrip() for line in filter(is_not_comment,
@@ -288,9 +283,6 @@ def save_status(status):
f.write("%s|%d|%d\n" % (filename, offset, inode))
-pushed_back_line = None
-
-
def next_line(file_handle):
global pushed_back_line
if pushed_back_line is not None:
@@ -497,7 +489,6 @@ def process_logfile(logfile, patterns, opt, status):
class Options(object):
-
MAP_OVERFLOW = {'C': 2, 'W': 1, 'I': 0, 'O': 0}
MAP_BOOL = {'true': True, 'false': False}
@@ -567,7 +558,6 @@ class Options(object):
def parse_sections(config):
-
logfile_patterns = {}
for filenames, patterns in config:
@@ -597,6 +587,12 @@ def parse_sections(config):
def main():
+ 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()):
+ shutil.copy("%s/logwatch.state" % mk_vardir(), status_filename())
+
try:
# This removes leftover folders which may be generated by crashing frozen
binaries
folder_cleaner = MEIFolderCleaner()