-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add file age check #160
base: master
Are you sure you want to change the base?
Add file age check #160
Conversation
src/check_file_age.py
Outdated
args = get_parser().parse_args() | ||
|
||
if not args.path: | ||
print('UNKNOWN - no path supplied') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not making the argument required then?
src/check_file_age.py
Outdated
print('UNKNOWN - no path supplied') | ||
exit(3) | ||
|
||
age = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to neither explicitly initialise nor declare it. age
will be available outside the try
scope too.
src/check_file_age.py
Outdated
try: | ||
age = time.time() - os.path.getmtime(args.path) | ||
except OSError: | ||
print('UNKNOWN - {} is not present or no permissions'.format( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply Multiline style code:
func(
argument_1, argument_2,
'some small string format'.format(...),
'some bigger bigger bigger string format'
.format(...)
even_more_arguments, ...
)
src/check_file_age.py
Outdated
status = 'OK' | ||
code = 0 | ||
|
||
if age > args.critical*60: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: Spaces around operators.
src/check_file_age.py
Outdated
if age > args.critical*60: | ||
code = 2 | ||
status = 'CRITICAL' | ||
elif age > args.warning*60: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: Spaces around operators.
src/check_file_age.py
Outdated
'--warning', '-w', | ||
help='warning threshold in minutes for file age', | ||
default=30, type=int) | ||
parser.add_argument( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apply Multiline style code:
func(
argument_1, argument_2,
'some small string format'.format(...),
'some bigger bigger bigger string format'
.format(...)
even_more_arguments, ...
)
src/check_file_age.py
Outdated
parser.add_argument('--path', '-p', help='path of file to check') | ||
parser.add_argument( | ||
'--warning', '-w', | ||
help='warning threshold in minutes for file age', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make help
being the last argument standing alone.
src/check_file_age.py
Outdated
default=30, type=int) | ||
parser.add_argument( | ||
'--critical', '-c', | ||
help='critical threshold in minutes for file age', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make help
being the last argument standing alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just minor things except of the sys.exit
one. Already approving though. Changes would be appreciated. ;)
'--path', '-p', | ||
required=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be just:
'--path', '-p', | |
required=True, | |
'--path', '-p', required=True, |
'--warning', '-w', | ||
default=30, type=int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'--warning', '-w', | |
default=30, type=int, | |
'--warning', '-w', type=int, default=30, |
'--critical', '-c', | ||
default=60, type=int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'--critical', '-c', | |
default=60, type=int, | |
'--critical', '-c', type=int, default=60, |
print( | ||
'UNKNOWN - {} is not present or no permissions'.format(args.path) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We rather go with this multiline style:
print( | |
'UNKNOWN - {} is not present or no permissions'.format(args.path) | |
) | |
print( | |
'UNKNOWN - {} is not present or no permissions'.format(args.path) | |
) |
'{} - {} last changed {} minutes ago'.format( | ||
status, args.path, round(age / 60) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try if you like this way more:
'{} - {} last changed {} minutes ago'.format( | |
status, args.path, round(age / 60) | |
) | |
'{} - {} last changed {} minutes ago' | |
.format(status, args.path, round(age / 60)) |
status, args.path, round(age / 60) | ||
) | ||
) | ||
exit(code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use sys.exit
. quit
and exit
are rather used for interactive shells. You will also need to import sys for that.
This check was written by Jon Dawson.