From c608809d1c3a91a1ae6ebf5777b04e9a3a57a821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Diemer?= <stephane.diemer@ubicast.eu> Date: Wed, 22 Aug 2018 16:00:57 +0200 Subject: [PATCH] Changed monitoring test to find cpu graph dynamically (refs #24369). --- tests/test_monitoring.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/test_monitoring.py b/tests/test_monitoring.py index 4d5784f4..bf4432b8 100755 --- a/tests/test_monitoring.py +++ b/tests/test_monitoring.py @@ -39,16 +39,31 @@ def print_green(txt): print_color(txt, GREEN) -host = conf.get('MS_SERVER_NAME') -suffix = '.'.join(host.split('.')[1:]) -MUNIN_CHECK_PATH = "/var/cache/munin/www/%s/%s/cpu-day.png" % (suffix, host) -if not os.path.exists(MUNIN_CHECK_PATH): - MUNIN_CHECK_PATH = "/var/cache/munin/www/%s/%s/cpu-day.png" % ("localdomain", "localhost.localdomain") +MUNIN_WWW_PATH = '/var/cache/munin/www/' def check_munin(): - print('Checking if monitoring works') - mtime = os.path.getmtime(MUNIN_CHECK_PATH) + print('Checking if monitoring works...') + if not os.path.exists(MUNIN_WWW_PATH): + print_red('Munin directory "%s" not found.' % MUNIN_WWW_PATH) + return 1 + path = os.path.join(MUNIN_WWW_PATH, 'localdomain', 'localhost.localdomain', 'cpu-day.png') + if not os.path.exists(path): + path = None + for name in os.listdir(MUNIN_WWW_PATH): + if not name.endswith('.html') and name != 'static' and os.path.isfile(os.path.join(MUNIN_WWW_PATH, name, 'index.html')): + for sub_name in os.listdir(os.path.join(MUNIN_WWW_PATH, name)): + p = os.path.join(MUNIN_WWW_PATH, name, sub_name, 'cpu-day.png') + if sub_name != 'index.html' and os.path.exists(p): + path = p + break + if path: + break + if not path: + print_red('Munin host directory not found in "%s".' % MUNIN_WWW_PATH) + return 1 + print('Found host directory: "%s".' % path) + mtime = os.path.getmtime(path) d = datetime.fromtimestamp(mtime) now = datetime.now() diff_seconds = (now - d).total_seconds() @@ -59,9 +74,6 @@ def check_munin(): print_green('Monitoring data is not older than 1 hour, everything seems fine.') return 0 -if not os.path.exists(MUNIN_CHECK_PATH): - print_red('Munin data %s not found.' % MUNIN_CHECK_PATH) - sys.exit(1) rc = check_munin() sys.exit(rc) -- GitLab