diff --git a/tests/scripts/test_monitoring.py b/tests/scripts/test_monitoring.py index 68278e0f90bc59033c15f7719f5d010df66a1517..5b16b495dc624c33278c9cd22301102a1c5db2f3 100755 --- a/tests/scripts/test_monitoring.py +++ b/tests/scripts/test_monitoring.py @@ -19,20 +19,57 @@ from utilities import logging as lg # noqa: E402 MUNIN_WWW_PATH = '/var/cache/munin/www/' +def check_munin_node(): + lg.log('Checking if Munin node works...') + + # check if package is installed + p = subprocess.run(['dpkg', '-s', 'munin-node'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if p.returncode != 0: + lg.info('The command "dpkg -s munin-node" returned code %s, assuming that the package is not installed. Test skipped.' % p.returncode) + return -1 + + # check that no plugin should be activated or disabled + lg.log('Checking that no plugin should be enabled/disabled.') + lg.log('munin-node-configure --shell --remove-also') + p = subprocess.run(['munin-node-configure', '--shell', '--remove-also'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out = p.stdout.decode('utf-8').strip() + err = p.stderr.decode('utf-8').strip() + lg.log(out) + lg.log(err) + if out: + if out.count('ln -s'): + lg.warning('%s plugins should be enabled.' % out.count('ln -s')) + if out.count('rm -f'): + lg.warning('%s plugins should be disabled.' % out.count('rm -f')) + lg.log('''To enable/disable correct plugins, please run:\n +munin-node-configure --shell --remove-also 2>/dev/null | sh; +systemctl restart munin 2>/dev/null; +systemctl restart munin-node;''') + return 0 + + def check_munin(): - lg.log('Checking if monitoring works...') - if not os.path.exists(MUNIN_WWW_PATH): - p = subprocess.run(['dpkg', '-s', 'munin'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) - if p.returncode == 0: - lg.error('Munin directory "%s" not found.' % MUNIN_WWW_PATH) - return 1 - else: - lg.info('Munin is not installed, test skipped.') - return 2 + lg.log('Checking if Munin graph works...') + + # check if package is installed + p = subprocess.run(['dpkg', '-s', 'munin'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + if p.returncode != 0: + lg.info('The command "dpkg -s munin" returned code %s, assuming that the package is not installed. Test skipped.' % p.returncode) + return -1 + + # get Munin www dir names + if os.path.exists(MUNIN_WWW_PATH): + names = os.listdir(MUNIN_WWW_PATH) + names.sort() + else: + names = [] + if not names: + lg.error('No Munin directory found in "%s".' % MUNIN_WWW_PATH) + return 1 # get cpu day graph of each host paths = list() - for name in os.listdir(MUNIN_WWW_PATH): + for name in names: 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)): path = os.path.join(MUNIN_WWW_PATH, name, sub_name, 'cpu-day.png') @@ -59,5 +96,6 @@ def check_munin(): if __name__ == '__main__': - code = check_munin() - sys.exit(code) + code1 = check_munin_node() + code2 = check_munin() + sys.exit(max(code1, code2))