Defined Type: tp::puppi

Defined in:
manifests/puppi.pp

Overview

Define: tp::puppi

Manages Puppi integration Usage of this define is optional. It’s automatically invoked in tp::install if theparameter puppi_enable is set to true. When used, puppi check and puppi info files for the application are created. If used, it requires the example42/puppi module.

Parameters:

  • ensure (Enum['present','absent']) (defaults to: present)
  • check_enable (Boolean) (defaults to: true)
  • check_template (String) (defaults to: 'tp/puppi/check.erb')
  • info_enable (Boolean) (defaults to: true)
  • info_template (String[1]) (defaults to: 'tp/puppi/info.erb')
  • info_defaults (Boolean) (defaults to: true)
  • log_enable (Boolean) (defaults to: true)
  • options_hash (Hash) (defaults to: {})
  • settings_hash (Hash) (defaults to: {})
  • data_module (String[1]) (defaults to: 'tinydata')
  • verbose (Boolean) (defaults to: false)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
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
# File 'manifests/puppi.pp', line 10

define tp::puppi (

  Enum['present','absent']   $ensure         = present,

  Boolean                    $check_enable   = true ,
  String                     $check_template = 'tp/puppi/check.erb',

  Boolean                    $info_enable    = true ,
  String[1]                  $info_template  = 'tp/puppi/info.erb',
  Boolean                    $info_defaults  = true,

  Boolean                    $log_enable     = true,

  Hash                       $options_hash   = {},
  Hash                       $settings_hash  = {},

  String[1]                  $data_module    = 'tinydata',

  Boolean                    $verbose        = false,

) {
  # If we use tp::puppi we need example42/puppi
  include puppi

  # Settings evaluation
  $tp_settings=tp_lookup($title,'settings',$data_module,'deep_merge')
  $settings = $tp_settings + $settings_hash

  # Default options and computed variables
  $puppi_defaults = {
    check_timeout          => '10',

    check_process_command  => 'check_procs',
    check_process_critical => '1:',
    check_process_warning  => '1:',
    check_process_metric   => 'PROCS',

    check_service_command  => 'service',

    check_port_command     => 'check_tcp',
    check_port_critical    => '10',
    check_port_warning     => '5',
    check_port_host        => '127.0.0.1',
  }

  $puppi_options = $puppi_defaults + $options_hash

  $real_check_base_dir = pick($puppi_options[check_command_base_dir],$puppi::checkpluginsdir)

  $real_check_process_command = $puppi_options[check_process_command] ? {
    'check_procs' => "${real_check_base_dir}/${puppi_options[check_process_command]} \
       -c ${puppi_options[check_process_critical]} \
       -w ${puppi_options[check_process_warning]} \
       -m ${puppi_options[check_process_metric]} \
       -C ${settings[process_name]} \
      ",
    default       => "${real_check_base_dir}/${puppi_options[check_process_command]}",
  }

  $real_check_service_command = $puppi_options[check_service_command] ? {
    'service' => "service ${settings[service_name]} status",
    default   => $puppi_options[check_service_command],
  }

  $real_check_port_command = $puppi_options[check_port_command] ? {
    'check_tcp' => "${real_check_base_dir}/${puppi_options[check_port_command]} \
       -H ${puppi_options[check_port_host]} \
       -c ${puppi_options[check_port_critical]} \
       -w ${puppi_options[check_port_warning]} \
       -p ${settings[tcp_port]} \
     ",
    default     => "${real_check_base_dir}/${puppi_options[check_port_command]}",
  }

  $array_package_name=any2array($settings['package_name'])
  $array_service_name=any2array($settings['service_name'])
  $array_log_file_path=any2array($settings['log_file_path'])
  $array_tcp_port=any2array($settings['tcp_port'])
  $array_info_commands=any2array($settings['info_commands'])

  # Puppi checks
  if $check_enable == true {
    file { "${puppi::params::checksdir}/${title}":
      ensure  => $ensure,
      mode    => '0755',
      owner   => $puppi::params::configfile_owner,
      group   => $puppi::params::configfile_group,
      require => Class['puppi'],
      content => template($check_template),
      tag     => 'tp_puppi_check',
    }
  }

  # Puppi info
  if $info_enable == true {
    if $info_defaults == true {
      file { "${puppi::params::infodir}/${title}":
        ensure  => $ensure,
        mode    => '0750',
        owner   => $puppi::params::configfile_owner,
        group   => $puppi::params::configfile_group,
        require => Class['puppi'],
        content => template($info_template),
        tag     => 'tp_puppi_info',
      }
    }

    if $settings[info_commands] {
      $infos = any2array($settings[info_commands])
      file { "${puppi::params::infodir}/${title}_extra":
        ensure  => $ensure,
        mode    => '0750',
        owner   => $puppi::params::configfile_owner,
        group   => $puppi::params::configfile_group,
        require => Class['puppi'],
        content => inline_template('<% @infos.each do |cmd| %><%= cmd %><% end %>'),
        tag     => 'tp_puppi_info',
      }
    }
  }

  # Puppi log
  if $log_enable == true {
    $logs = any2array($settings[log_file_path])
    file { "${puppi::params::logsdir}/${title}":
      ensure  => $ensure,
      mode    => '0750',
      owner   => $puppi::params::configfile_owner,
      group   => $puppi::params::configfile_group,
      require => Class['puppi'],
      content => inline_template('<% @logs.each do |path| %><%= path %><% end %>'),
      tag     => 'tp_puppi_log',
    }
  }
}