whoami7 - Manager
:
/
lib64
/
nagios
/
plugins
/
nccustom
/
Upload File:
files >> //lib64/nagios/plugins/nccustom/check_ro_fs.py
#!/usr/libexec/platform-python # -*- coding: utf-8 -*- # version 2013/07/31 # writen by ED # Requirements: # you need to allow fillowing commands in sudo: # "/bin/cat /etc/cagefs/cagefs.mp" and "/bin/touch /backup/ro_backup_test.tmp" # edited by Max.N # remove /backup from monitoring, deprecated by check_backup.sh # added PHP 7.3 to exclude lists, TO-12377 (by Bogdan Kukharskiy) import os, re, sys, time, random from subprocess import Popen, PIPE debug = 0 # Python 2 version; #cur_mount = [x.split(' ') for x in Popen('cat /proc/mounts', stdout=PIPE, shell=True).stdout.read().split('\n') if len(x) != 0 ] cur_mount = [x.split(' ') for x in Popen('cat /proc/mounts', stdout=PIPE, shell=True).stdout.read().decode('UTF-8').split('\n') if len(x) != 0 ] ro_re = re.compile('^ro,.*$') cagefs_exclude_file = '/etc/cagefs/cagefs.mp' cagefs_skeleton_dir = '/usr/share/cagefs-skeleton' if os.path.islink(cagefs_skeleton_dir): cagefs_skeleton_dir = os.path.realpath(cagefs_skeleton_dir) cagefs_exclude_re = re.compile('^!/.*$') # Python 2 version; #cagefs_exclude_list = [cagefs_skeleton_dir + x[1:] for x in Popen('sudo /bin/cat '+cagefs_exclude_file, stdout=PIPE, shell=True).stdout.read().split('\n') if cagefs_exclude_re.match(x)] cagefs_exclude_list = [cagefs_skeleton_dir + x[1:] for x in Popen('sudo /bin/cat '+cagefs_exclude_file, stdout=PIPE, shell=True).stdout.read().decode('UTF-8').split('\n') if cagefs_exclude_re.match(x)] cagefs_exclude_list.append("%s/var/lve/lveinfo.ver.cagefs" % (cagefs_skeleton_dir)) # whitelist lveinfo.ver.cagefs RO file if debug: print('cagefs_exclude_list ', cagefs_exclude_list) war_list = [] exclude_list = [cagefs_skeleton_dir + '/opt/suphp/sbin', '/backup'] exclude_list.extend([cagefs_skeleton_dir + '/opt/cpanel/ea-php%s/root/etc' % x for x in ('52', '53', '54', '55', '56', '70', '71', '72', '73', '74', '81')]) exclude_list.extend([cagefs_skeleton_dir + '/opt/cpanel/ea-php%s/root/usr/bin' % x for x in ('52', '53', '54', '55', '56', '70', '71', '72', '73', '74', '81')]) exclude_list.extend(cagefs_exclude_list) if debug: print('exclude_list', exclude_list) for line in cur_mount: if debug: print('line',line) if len(line) == 6: if ro_re.match(line[3]) and line[1] not in exclude_list: if debug: print('debug match ', line) war_list.append(line[1] + ' is in ' + line[3] + ' state,') else: war_list.append("Warning! Number of columns isn't 6") if debug: print("Warning! Number of columns isn't 6", line) result_re = re.compile("^.* is in.* state,$") result = 0 if len(war_list) != 0: for res_line in war_list: if result_re.match(res_line): result = 1 if result: print(war_list) sys.exit(2) else: raise SystemExit(war_list) else: print('OK')
Copyright ©2021 || Defacer Indonesia