Defined Type: consul::check

Defined in:
manifests/check.pp

Summary

Sets up a Consul healthcheck

Overview

Parameters:

  • ensure (Enum['absent', 'present']) (defaults to: present)

    Define availability of check. Use ‘absent’ to remove existing checks

  • http (Optional) (defaults to: undef)

    HTTP endpoint for the service healthcheck

  • id (String[1]) (defaults to: $title)

    The id for the check (defaults to $title)

  • interval (Optional) (defaults to: undef)

    Value in seconds for the interval between runs of the check

  • notes (Optional) (defaults to: undef)

    Human readable description of the check

  • script (Optional) (defaults to: undef)

    Full path to the location of the healthcheck script. Must be nagios compliant with regards to the return codes. This parameter is deprecated in Consul 1.0.0, see github.com/hashicorp/consul/issues/3509.

  • args (Optional) (defaults to: undef)

    Arguments to be ‘exec`ed for the healthcheck script.

  • service_id (Optional) (defaults to: undef)

    An optional service_id to match this check against

  • status (Optional) (defaults to: undef)

    The default state of the check when it is registered against a consul agent. Should be either “critical” or “passing”

  • tcp (Optional) (defaults to: undef)

    The IP/hostname and port for the service healthcheck. Should be in ‘hostname:port’ format.

  • grpc (Optional) (defaults to: undef)

    GRPC endpoint for the service healthcheck

  • timeout (Optional) (defaults to: undef)

    A timeout value for HTTP request only

  • token (Optional) (defaults to: undef)

    ACL token for interacting with the catalog (must be ‘management’ type)

  • ttl (Optional) (defaults to: undef)

    Value in seconds before the http endpoint considers a failing healthcheck to be “HARD” down.

  • success_before_passing (Optional) (defaults to: undef)

    Value may be set to become check passing only after a specified number of consecutive checks return passing

  • failures_before_critical (Optional) (defaults to: undef)

    Value may be set to become check critical only after a specified number of consecutive checks return critical

See Also:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'manifests/check.pp', line 25

define consul::check (
  Enum['absent', 'present'] $ensure  = present,
  Optional $http                     = undef,
  String[1] $id                      = $title,
  Optional $interval                 = undef,
  Optional $notes                    = undef,
  Optional $script                   = undef,
  Optional $args                     = undef,
  Optional $service_id               = undef,
  Optional $status                   = undef,
  Optional $tcp                      = undef,
  Optional $grpc                     = undef,
  Optional $timeout                  = undef,
  Optional $token                    = undef,
  Optional $ttl                      = undef,
  Optional $success_before_passing   = undef,
  Optional $failures_before_critical = undef,
) {
  include consul

  $basic_hash = {
    'id'                       => $id,
    'name'                     => $name,
    'ttl'                      => $ttl,
    'http'                     => $http,
    'script'                   => $script,
    'args'                     => $args,
    'tcp'                      => $tcp,
    'grpc'                     => $grpc,
    'interval'                 => $interval,
    'timeout'                  => $timeout,
    'service_id'               => $service_id,
    'notes'                    => $notes,
    'token'                    => $token,
    'status'                   => $status,
    'success_before_passing'   => $success_before_passing,
    'failures_before_critical' => $failures_before_critical,
  }

  $check_hash = {
    check => $basic_hash.filter |$key, $val| { $val =~ NotUndef },
  }

  consul::validate_checks($check_hash[check])

  $escaped_id = regsubst($id,'\/','_','G')
  file { "${consul::config_dir}/check_${escaped_id}.json":
    ensure  => $ensure,
    owner   => $consul::user_real,
    group   => $consul::group_real,
    mode    => $consul::config_mode,
    content => consul::sorted_json($check_hash, $consul::pretty_config, $consul::pretty_config_indent),
    notify  => Class['consul::reload_service'],
  }
}