Created
November 25, 2018 14:14
-
-
Save andiwand/abe2142238b392c769263c72c571ee31 to your computer and use it in GitHub Desktop.
nagios script; check access / modified / creation age
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import time | |
import argparse | |
def main(): | |
parser = argparse.ArgumentParser(description='check access / modified / creation age') | |
parser.add_argument('path', help='path to check') | |
parser.add_argument('warning', type=float, help='warning limit (in seconds)') | |
parser.add_argument('error', type=float, help='error limit (in seconds)') | |
parser.add_argument('--time', choices=['atime', 'mtime', 'ctime'], default='mtime', help='time to use') | |
args = parser.parse_args() | |
if not os.path.exists(args.path): | |
print('UNKNOWN %s does not exist' % args.path) | |
return 3 | |
stat = os.stat(args.path) | |
xtime = getattr(stat, 'st_%s' % args.time) | |
age = time.time() - xtime | |
if age >= args.error: | |
print('ERROR %s is too old %d s' % (args.path, age)) | |
return 2 | |
if age >= args.warning: | |
print('WARNING %s is too old %d s' % (args.path, age)) | |
return 1 | |
print('OK %s is %d s old' % (args.path, age)) | |
return 0 | |
if __name__ == '__main__': | |
code = main() | |
sys.exit(code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment