add file exists check
This commit is contained in:
@@ -4,6 +4,7 @@ import subprocess
|
||||
import datetime
|
||||
import argparse
|
||||
import enum
|
||||
import os
|
||||
import sys
|
||||
from email.utils import parsedate_to_datetime
|
||||
|
||||
@@ -50,31 +51,36 @@ if __name__ == '__main__':
|
||||
message = "Plugin failed"
|
||||
perfdata = {}
|
||||
|
||||
try:
|
||||
expiry_date = get_expiry_date(args.file)
|
||||
|
||||
|
||||
perfdata["expires_in"] = (expiry_date - datetime.datetime.now(expiry_date.tzinfo)).days
|
||||
|
||||
if is_expired(args.file, 0):
|
||||
message = f"Expired on {expiry_date}"
|
||||
status = Status.CRITICAL
|
||||
|
||||
elif is_expired(args.file, args.critical_threshold):
|
||||
message = f"Will expire on {expiry_date}"
|
||||
status = Status.CRITICAL
|
||||
|
||||
elif is_expired(args.file, args.warning_threshold):
|
||||
message = f"Will expire on {expiry_date}"
|
||||
status = Status.WARNING
|
||||
|
||||
else:
|
||||
message = f"Will expire on {expiry_date}"
|
||||
status = Status.OK
|
||||
|
||||
except Exception as e:
|
||||
message = f"Failed: {e}"
|
||||
if not os.path.isfile(args.file):
|
||||
status = Status.UNKNOWN
|
||||
message = "File not found"
|
||||
|
||||
else:
|
||||
try:
|
||||
expiry_date = get_expiry_date(args.file)
|
||||
|
||||
|
||||
perfdata["expires_in"] = (expiry_date - datetime.datetime.now(expiry_date.tzinfo)).days
|
||||
|
||||
if is_expired(args.file, 0):
|
||||
message = f"Expired on {expiry_date}"
|
||||
status = Status.CRITICAL
|
||||
|
||||
elif is_expired(args.file, args.critical_threshold):
|
||||
message = f"Will expire on {expiry_date}"
|
||||
status = Status.CRITICAL
|
||||
|
||||
elif is_expired(args.file, args.warning_threshold):
|
||||
message = f"Will expire on {expiry_date}"
|
||||
status = Status.WARNING
|
||||
|
||||
else:
|
||||
message = f"Will expire on {expiry_date}"
|
||||
status = Status.OK
|
||||
|
||||
except Exception as e:
|
||||
message = f"Failed: {e}"
|
||||
status = Status.UNKNOWN
|
||||
|
||||
perfdata_str = ""
|
||||
for key,value in perfdata.items():
|
||||
|
||||
Reference in New Issue
Block a user