Wrote this simple plugin to check if a log file was stale on a server using nagios and nrpe. This plugin checks multiple files with the app. naming convention.
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 |
#!/usr/bin/env python __author__ = "Jason Ralph" """ IMPORTS """ import datetime import time import re import sys import os import optparse import os.path import glob """ NAGIOS API RETURN CODES """ nag_ret_dict = {'NagOk': 0, 'NagWarn': 1, 'NagCrit': 2, 'NagUnkown': 3} def main(): for file in glob.glob('/var/log/httpd/app.*'): now = datetime.datetime.now() then = datetime.datetime.fromtimestamp(os.path.getmtime(file)) tdelta = now - then if not file: print("OK: Waiting for file") sys.exit(nag_ret_dict['NagOk']) elif tdelta > datetime.timedelta(days=1): print("CRIT: %s: Is greater then %s") % (file, tdelta) sys.exit(nag_ret_dict['NagCrit']) else: print("OK: NOW: %s - THEN: %s - DELTA: %s" ) % (now, then, tdelta) sys.exit(nag_ret_dict['NagOk']) if __name__ == "__main__": main() |