Initial commit: Basic CLI and checks
Certo supports polling one or several hostnames. Output can be human-readable or JSON.
This commit is contained in:
36
certo/__main__.py
Normal file
36
certo/__main__.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
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 pprint import pprint
|
||||
|
||||
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))
|
||||
|
||||
if output_as_json:
|
||||
print(json_output(results))
|
||||
else:
|
||||
print(default_output(results))
|
||||
Reference in New Issue
Block a user