Defined Type: sensu::handler

Defined in:
manifests/handler.pp

Summary

sensu::handler

Overview

Defines Sensu handlers

Parameters:

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

    Whether the check should be present or not

  • type (Enum['pipe','tcp','udp','amqp','set','transport']) (defaults to: 'pipe')

    Type of handler

  • command (Optional[String]) (defaults to: undef)

    Command to run as the handler when type=pipe

  • handlers (Optional[Array]) (defaults to: undef)

    Handlers to use when type=set

  • severities (Array) (defaults to: ['ok', 'warning', 'critical', 'unknown'])

    Severities handler is valid for

  • exchange (Optional[Hash]) (defaults to: undef)

    Exchange information used when type=amqp Keys: host, port

  • pipe (Optional[Hash]) (defaults to: undef)

    Pipe information used when type=transport Keys: name, type, options

  • socket (Optional[Hash]) (defaults to: undef)

    Socket information when type=tcp or type=udp Keys: host, port

  • filters (Array) (defaults to: [])

    Filter commands to apply

  • source (Optional[Pattern[/^puppet:\/\//]]) (defaults to: undef)

    Source of the puppet handler

  • install_path (String) (defaults to: $::osfamily)

    Path to install the handler

  • config (Optional[Hash]) (defaults to: undef)

    Handler specific config

  • timeout (Optional[Integer]) (defaults to: undef)

    Handler timeout configuration

  • handle_flapping (Boolean) (defaults to: false)

    If events in the flapping state should be handled.

  • handle_silenced (Boolean) (defaults to: false)

    If events in the silenced state should be handled.

  • mutator (Any) (defaults to: undef)

    The handle mutator. Valid values: Any kind of data which can be added to the handler mutator.

  • subdue (Any) (defaults to: undef)

    The handle subdue. Valid values: Any kind of data which can be added to the handler subdue.



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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'manifests/handler.pp', line 44

define sensu::handler(
  Enum['present','absent'] $ensure = 'present',
  Enum['pipe','tcp','udp','amqp','set','transport'] $type = 'pipe',
  Optional[String] $command        = undef,
  Optional[Array] $handlers        = undef,
  Array $severities      = ['ok', 'warning', 'critical', 'unknown'],
  Optional[Hash] $exchange         = undef,
  Optional[Hash] $pipe             = undef,
  Any $mutator                     = undef,
  Optional[Hash] $socket           = undef,
  Array $filters                   = [],
  # Used to install the handler
  Optional[Pattern[/^puppet:\/\//]] $source = undef,
  String $install_path             = $::osfamily ? {
    'windows' => 'C:/opt/sensu/handlers',
    default   => '/etc/sensu/handlers',
  },
  # Handler specific config
  Optional[Hash] $config           = undef,
  Any $subdue                      = undef,
  Optional[Integer] $timeout       = undef,
  Boolean $handle_flapping         = false,
  Boolean $handle_silenced         = false,
) {

  if $subdue{ fail('Subdue at handler is deprecated since sensu 0.26. See https://sensuapp.org/docs/0.26/overview/changelog.html#core-v0-26-0')}


  if $type == 'pipe' and $ensure != 'absent' and !$command and !$source and !$mutator {
    fail('command must be set with type pipe')
  }
  if ($type == 'tcp' or $type == 'udp') and !$socket {
    fail("socket must be set with type ${type}")
  }

  if $type == 'amqp' and !$exchange {
    fail('exchange must be set with type amqp')
  }

  if $type == 'transport' and !$pipe {
    fail('pipe must be set with type transport')
  }

  if $type == 'set' and !$handlers {
    fail('handlers must be set with type set')
  }

  if $::sensu::server {
    $notify_services = Class['sensu::server::service']
  } else {
    $notify_services = []
  }

  $file_ensure = $ensure ? {
    'absent' => 'absent',
    default  => 'file'
  }

  if $source {
    $handler = "${install_path}/${basename($source)}"

    ensure_resource('file', $handler, {
      ensure => $file_ensure,
      owner  => $::sensu::user,
      group  => $::sensu::group,
      mode   => $::sensu::dir_mode,
      source => $source,
    })

    $command_real = $command ? {
      undef   => $handler,
      default => $command,
    }
  } else {
    $command_real = $command
  }

  # handler configuration may contain "secrets"
  file { "${::sensu::conf_dir}/handlers/${name}.json":
    ensure => $file_ensure,
    owner  => $::sensu::user,
    group  => $::sensu::group,
    mode   => $::sensu::file_mode,
    before => Sensu_handler[$name],
  }

  sensu_handler { $name:
    ensure          => $ensure,
    base_path       => "${::sensu::conf_dir}/handlers",
    type            => $type,
    command         => $command_real,
    handlers        => $handlers,
    severities      => $severities,
    exchange        => $exchange,
    pipe            => $pipe,
    socket          => $socket,
    mutator         => $mutator,
    filters         => $filters,
    config          => $config,
    timeout         => $timeout,
    handle_flapping => $handle_flapping,
    handle_silenced => $handle_silenced,
    notify          => $notify_services,
    require         => File["${::sensu::conf_dir}/handlers"],
  }
}