Puppet Class: sensu::package

Defined in:
manifests/package.pp

Summary

Installs Sensu packages

Overview

Installs the Sensu packages

Parameters:

  • conf_dir (Optional[String]) (defaults to: $::sensu::conf_dir)

    The default configuration directory.

  • confd_dir (Variant[String,Array,Undef]) (defaults to: $::sensu::confd_dir)

    Additional directories to load configuration snippets from.

  • heap_size (Variant[Undef,Integer,Pattern[/^(\d+)/]]) (defaults to: $::sensu::heap_size)

    Value of the HEAP_SIZE environment variable. Note: This has no effect on sensu-core.

  • config_file (Variant[Stdlib::Absolutepath,Undef]) (defaults to: $::sensu::config_file)

    Value of the CONFIG_FILE environment variable.

  • deregister_handler (Optional[String]) (defaults to: $::sensu::deregister_handler)

    The handler to use when deregistering a client on stop.

  • deregister_on_stop (Optional[Boolean]) (defaults to: $::sensu::deregister_on_stop)

    Whether the sensu client should deregister from the API on service stop

  • gem_path (Optional[String]) (defaults to: $::sensu::gem_path)

    Paths to add to GEM_PATH if we need to look for different dirs.

  • init_stop_max_wait (Variant[Undef,Integer,Pattern[/^(\d+)$/]]) (defaults to: $::sensu::init_stop_max_wait)

    Number of seconds to wait for the init stop script to run

  • log_dir (Optional[String]) (defaults to: $::sensu::log_dir)

    Sensu log directory to be used Valid values: Any valid log directory path, accessible by the sensu user

  • log_level (Optional[String]) (defaults to: $::sensu::log_level)

    Sensu log level to be used Valid values: debug, info, warn, error, fatal

  • path (Optional[String]) (defaults to: $::sensu::path)

    Used to set PATH in /etc/default/sensu

  • env_vars (Optional[Hash[String[1], Variant[String, Boolean, Integer]]]) (defaults to: $::sensu::env_vars)

    Additional environment variables for /etc/default/sensu

  • rubyopt (Optional[String]) (defaults to: $::sensu::rubyopt)

    Ruby opts to be passed to the sensu services

  • use_embedded_ruby (Optional[Boolean]) (defaults to: $::sensu::use_embedded_ruby)

    If the embedded ruby should be used, e.g. to install the sensu-plugin gem. This value is overridden by a defined sensu_plugin_provider. Note, the embedded ruby should always be used to provide full compatibility. Using other ruby runtimes, e.g. the system ruby, is not recommended.



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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'manifests/package.pp', line 41

class sensu::package (
  Optional[String] $conf_dir            = $::sensu::conf_dir,
  Variant[String,Array,Undef] $confd_dir = $::sensu::confd_dir,
  Variant[Undef,Integer,Pattern[/^(\d+)/]] $heap_size = $::sensu::heap_size,
  Variant[Stdlib::Absolutepath,Undef] $config_file = $::sensu::config_file,
  Optional[String] $deregister_handler  = $::sensu::deregister_handler,
  Optional[Boolean] $deregister_on_stop = $::sensu::deregister_on_stop,
  Optional[String] $gem_path            = $::sensu::gem_path,
  Variant[Undef,Integer,Pattern[/^(\d+)$/]] $init_stop_max_wait = $::sensu::init_stop_max_wait,
  Optional[String] $log_dir             = $::sensu::log_dir,
  Optional[String] $log_level           = $::sensu::log_level,
  Optional[String] $path                = $::sensu::path,
  Optional[Hash[String[1], Variant[String, Boolean, Integer]]] $env_vars = $::sensu::env_vars,
  Optional[String] $rubyopt             = $::sensu::rubyopt,
  Optional[Boolean] $use_embedded_ruby  = $::sensu::use_embedded_ruby,
) {

  case $::osfamily {
    'Darwin': {
      $pkg_provider = 'pkgdmg'
      $pkg_source   = '/tmp/sensu-installer.dmg'
      $pkg_require  = "Remote_file[${pkg_source}]"
      $pkg_title    = 'sensu'
      $pkg_version  = $::sensu::version
      $service_name = 'org.sensuapp.sensu-client'

      remote_file { $pkg_source:
        ensure => present,
        source => "https://repositories.sensuapp.org/osx/${::macosx_productversion_major}/x86_64/sensu-${pkg_version}.dmg",
      }
    }

    'Debian': {
      $pkg_title    = 'sensu'
      $pkg_name     = 'sensu'
      $pkg_version  = $::sensu::version
      $pkg_source   = undef
      $pkg_provider = undef
      $service_name = 'sensu-client'

      if $::sensu::manage_repo {
        class { '::sensu::repo::apt': }
      }
      if $::sensu::manage_repo and $::sensu::install_repo {
        include ::apt
        $pkg_require = Class['apt::update']
      }
      else {
        $pkg_require = undef
      }
    }

    'RedHat': {
      $pkg_title = 'sensu'
      $pkg_name = 'sensu'
      $pkg_version = $::sensu::version
      $pkg_source = undef
      $pkg_provider = undef
      $service_name = 'sensu-client'

      if $::sensu::manage_repo {
        class { '::sensu::repo::yum': }
      }

      $pkg_require = undef
    }

    'windows': {
      $repo_require = undef

      # $pkg_version is passed to Package[sensu] { ensure }.  The Windows MSI
      # provider translates hyphens to dots, e.g. '0.29.0-11' maps to
      # '0.29.0.11' on the system.  This mapping is necessary to converge.
      $pkg_version = regsubst($::sensu::version, '-', '.')
      # The version used to construct the download URL.
      $pkg_url_version = $::sensu::version ? {
        'installed' => 'latest',
        default     => $::sensu::version,
      }
      # The title used for consistent relationships in the Puppet catalog
      $pkg_title = $::sensu::windows_package_title
      # The name used by the provider to compare to Windows Add/Remove programs.
      $pkg_name = $::sensu::windows_package_name
      $service_name = 'sensu-client'

      # The user can override the computation of the source URL.  This URL is
      # used with the remote_file resource, it is not used with the chocolatey
      # package provider.
      if $::sensu::windows_pkg_url {
        $pkg_url = $::sensu::windows_pkg_url
      } else {
        # The OS Release specific sub-folder
        $os_release = $facts['os']['release']['major']
        # e.g. '2012 R2' => '2012r2'
        $pkg_url_dir = regsubst($os_release, '^(\d+)\s*[rR](\d+)', '\\1r\\2')
        $pkg_arch = $facts['os']['architecture']
        $pkg_url = "${sensu::windows_repo_prefix}/${pkg_url_dir}/sensu-${pkg_url_version}-${pkg_arch}.msi"
      }

      if $::sensu::windows_package_provider == 'chocolatey' {
        $pkg_provider = 'chocolatey'
        if $::sensu::windows_choco_repo {
          $pkg_source = $::sensu::windows_choco_repo
        } else {
          $pkg_source = undef
        }
        $pkg_require = undef
      } else {
        # Use Puppet's default package provider
        $pkg_provider = undef
        # Where the MSI is downloaded to and installed from.
        $pkg_source = "C:\\Windows\\Temp\\sensu-${pkg_url_version}.msi"
        $pkg_require = "Remote_file[${pkg_title}]"

        # path matches Package[sensu] { source => $pkg_source }
        remote_file { $pkg_title:
          ensure   => present,
          path     => $pkg_source,
          source   => $pkg_url,
          checksum => $::sensu::package_checksum,
        }
      }
    }

    default: { fail("${::osfamily} not supported yet") }

  }

  case $::osfamily {
    'Darwin': {
      package { $pkg_title:
        ensure   => present,
        source   => $pkg_source,
        require  => $pkg_require,
        provider => $pkg_provider,
      }
    }
    default: {
      package { $pkg_title:
        ensure   => $pkg_version,
        name     => $pkg_name,
        source   => $pkg_source,
        require  => $pkg_require,
        provider => $pkg_provider,
      }
    }
  }

  if $::sensu::sensu_plugin_provider {
    $plugin_provider = $::sensu::sensu_plugin_provider
  } else {
    $plugin_provider = $::sensu::use_embedded_ruby ? {
      true    => 'sensu_gem',
      default => 'gem',
    }
  }

  if $plugin_provider =~ /gem/ and $::sensu::gem_install_options {
    package { $::sensu::sensu_plugin_name :
      ensure          => $::sensu::sensu_plugin_version,
      provider        => $plugin_provider,
      install_options => $::sensu::gem_install_options,
    }
  } else {
    package { $::sensu::sensu_plugin_name :
      ensure   => $::sensu::sensu_plugin_version,
      provider => $plugin_provider,
    }
  }

  if $::osfamily != 'windows' {
    $template_content = $::osfamily ? {
      'Darwin' => 'EMBEDDED_RUBY=true',
      default  => template("${module_name}/sensu.erb")
    }
    file { '/etc/default/sensu':
      ensure  => file,
      content => $template_content,
      owner   => '0',
      group   => '0',
      mode    => '0444',
      require => Package[$pkg_title],
    }
  }

  file { [ $conf_dir, "${conf_dir}/handlers", "${conf_dir}/checks", "${conf_dir}/filters", "${conf_dir}/extensions", "${conf_dir}/mutators", "${conf_dir}/contacts" ]:
    ensure  => directory,
    owner   => $::sensu::user,
    group   => $::sensu::group,
    mode    => $::sensu::dir_mode,
    purge   => $::sensu::_purge_config,
    recurse => true,
    force   => true,
    require => Package[$pkg_title],
  }

  if $::sensu::manage_handlers_dir {
    file { "${sensu::etc_dir}/handlers":
      ensure  => directory,
      mode    => $::sensu::dir_mode,
      owner   => $::sensu::user,
      group   => $::sensu::group,
      purge   => $::sensu::_purge_handlers,
      recurse => true,
      force   => true,
      require => Package[$pkg_title],
    }
  }

  file { ["${sensu::etc_dir}/extensions", "${sensu::etc_dir}/extensions/handlers"]:
    ensure  => directory,
    mode    => $::sensu::dir_mode,
    owner   => $::sensu::user,
    group   => $::sensu::group,
    purge   => $::sensu::_purge_extensions,
    recurse => true,
    force   => true,
    require => Package[$pkg_title],
  }

  if $::sensu::manage_mutators_dir {
    file { "${sensu::etc_dir}/mutators":
      ensure  => directory,
      mode    => $::sensu::dir_mode,
      owner   => $::sensu::user,
      group   => $::sensu::group,
      purge   => $::sensu::_purge_mutators,
      recurse => true,
      force   => true,
      require => Package[$pkg_title],
    }
  }

  if $::sensu::_manage_plugins_dir {
    file { "${sensu::etc_dir}/plugins":
      ensure  => directory,
      mode    => $::sensu::dir_mode,
      owner   => $::sensu::user,
      group   => $::sensu::group,
      purge   => $::sensu::_purge_plugins,
      recurse => true,
      force   => true,
      require => Package[$pkg_title],
    }
  }

  if $::sensu::spawn_limit {
    $spawn_config = { 'sensu' => { 'spawn' => { 'limit' => $::sensu::spawn_limit } } }
    $spawn_template = '<%= require "json"; JSON.pretty_generate(@spawn_config) + $/ %>'
    $spawn_ensure = 'file'
    $spawn_content = inline_template($spawn_template)
    if $::sensu::client and $::sensu::manage_services {
      $spawn_notify = [
        Service[$service_name],
        Class['sensu::server::service'],
      ]
    } elsif $::sensu::manage_services {
      $spawn_notify = [ Class['sensu::server::service'] ]
    } else {
      $spawn_notify = undef
    }
  } else {
    $spawn_ensure = undef
    $spawn_content = undef
    $spawn_notify = undef
  }

  file { "${sensu::etc_dir}/conf.d/spawn.json":
    ensure  => $spawn_ensure,
    content => $spawn_content,
    mode    => $::sensu::dir_mode,
    owner   => $::sensu::user,
    group   => $::sensu::group,
    require => Package[$pkg_title],
    notify  => $spawn_notify,
  }

  if $::sensu::manage_user and $::osfamily != 'windows' {
    user { $::sensu::user:
      ensure  => 'present',
      system  => true,
      home    => $::sensu::home_dir,
      shell   => $::sensu::shell,
      require => Group[$::sensu::group],
      comment => 'Sensu Monitoring Framework',
    }

    group { $::sensu::group:
      ensure => 'present',
      system => true,
    }
  } elsif $::sensu::manage_user and $::osfamily == 'windows' {
    notice('Managing a local windows user is not implemented on windows')
  }

  file { "${sensu::etc_dir}/config.json": ensure => absent }
}