Skip to content

Commit

Permalink
Merge pull request #3 from dnmvisser/dv_api_errors_as_unknown
Browse files Browse the repository at this point in the history
Classify API errors as UNKNOWN for easy filtering
  • Loading branch information
dnmvisser committed Nov 20, 2020
2 parents 24d0dbd + 18022c2 commit 39cdb47
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions nagios-ssllabs-rating.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def report(results):
ok_msg = []
warn_msg = []
crit_msg = []
unknown_msg = []

# Ensure tempdir exists
from pathlib import Path
Expand Down Expand Up @@ -163,10 +164,12 @@ def report(results):
# Report results
report(results)
else:
# https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#error-response-status-codes
# FIXME This should never happen, but we should be able to handle it
# Usually resource issues at the SSL Labs API side.
# This happens rarely, but in case it does, they're transient.
# We classify them as unknown, which allows us to disable notifications for it,
# because they're not a problem with the service being checked.
debug_info = "\n\nHTTP response headers:\n\n" + yaml.dump(response.headers, default_flow_style=False)
crit_msg.append("Received HTTP " + str(response.status_code) + " from SSL Labs API" +
unknown_msg.append("The SSL Labs API responded with HTTP " + str(response.status_code) +
"\nSee https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md#error-response-status-codes" +
debug_info)

Expand All @@ -177,7 +180,9 @@ def report(results):
nagios_exit("UNKNOWN: {0}.".format(e), 3)

# Exit with accumulated message(s)
if crit_msg:
if unknown_msg:
nagios_exit("UNKNOWN: " + ' '.join(unknown_msg), 3)
elif crit_msg:
nagios_exit("CRITICAL: " + ' '.join(crit_msg + warn_msg), 2)
elif warn_msg:
nagios_exit("WARNING: " + ' '.join(warn_msg), 1)
Expand Down

0 comments on commit 39cdb47

Please sign in to comment.