#!/usr/bin/python -u # =========================================================================== # # check_readonly - Check if all ext3 file systems are writable # # Usage: Simply run the script, and it will check the local host only. # There are no command-line options for this check. Maybe in the # future, but for now, it does exactly what we want it to do. # # Changelog: # # 2008-06-05 -- bjared@ethosprime.com -- Created this script. # =========================================================================== import sys, os, re, commands # Dictionary of Nagios Plug-in return-values ERRORS={ 'OK':0, 'WARNING':1, 'CRITICAL':2, 'UNKNOWN':3, 'DEPENDENT':4 }; # Initialize the return value returnVal = ERRORS['OK'] # Initialize the return string returnStr = "check_readonly OK: All mountpoints writable" # Get a list of all the mounted volumes that are ext3 mounts = commands.getoutput("mount -t ext3").split("\n") # Compile a regular expression to capture the mounted directories myRE = re.compile("\S+ on (\S+) type ext3.*") # Initialize the counter used within the "for" loop counter = 1 # Loop through all the lines returned by the "mount -t ext3" command for line in mounts: # Apply the regular expression, and return the captured value mountpoint = myRE.match(line).group(1) # Set wFile to the full path of our file we're going to test with wFile = mountpoint + "/this-is-only-a-test" try: # We see if we can open our file for writing in that partition wTest = file(wFile, "w") except: # If the write fails, we are dropped into here, and prepare output if counter == 1: returnVal = ERRORS['CRITICAL'] returnStr = "check_readonly CRITICAL: Could not write to: " else: if counter > 1: returnStr += ", " returnStr += mountpoint counter += 1 else: # If the write succeeded, and we clean up after ourselves. wTest.close() os.unlink(wFile) # Print the status of this check print returnStr # Exit with our return value sys.exit(returnVal)