whoami7 - Manager
:
/
usr
/
local
/
nagios
/
plugins
/
Upload File:
files >> //usr/local/nagios/plugins/check_ro_fs.py.20201118.bak
#!/usr/bin/python ##################################### # this file is under Puppet control # # the last change: # # 2013/11/15, Eduard N. # ##################################### # 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" import os, re, sys, time, random from subprocess import Popen, PIPE debug = 0 #to do: #exclude/include via argv cur_mount = [x.split(' ') for x in Popen('cat /proc/mounts', stdout=PIPE, shell=True).stdout.read().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' cagefs_exclude_re = re.compile('^!/.*$') 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)] if debug: print ('cagefs_exclude_list ',cagefs_exclude_list) war_list = [] exclude_list = ['/usr/share/cagefs-skeleton/opt/suphp/sbin'] #include_list = ['/backup'] exclude_list.extend(cagefs_exclude_list) if debug: print ('exclude_list',exclude_list) for i in cur_mount: if debug: print ('i',i) if len(i) == 6: if ro_re.match(i[3]) and i[1] not in exclude_list: # if ro_re.match(i[3]) and i[3] in include_list: if debug: print ('debug match ', i) war_list.append(i[1]+' is in '+i[3]+' state,') else: war_list.append("Warning! Number of columns isn't 6") if debug: print ("Warning! Number of columns isn't 6", i) backup_dir = '/backup/' #test_file_name = str(int(time.time()))+str(random.randrange(0, 999999))+'backuptest.tmp' test_file_name = 'ro_backup_test.tmp' if debug: print ('run command: sudo /bin/touch '+backup_dir+test_file_name) test_command = Popen('sudo /bin/touch '+backup_dir+test_file_name, stderr=PIPE, shell=True) test_out, test_err = test_command.communicate() if test_command.returncode and len(test_err): war_list.append(backup_dir+' is in '+test_err+' state,') 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