Skip to content
Snippets Groups Projects
Commit 0524de58 authored by Stéphane Diemer's avatar Stéphane Diemer
Browse files

Fixed monitoring test if munin is not installed (refs #26808).

parent 38bf0fd5
No related branches found
No related tags found
No related merge requests found
...@@ -4,49 +4,33 @@ ...@@ -4,49 +4,33 @@
Criticality: Low Criticality: Low
Check that the monitoring graphs work. Check that the monitoring graphs work.
''' '''
import os
from datetime import datetime from datetime import datetime
import sys
import imp import imp
import os
YELLOW = '\033[93m' import subprocess
GREEN = '\033[92m' import sys
RED = '\033[91m'
DEF = '\033[0m'
os.chdir(os.path.dirname(__file__)) os.chdir(os.path.dirname(__file__))
if not os.path.isfile('../utils.py'): if not os.path.isfile('../utils.py'):
print('The envsetup configuration was not found.') print('The envsetup configuration was not found.')
sys.exit(1) sys.exit(1)
else: u = imp.load_source('es_utils', '../utils.py')
es_utils = imp.load_source('es_utils', '../utils.py') conf = u.load_conf()
conf = es_utils.load_conf()
def print_color(txt, col):
print('%s%s%s' % (col, txt, DEF))
def print_yellow(txt):
print_color(txt, YELLOW)
def print_red(txt):
print_color(txt, RED)
def print_green(txt):
print_color(txt, GREEN)
MUNIN_WWW_PATH = '/var/cache/munin/www/' MUNIN_WWW_PATH = '/var/cache/munin/www/'
def check_munin(): def check_munin():
print('Checking if monitoring works...') u.log('Checking if monitoring works...')
if not os.path.exists(MUNIN_WWW_PATH): if not os.path.exists(MUNIN_WWW_PATH):
print_red('Munin directory "%s" not found.' % MUNIN_WWW_PATH) p = subprocess.run(['dpkg', '-s', 'munin'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return 1 if p.returncode == 0:
u.error('Munin directory "%s" not found.' % MUNIN_WWW_PATH)
return 1
else:
u.error('Munin is not installed.')
return 2
# get cpu day graph of each host # get cpu day graph of each host
paths = list() paths = list()
...@@ -57,24 +41,25 @@ def check_munin(): ...@@ -57,24 +41,25 @@ def check_munin():
if sub_name != 'index.html' and os.path.exists(path): if sub_name != 'index.html' and os.path.exists(path):
paths.append(path) paths.append(path)
if not paths: if not paths:
print_red('No Munin host directory was found in "%s".' % MUNIN_WWW_PATH) u.error('No Munin host directory was found in "%s".' % MUNIN_WWW_PATH)
return 1 return 1
# check graph mtime # check graph mtime
error = False error = False
for path in paths: for path in paths:
print('Checking graph "%s" modification date...' % path) u.log('Checking graph "%s" modification date...' % path)
mtime = os.path.getmtime(path) mtime = os.path.getmtime(path)
d = datetime.fromtimestamp(mtime) d = datetime.fromtimestamp(mtime)
now = datetime.now() now = datetime.now()
diff_seconds = (now - d).total_seconds() diff_seconds = (now - d).total_seconds()
if diff_seconds > 3600: if diff_seconds > 3600:
print_red('The graph is older than 1 hour. The monitoring is probably not working.') u.error('The graph is older than 1 hour. The monitoring is probably not working.')
error = True error = True
else: else:
print_green('The graph is not older than 1 hour.') u.success('The graph is not older than 1 hour.')
return 1 if error else 0 return 1 if error else 0
rc = check_munin() if __name__ == '__main__':
sys.exit(rc) rc = check_munin()
sys.exit(rc)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment