Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[http_check] Adding a days_critical to the SSL certificate expiration feature #2087

Merged
merged 1 commit into from
Nov 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions checks.d/http_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def report_as_service_check(self, sc_name, status, instance, msg=None):

def check_cert_expiration(self, instance, timeout, instance_ca_certs):
warning_days = int(instance.get('days_warning', 14))
critical_days = int(instance.get('days_critical', 7))
url = instance.get('url')

o = urlparse(url)
Expand All @@ -402,6 +403,10 @@ def check_cert_expiration(self, instance, timeout, instance_ca_certs):
if days_left.days < 0:
return Status.DOWN, "Expired by {0} days".format(days_left.days)

elif days_left.days < critical_days:
return Status.CRITICAL, "This cert TTL is critical: only {0} days before it expires"\
.format(days_left.days)

elif days_left.days < warning_days:
return Status.WARNING, "This cert is almost expired, only {0} days left"\
.format(days_left.days)
Expand Down
4 changes: 3 additions & 1 deletion checks/network_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
class Status:
DOWN = "DOWN"
WARNING = "WARNING"
CRITICAL = "CRITICAL"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that it makes much sense to add a new "CRITICAL" status here. These statuses seem to have been primarily used before we had actual service checks, and service checks now only have 3 states (OK, WARNING, CRITICAL).

So I would use a Status.DOWN status for this new threshold.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olivielpeau the thing is I don't like setting DOWN when it's not really true. I create that redundant state for better code readability - if you disagree I'm happy to change it back again.

UP = "UP"


Expand All @@ -33,7 +34,8 @@ class NetworkCheck(AgentCheck):
STATUS_TO_SERVICE_CHECK = {
Status.UP : AgentCheck.OK,
Status.WARNING : AgentCheck.WARNING,
Status.DOWN : AgentCheck.CRITICAL
Status.CRITICAL : AgentCheck.CRITICAL,
Status.DOWN : AgentCheck.CRITICAL,
}

"""
Expand Down
4 changes: 3 additions & 1 deletion conf.d/http_check.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ instances:
# The (optional) ssl_expire will instruct the check
# to create a service check that checks the expiration of the
# ssl certificate. Allow for a warning to occur when x days are
# left in the certificate.
# left in the certificate, and alternatively raise a critical
# warning if the certificate is y days from the expiration date.
# The SSL certificate will always be validated for this additional
# service check regardless of the value of disable_ssl_validation
#
# check_certificate_expiration: true
# days_warning: 14
# days_critical: 7

# The (optional) headers parameter allows you to send extra headers
# with the request. This is useful for explicitly specifying the host
Expand Down
26 changes: 21 additions & 5 deletions tests/checks/integration/test_http_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,29 @@
'url': 'https://github.com:443',
'timeout': 1,
'check_certificate_expiration': True,
'days_warning': 14
'days_warning': 14,
'days_critical': 7
}, {
'name': 'cert_exp_soon',
'url': 'https://google.com',
'timeout': 1,
'check_certificate_expiration': True,
'days_warning': 9999
'days_warning': 9999,
'days_critical': 7
}, {
'name': 'cert_critical',
'url': 'https://google.com',
'timeout': 1,
'check_certificate_expiration': True,
'days_warning': 9999,
'days_critical': 9999
}, {
'name': 'conn_error',
'url': 'https://thereisnosuchlink.com',
'timeout': 1,
'check_certificate_expiration': True,
'days_warning': 14
'days_warning': 14,
'days_critical': 7
}
]
}
Expand All @@ -80,7 +90,8 @@
'url': 'https://github.com',
'timeout': 1,
'check_certificate_expiration': True,
'days_warning': 14
'days_warning': 14,
'days_critical': 7
},
]
}
Expand All @@ -91,7 +102,8 @@
'url': 'https://github.com',
'timeout': 1,
'check_certificate_expiration': True,
'days_warning': 14
'days_warning': 14,
'days_critical': 7
},
]
}
Expand Down Expand Up @@ -203,6 +215,10 @@ def test_check_ssl(self):
self.assertServiceCheckOK("http.can_connect", tags=tags)
self.assertServiceCheckWarning("http.ssl_cert", tags=tags)

tags = ['url:https://google.com', 'instance:cert_critical']
self.assertServiceCheckOK("http.can_connect", tags=tags)
self.assertServiceCheckCritical("http.ssl_cert", tags=tags)

tags = ['url:https://thereisnosuchlink.com', 'instance:conn_error']
self.assertServiceCheckCritical("http.can_connect", tags=tags)
self.assertServiceCheckCritical("http.ssl_cert", tags=tags)
Expand Down