58 lines
1.5 KiB
Python
Executable File
58 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
import sys, os, subprocess, socket, logging, logging.handlers
|
|
|
|
# script variables
|
|
checkPath = "/tmp"
|
|
|
|
# some filesystems are only writable by root
|
|
if os.geteuid() != 0:
|
|
subprocess.call(['sudo', 'python', sys.argv[0]]);
|
|
sys.exit(0);
|
|
|
|
# log to syslog
|
|
log = logging.getLogger(__file__)
|
|
log.setLevel(logging.DEBUG)
|
|
|
|
handler = logging.handlers.SysLogHandler(address = '/dev/log');
|
|
formatter = logging.Formatter('%(name)s %(levelname)s: %(message)s');
|
|
handler.setFormatter(formatter);
|
|
log.addHandler(handler);
|
|
|
|
# print message and exit
|
|
def printExit(msg):
|
|
print (msg);
|
|
log.info(msg);
|
|
exit(0);
|
|
|
|
# program begins
|
|
if os.path.isfile('/dev/shm/fsro-py.lock'):
|
|
printExit('MINOR Please health check CIFS mounts and then delete /dev/shm/fsro-py.lock.')
|
|
else:
|
|
open('/dev/shm/fsro-py.lock', 'a').close();
|
|
|
|
mountExists = subprocess.call(["grep", "-q", checkPath, "/proc/mounts"]);
|
|
if mountExists != 0:
|
|
printExit('MAJOR Mount ' + checkPath + ' missing');
|
|
|
|
testFile = checkPath + "/." + socket.gethostname() + "-test.dat";
|
|
|
|
try:
|
|
with open(testFile, 'wb') as fw:
|
|
fw.write(os.urandom(10*1024*1024));
|
|
fw.close();
|
|
except Exception as e:
|
|
printExit('MAJOR Mount ' + checkPath + ' not writable: ' + e);
|
|
|
|
try:
|
|
with open(testFile, 'r') as fr:
|
|
fr.read();
|
|
fr.close();
|
|
except Exception as e:
|
|
printExit('MAJOR Mount ' + checkPath + ' not readable: ' + e);
|
|
|
|
|
|
os.remove(testFile);
|
|
os.remove('/dev/shm/fsro-py.lock');
|
|
|
|
printExit('OK Mount ' + checkPath + ' healthy');
|