Skip to content

HTTP


Whenever you need to make HTTP requests, the base class provides a convenience member that has the same interface as the popular requests library and ensures consistent behavior across all integrations.

The wrapper automatically parses and uses configuration from the instance, init_config, and Agent config. Also, this is only done once during initialization and cached to reduce the overhead of every call.

For example, to make a GET request you would use:

response = self.http.get(url)

and the wrapper will pass the right things to requests. All methods accept optional keyword arguments like stream, etc.

Any method-level option will override configuration. So for example if tls_verify was set to false and you do self.http.get(url, verify=True), then SSL certificates will be verified on that particular request. You can use the keyword argument persist to override persist_connections.

There is also support for non-standard or legacy configurations with the HTTP_CONFIG_REMAPPER class attribute. For example:

class MyCheck(AgentCheck):
    HTTP_CONFIG_REMAPPER = {
        'disable_ssl_validation': {
            'name': 'tls_verify',
            'default': False,
            'invert': True,
        },
        ...
    }
    ...

Support for Unix socket is provided via requests-unixsocket and allows making UDS requests on the unix:// scheme (not supported on Windows until Python adds support for AF_UNIX, see ticket):

url = 'unix:///var/run/docker.sock'
response = self.http.get(url)

Options

Some options can be set globally in init_config (with instances taking precedence). For complete documentation of every option, see the associated configuration templates for the instances and init_config sections.

  • auth_token
  • auth_type
  • aws_host
  • aws_region
  • aws_service
  • connect_timeout
  • extra_headers
  • headers
  • kerberos_auth
  • kerberos_cache
  • kerberos_delegate
  • kerberos_force_initiate
  • kerberos_hostname
  • kerberos_keytab
  • kerberos_principal
  • log_requests
  • ntlm_domain
  • password
  • persist_connections
  • proxy
  • read_timeout
  • skip_proxy
  • tls_ca_cert
  • tls_cert
  • tls_use_host_header
  • tls_ignore_warning
  • tls_private_key
  • tls_verify
  • timeout
  • use_legacy_auth_encoding
  • username

Future

  • Support for configuring cookies! Since they can be set globally, per-domain, and even per-path, the configuration may be complex if not thought out adequately. We'll discuss options for what that might look like. Only our spark and cisco_aci checks currently set cookies, and that is based on code logic, not configuration.

Last update: September 23, 2020