diff --git a/tests/test_monitoring.py b/tests/test_monitoring.py index 4d5784f440b51e65fd093159483cd6208a782728..bf4432b8829757aededf4ab443a90fdac346c16a 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)