Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add file age check #160

wants to merge 3 commits into from

Conversation

meikomeik
Copy link
Member

This check was written by Jon Dawson.

args = get_parser().parse_args()

if not args.path:
print('UNKNOWN - no path supplied')
Copy link
Contributor

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?

print('UNKNOWN - no path supplied')
exit(3)

age = 0
Copy link
Contributor

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.

try:
age = time.time() - os.path.getmtime(args.path)
except OSError:
print('UNKNOWN - {} is not present or no permissions'.format(
Copy link
Contributor

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, ...
)

status = 'OK'
code = 0

if age > args.critical*60:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: Spaces around operators.

if age > args.critical*60:
code = 2
status = 'CRITICAL'
elif age > args.warning*60:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: Spaces around operators.

'--warning', '-w',
help='warning threshold in minutes for file age',
default=30, type=int)
parser.add_argument(
Copy link
Contributor

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, ...
)

parser.add_argument('--path', '-p', help='path of file to check')
parser.add_argument(
'--warning', '-w',
help='warning threshold in minutes for file age',
Copy link
Contributor

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.

default=30, type=int)
parser.add_argument(
'--critical', '-c',
help='critical threshold in minutes for file age',
Copy link
Contributor

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 Show resolved Hide resolved
src/check_file_age.py Outdated Show resolved Hide resolved
Copy link
Contributor

@TheFRedFox TheFRedFox left a 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. ;)

Comment on lines +40 to +41
'--path', '-p',
required=True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be just:

Suggested change
'--path', '-p',
required=True,
'--path', '-p', required=True,

Comment on lines +45 to +46
'--warning', '-w',
default=30, type=int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'--warning', '-w',
default=30, type=int,
'--warning', '-w', type=int, default=30,

Comment on lines +50 to +51
'--critical', '-c',
default=60, type=int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'--critical', '-c',
default=60, type=int,
'--critical', '-c', type=int, default=60,

Comment on lines +66 to +68
print(
'UNKNOWN - {} is not present or no permissions'.format(args.path)
)
Copy link
Contributor

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:

Suggested change
print(
'UNKNOWN - {} is not present or no permissions'.format(args.path)
)
print(
'UNKNOWN - {} is not present or no permissions'.format(args.path)
)

Comment on lines +82 to +84
'{} - {} last changed {} minutes ago'.format(
status, args.path, round(age / 60)
)
Copy link
Contributor

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:

Suggested change
'{} - {} 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)
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants