Treat ConnectionRefusedError like SSLCertVerificationError
This commit is contained in:
parent
ad04443928
commit
70b68108c7
|
@ -16,17 +16,17 @@ args = ap.parse_args()
|
||||||
now = time.time()
|
now = time.time()
|
||||||
report0 = []
|
report0 = []
|
||||||
|
|
||||||
with socket.create_connection((args.hostname, args.port)) as sock:
|
try:
|
||||||
|
with socket.create_connection((args.hostname, args.port)) as sock:
|
||||||
context = ssl.create_default_context()
|
context = ssl.create_default_context()
|
||||||
try:
|
|
||||||
with context.wrap_socket(sock, server_hostname=args.hostname) as ssock:
|
with context.wrap_socket(sock, server_hostname=args.hostname) as ssock:
|
||||||
cert = ssock.getpeercert()
|
cert = ssock.getpeercert()
|
||||||
not_after = ssl.cert_time_to_seconds(cert["notAfter"])
|
not_after = ssl.cert_time_to_seconds(cert["notAfter"])
|
||||||
delta = not_after - now
|
delta = not_after - now
|
||||||
except ssl.SSLCertVerificationError as e:
|
except (ssl.SSLCertVerificationError, ConnectionRefusedError) as e:
|
||||||
print("got error %s; setting delta to 0", e)
|
print("got error %s; setting delta to 0" % e)
|
||||||
delta = 0
|
delta = 0
|
||||||
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta })
|
report0.append({ "measure": "tls_cert_ttl", "unit": "s", "value": delta })
|
||||||
|
|
||||||
report = [
|
report = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue