Add option to output failures only
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
"""
|
"""
|
||||||
Usage:
|
Usage:
|
||||||
certo [-vj] [-d DAYS|--days-to-expiration=DAYS] [-t SECONDS|--timeout=SECONDS] <hostnames>...
|
certo [-vjf] [-d DAYS|--days-to-expiration=DAYS] [-t SECONDS|--timeout=SECONDS] <hostnames>...
|
||||||
certo -h | --help
|
certo -h | --help
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-h --help Show this help.
|
-h --help Show this help.
|
||||||
-j Output in JSON format [default: False].
|
-j Output in JSON format [default: False].
|
||||||
-v Increase verbosity [default: False].
|
-v Increase verbosity [default: False].
|
||||||
|
-f --failonly Output failures only [default: False]
|
||||||
-d DAYS --days-to-expiration=DAYS Warn about near expiration if within DAYS of the cert's notAfter [default: 5].
|
-d DAYS --days-to-expiration=DAYS Warn about near expiration if within DAYS of the cert's notAfter [default: 5].
|
||||||
-t SECONDS --timeout=SECONDS Timeout for SSL Handshake [default: 5].
|
-t SECONDS --timeout=SECONDS Timeout for SSL Handshake [default: 5].
|
||||||
"""
|
"""
|
||||||
@@ -23,6 +24,7 @@ async def main():
|
|||||||
args = docopt(__doc__)
|
args = docopt(__doc__)
|
||||||
|
|
||||||
output_as_json = args.get("-j")
|
output_as_json = args.get("-j")
|
||||||
|
output_passes = not args.get("--failonly")
|
||||||
if args.get("-v"):
|
if args.get("-v"):
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
hostnames = args.get("<hostnames>")
|
hostnames = args.get("<hostnames>")
|
||||||
@@ -30,9 +32,9 @@ async def main():
|
|||||||
|
|
||||||
# @todo factory
|
# @todo factory
|
||||||
if output_as_json:
|
if output_as_json:
|
||||||
reporter = JSONReporter()
|
reporter = JSONReporter(output_passes)
|
||||||
else:
|
else:
|
||||||
reporter = DefaultReporter()
|
reporter = DefaultReporter(output_passes)
|
||||||
|
|
||||||
jobs = {
|
jobs = {
|
||||||
check_host_certificate_expiration(hs, days_to_expiration) for hs in hostnames
|
check_host_certificate_expiration(hs, days_to_expiration) for hs in hostnames
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import json
|
|||||||
|
|
||||||
|
|
||||||
class CheckReporter:
|
class CheckReporter:
|
||||||
def __init__(self):
|
def __init__(self, output_passes):
|
||||||
self.checks = list()
|
self.checks = list()
|
||||||
|
self.output_passes = output_passes
|
||||||
|
|
||||||
def append(self, check):
|
def append(self, check):
|
||||||
self.checks.append(check)
|
self.checks.append(check)
|
||||||
@@ -35,7 +36,7 @@ class JSONReporter(CheckReporter):
|
|||||||
list(
|
list(
|
||||||
map(
|
map(
|
||||||
lambda check: JSONReporter.__make_check_serialisable(check),
|
lambda check: JSONReporter.__make_check_serialisable(check),
|
||||||
self.checks,
|
self.checks if self.output_passes else self.failed(),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
indent=4,
|
indent=4,
|
||||||
@@ -45,6 +46,8 @@ class JSONReporter(CheckReporter):
|
|||||||
class DefaultReporter(CheckReporter):
|
class DefaultReporter(CheckReporter):
|
||||||
def append(self, check):
|
def append(self, check):
|
||||||
super().append(check)
|
super().append(check)
|
||||||
|
if check.check_successful and not self.output_passes:
|
||||||
|
return
|
||||||
result = f"[{'PASS' if check.check_successful else 'FAIL'}] Check host {check.hostname}"
|
result = f"[{'PASS' if check.check_successful else 'FAIL'}] Check host {check.hostname}"
|
||||||
if check.debug:
|
if check.debug:
|
||||||
result += f" - {check.debug}"
|
result += f" - {check.debug}"
|
||||||
|
|||||||
Reference in New Issue
Block a user