40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""
|
|
Usage: certo [-v] [-j] <hostnames>... [-d DAYS|--days-to-expiration=DAYS] [-t SECONDS|--timeout=SECONDS]
|
|
|
|
Options:
|
|
-v Increase verbosity [default: False]
|
|
-j Output in JSON format [default: False]
|
|
-d DAYS --days-to-expiration=DAYS Warn about impending expiration if within DAYS of the cert's notAfter [default: 5]
|
|
-t SECONDS --timeout=SECONDS Timeout for SSL Handshake [default: 5]
|
|
"""
|
|
import logging
|
|
|
|
from docopt import docopt
|
|
|
|
from certo.checks.hostname import check_host_certificate_expiration
|
|
from certo.output import default_output, json_output
|
|
|
|
if __name__ == "__main__":
|
|
args = docopt(__doc__)
|
|
|
|
output_as_json = args.get("-j")
|
|
if args.get("-v"):
|
|
logging.getLogger().setLevel(logging.INFO)
|
|
hostnames = args.get("<hostnames>")
|
|
days_to_expiration = int(args.get("--days-to-expiration"))
|
|
|
|
results = []
|
|
|
|
for hs in hostnames:
|
|
logging.info(f"Getting CERT from {hs}")
|
|
results.append(check_host_certificate_expiration(hs, days_to_expiration))
|
|
|
|
failed = list(r for r in results if not r.check_successful)
|
|
|
|
if output_as_json:
|
|
print(json_output(results))
|
|
else:
|
|
print(default_output(results))
|
|
|
|
exit(len(failed))
|