1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/usr/bin/python import os.path import time import datetime import sys import optparse """Check the status of application lock file to be sure it is not stale, warn at critical at 18000 seconds warn at 10800""" parser = optparse.OptionParser() parser.add_option('-w', action="store", default="10800", help="seconds to warn", type="int") parser.add_option('-c', action="store", default="18000", help="seconds to crit", type="int") options, args = parser.parse_args() nagOk = 0 nagWarn = 1 nagCrit = 2 try: statInfo = os.stat('/opt/application/.sync-lock') except OSError: print("WAITING FOR LOCK FILE") sys.exit(nagOk) now = int(time.time()) statInfoSlice = statInfo[8] timeDiff = now - statInfoSlice #print("NOW: %s") % now #print("FILEAGE: %s") % statInfoSlice #print("TIMEDIFF: %s") % timeDiff if timeDiff > options.c: print("CRIT: lock file is older than 5 hours") sys.exit(nagCrit) elif timeDiff > options.w: print("WARN: lock file is older than 3 hours") sys.exit(nagWarn) else: print("OK: lock file is under 3 hours") sys.exit(nagOk) |