Puppet Class: smokeping::config

Defined in:
manifests/config.pp

Overview



1
2
3
4
5
6
7
8
9
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
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
# File 'manifests/config.pp', line 1

class smokeping::config {
  $mode          = $smokeping::mode
  $master_url    = $smokeping::master_url
  $shared_secret = $smokeping::shared_secret
  $slave_name    = $smokeping::slave_name
  $master_name   = $smokeping::master_name

  # General config
  $owner          = $smokeping::owner
  $contact        = $smokeping::contact
  $mailhost       = $smokeping::mailhost
  $cgiurl         = $smokeping::cgiurl
  $syslogfacility = $smokeping::syslogfacility
  $syslogpriority = $smokeping::syslogpriority
  $daemon_user    = $smokeping::daemon_user
  $daemon_group   = $smokeping::daemon_group

  # The owner of the image files (written by the webserver)
  $webserver_user  = $smokeping::webserver_user
  $webserver_group = $smokeping::webserver_group

  # Probes
  $probes = $smokeping::probes

  # Alerts
  $alerts_to   = $smokeping::alerts_to
  $alerts_from = $smokeping::alerts_from
  $alerts      = $smokeping::alerts

  # Targets
  $default_probe  = $smokeping::default_probe
  $cgi_remark_top = $smokeping::cgi_remark_top
  $cgi_title_top  = $smokeping::cgi_title_top
  $targets        = $smokeping::targets

  # Pathnames
  $path_sendmail  = $smokeping::path_sendmail
  $path_imgcache  = $smokeping::path_imgcache
  $path_imgurl    = $smokeping::path_imgurl
  $path_datadir   = $smokeping::path_datadir
  $path_piddir    = $smokeping::path_piddir
  $path_smokemail = $smokeping::path_smokemail
  $path_tmail     = $smokeping::path_tmail

  File {
    owner => root,
    group => root,
    mode  => '0644',
  }

  file { '/etc/smokeping/config.d':
    ensure  => directory,
    recurse => true,
    purge   => true,
    force   => true,
  }

  -> file {
    '/etc/smokeping/config':
      content => template('smokeping/config.erb');
    '/etc/smokeping/config.d/Alerts':
      content => template('smokeping/alerts.erb');
    '/etc/smokeping/config.d/Database':
      content => template('smokeping/database.erb');
    '/etc/smokeping/config.d/General':
      content => template('smokeping/general.erb');
    '/etc/smokeping/config.d/pathnames':
      content => template('smokeping/pathnames.erb');
    '/etc/smokeping/config.d/Presentation':
      content => template('smokeping/presentation.erb');
    '/etc/smokeping/config.d/Probes':
      content => template('smokeping/probes.erb');
  }

  ## Platform Specific
  if $facts['os']['family'] == 'Debian' or $facts['os']['name'] == 'Ubuntu' {
    # Defaults file allows smokeping to be launched in different modes (eg slave vs master)
    file { '/etc/default/smokeping':
      content => template('smokeping/defaults.erb');
    }
  } else {
    # TODO: Add master/slave support to non-Debian distros
    #
    # We don't yet support modes other than standalone on other platforms
    # such as RHEL - to offer it, we need to start replacing the systemd
    # service file loaded by the package manager with a custom one that
    # has the alternative parameters set, like in the default file above
    # for Debian/Ubuntu systems.

    if ($mode != 'standalone') {
      fail('Currently master/slave mode not supported for this OS family')
    }
  }

  ## mode specific
  case $mode {
    ## Slave configuration
    'slave': {
      # Check if slave_display_name is unset.
      # --> use FQDN if not set.
      if $smokeping::slave_display_name == '' {
        $display_name = $facts['networking']['fqdn']
      } else {
        $display_name = $smokeping::slave_display_name
      }

      if $smokeping::slave_color == '' {
        $slave_color = sprintf('%06d', fqdn_rand('999999'))
      } else {
        $slave_color = $smokeping::slave_color
      }

      smokeping::slave { $facts['networking']['fqdn']:
        location     => $smokeping::slave_location,
        display_name => $display_name,
        color        => $slave_color,
      }
      # periodic restart to pick-up new config
      #cron {
      #  'smokeping::periodic-restart':
      #    command => 'PATH=$PATH:/sbin /etc/init.d/smokeping stop >/dev/null 2>&1; sleep 2; PATH=$PATH:/sbin /etc/init.d/smokeping start >/dev/null 2>&1',
      #    user    => root,
      #    minute  => '*/15';
      #}
    }
    ## Master/Standalone configuration
    ## collect slaves if mode is master and create Targets
    ## if mode is standalone, just create targets...
    /^(master|standalone)$/: {
      if $mode =~ /^master$/ {
        # collect slaves
        File <<| tag == "smokeping-slave-${master_name}" |>>
        file { $smokeping::slave_dir: ensure => directory; }
        concat { '/etc/smokeping/config.d/Slaves':
          owner => root,
          group => root,
          mode  => '0644',
        }
        concat::fragment { 'slaves-header':
          target  => '/etc/smokeping/config.d/Slaves',
          order   => 10,
          content => "*** Slaves ***\nsecrets=${smokeping::slave_secrets}\n\n",
        }
        Concat::Fragment <<| tag == "smokeping-slave-${master_name}" |>>

        # collect shared secrets from slaves
        concat { $smokeping::slave_secrets:
          owner => $daemon_user,
          group => $webserver_group,
          mode  => '0640',
        }
        Concat::Fragment <<| tag == "smokeping-slave-secret-${master_name}" |>>
      } else {
        # ensure $smokeping::slave_secret is there
        file { $smokeping::slave_secrets:
          ensure => file,
          owner  => $daemon_user,
          group  => $webserver_group,
          mode   => '0640',
        }
      }

      # create target definitions
      file { $smokeping::targets_dir:
        ensure  => directory,
        recurse => true,
        purge   => true,
        force   => true,
      }
      concat { '/etc/smokeping/config.d/Targets':
        owner => root,
        group => root,
        mode  => '0644',
      }
      concat::fragment { 'targets-header':
        target  => '/etc/smokeping/config.d/Targets',
        order   => 10,
        content => template('smokeping/targets-header.erb'),
      }
      create_resources('smokeping::target', $targets, {})
    }
    default: { fail("mode ${mode} unknown") }
  }
}