Puppet Class: monit::config

Inherits:
monit::params
Defined in:
manifests/config.pp

Overview

Class: monit::config

Configures monit daemon

Parameters:

  • ensure (Any)
  • bind_address (Any)
  • bind_port (Any)
  • username (Any)
  • password (Any)
  • all_addresses_ipv4 (Any)
  • min_cycles (Any)
  • loadavg_1min (Any)
  • loadavg_5min (Any)
  • memory_usage (Any)
  • cpu_usage_system (Any)
  • cpu_usage_user (Any)
  • space_usage (Any)
  • inode_usage (Any)
  • email (Any)
  • mmonit_user (Any)
  • mmonit_password (Any)
  • mmonit_host (Any)
  • mmonit_port (Any)


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
# File 'manifests/config.pp', line 6

class monit::config
(
    $ensure,
    $bind_address,
    $bind_port,
    $username,
    $password,
    $all_addresses_ipv4,
    $min_cycles,
    $loadavg_1min,
    $loadavg_5min,
    $memory_usage,
    $cpu_usage_system,
    $cpu_usage_user,
    $space_usage,
    $inode_usage,
    $email,
    $mmonit_user,
    $mmonit_password,
    $mmonit_host,
    $mmonit_port

) inherits monit::params
{
    # Generate the URL for M/Monit, if $mmonit_user is defined
    if $mmonit_user {
        $mmonit_line = "set mmonit http://${mmonit_user}:${mmonit_password}@${mmonit_host}:${mmonit_port}/collector"
    } else {
        $mmonit_line = undef
    }

    # Generate the "set httpd" line
    if $bind_address == 'all' {
        $httpd_line = "set httpd port ${bind_port}"
    } elsif $bind_address == 'query' {
        $ipv4_address = generate('/usr/local/bin/getip.sh', '-4', $::fqdn)
        $httpd_line = "set httpd port ${bind_port} and use the address ${ipv4_address}"
    } else {
        $httpd_line = "set httpd port ${bind_port} and use the address ${bind_address}"
    }

    if $username {
        $httpd_credentials_line = "allow ${username}:${password}"
    } else {
        $httpd_credentials_line = undef
    }

    $ensure_file = $ensure ? {
        /(present|running)/ => present,
        'absent' => absent,
    }

    $ensure_dir = $ensure ? {
        /(present|running)/ => directory,
        'absent' => absent,
    }

    file { 'monit-control-dir':
        ensure  => $ensure_dir,
        name    => '/var/monit',
        owner   => $::os::params::adminuser,
        group   => $::os::params::admingroup,
        mode    => '0755',
        require => Class['monit::install'],
    }

    # This line will _not_ be added to monit configuration if $cpu_usage_user 
    # parameter is set to false.
    $cpu_usage_user_line = "if cpu usage (user) > ${cpu_usage_user} for ${min_cycles} cycles then alert"

    file { 'monit-monitrc':
        ensure  => $ensure_file,
        name    => $::monit::params::monitrc_name,
        content => template('monit/monitrc.erb'),
        owner   => $::os::params::adminuser,
        group   => $::os::params::admingroup,
        mode    => '0600',
        require => Class['monit::install'],
        notify  => Class['monit::service'],
    }

    file {  'monit-conf.d':
        ensure  => $ensure_dir,
        name    => $::monit::params::fragment_dir,
        owner   => $::os::params::adminuser,
        group   => $::os::params::admingroup,
        mode    => '0755',
        require => Class['monit::install'],
    }

    file { 'monit-core.monit':
        ensure  => $ensure_file,
        name    => "${::monit::params::fragment_dir}/core.monit",
        content => template('monit/core.monit.erb'),
        owner   => $::os::params::adminuser,
        group   => $::os::params::admingroup,
        mode    => '0600',
        require => File['monit-conf.d'],
        notify  => Class['monit::service'],
    }

    # Some operating systems require additional configuration files
    if $::osfamily == 'Debian' {
        class { '::monit::config::debian':
            ensure => $ensure,
        }
    }
}