Source code for lighthouse.checks.http
import logging
from six.moves import http_client as client
from lighthouse import check
logger = logging.getLogger(__name__)
[docs]class HTTPCheck(check.Check):
"""
Simple check for HTTP services.
Pings a configured uri on the host. The check passes if the response
code is in the 2xx range.
"""
name = "http"
def __init__(self, *args, **kwargs):
super(HTTPCheck, self).__init__(*args, **kwargs)
self.uri = None
self.use_https = None
self.method = None
@classmethod
[docs] def validate_dependencies(cls):
"""
This check uses stdlib modules so dependencies are always present.
"""
return True
@classmethod
[docs] def validate_check_config(cls, config):
"""
Validates the http check config. The "uri" key is required.
"""
if "uri" not in config:
raise ValueError("Missing uri.")
[docs] def apply_check_config(self, config):
"""
Takes a validated config dictionary and sets the `uri`, `use_https`
and `method` attributes based on the config's contents.
"""
self.uri = config["uri"]
self.use_https = config.get("https", False)
self.method = config.get("method", "GET")