Puppet Class: nagios::base
- Inherited by:
-
nagios::debian
nagios::redhat
nagios::base::withwebinterface
- Defined in:
- manifests/base.pp
Overview
Class: nagios::base
Define common resources between debian and redhat based systems. It shouldn’t be necessary to include this class directly. Instead, you should use:
include nagios
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 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 |
# File 'manifests/base.pp', line 8
class nagios::base {
include ::nagios::params
# variables used in ERB template
$basename = $nagios::params::basename
$nagios_p1_file = $nagios::params::p1file
$nagios_debug_level = '0'
$nagios_debug_verbosity = '0'
$pidfile = $nagios::params::pidfile
case $::osfamily {
'Debian': { $nagios_mail_path = '/usr/bin/mail' }
'RedHat': { $nagios_mail_path = '/bin/mail' }
default: { fail ("OS family ${::osfamily} not yet implemented !") }
}
# Common resources between base, redhat, and debian
user { 'nagios':
ensure => present,
shell => '/bin/sh',
require => Package['nagios'],
}
service { 'nagios':
ensure => running,
enable => true,
hasrestart => true,
require => Package['nagios'],
}
exec { 'nagios-restart':
command => "${nagios::params::basename} -v ${nagios::params::conffile} && /etc/init.d/${nagios::params::basename} restart",
refreshonly => true,
path => $::path,
}
exec { 'nagios-reload':
command => "${nagios::params::basename} -v ${nagios::params::conffile} && /etc/init.d/${nagios::params::basename} reload",
refreshonly => true,
path => $::path,
}
$read_write_dir = $::osfamily ? {
'Debian' => '/var/lib/nagios3/rw',
'RedHat' => '/var/spool/nagios/cmd',
}
$command_file = "${read_write_dir}/nagios.cmd"
file { 'nagios read-write dir':
ensure => directory,
path => $read_write_dir,
owner => 'nagios',
group => 'nagios',
mode => '2710',
require => Package['nagios'],
}
file { 'nagios query-handler read-write dir':
ensure => directory,
path => "/var/log/${nagios::params::basename}/rw",
owner => 'nagios',
group => 'nagios',
mode => '2710',
require => Package['nagios'],
}
file {[
"/var/run/${nagios::params::basename}",
"/var/log/${nagios::params::basename}",
"/var/lib/${nagios::params::basename}",
"/var/lib/${nagios::params::basename}/spool",
"/var/lib/${nagios::params::basename}/spool/checkresults",
"/var/cache/${nagios::params::basename}",
]:
ensure => directory,
owner => nagios,
group => nagios,
mode => '0755',
require => Package['nagios'],
before => Service['nagios'],
}
nagios::resource { 'USER1': value => $nagios::params::user1 }
concat {[
$nagios::params::conffile,
"${nagios::params::rootdir}/resource.cfg",
]:
notify => Exec['nagios-restart'],
require => Package['nagios'],
}
$use_syslog = $nagios::use_syslog
concat::fragment {'main':
target => $nagios::params::conffile,
content => template('nagios/nagios.cfg.erb'),
}
# other common resources below
file { ["${nagios::params::rootdir}/conf.d",
"${nagios::params::rootdir}/auto-puppet",
"${nagios::params::rootdir}/nagios.d"]:
ensure => absent,
force => true,
recurse => true,
require => Package['nagios'],
}
# purge undefined nagios resources
file { $nagios::params::resourcedir:
ensure => directory,
# lint:ignore:fileserver
source => 'puppet:///modules/nagios/empty',
# lint:endignore
owner => root,
group => root,
mode => '0644',
purge => true,
force => true,
recurse => true,
notify => Exec['nagios-restart'],
}
$module_path = get_module_path($module_name)
file {"${nagios::params::resourcedir}/generic-host.cfg":
ensure => file,
owner => root,
group => root,
mode => '0644',
content => file("${module_path}/files/generic-host.cfg"),
notify => Exec['nagios-restart'],
}
$check_ping_ipv = $::nagios::check_ping_ipv
file {"${nagios::params::resourcedir}/generic-command.cfg":
ensure => file,
owner => root,
group => root,
mode => '0644',
content => template('nagios/generic-command.cfg.erb'),
notify => Exec['nagios-restart'],
}
file {"${nagios::params::resourcedir}/generic-timeperiod.cfg":
ensure => file,
owner => root,
group => root,
mode => '0644',
content => file("${module_path}/files/generic-timeperiod.cfg"),
notify => Exec['nagios-restart'],
}
file {"${nagios::params::resourcedir}/base-contacts.cfg":
ensure => file,
owner => 'root',
mode => '0644',
}
nagios_contact { 'root':
contact_name => 'root',
# lint:ignore:alias_parameter
alias => 'Root',
# lint:endignore
service_notification_period => '24x7',
host_notification_period => '24x7',
service_notification_options => 'w,u,c,r',
host_notification_options => 'd,r',
service_notification_commands => 'notify-service-by-email',
host_notification_commands => 'notify-host-by-email',
email => 'root',
target => "${nagios::params::resourcedir}/base-contacts.cfg",
notify => Exec['nagios-restart'],
require => File["${nagios::params::resourcedir}/base-contacts.cfg"],
}
file {"${nagios::params::resourcedir}/base-contactgroups.cfg":
ensure => file,
owner => 'root',
mode => '0644',
}
nagios_contactgroup { 'admins':
contactgroup_name => 'admins',
# lint:ignore:alias_parameter
alias => 'Nagios Administrators',
# lint:endignore
members => 'root',
target => "${nagios::params::resourcedir}/base-contactgroups.cfg",
notify => Exec['nagios-restart'],
require => [
Nagios_contact['root'],
File["${nagios::params::resourcedir}/base-contactgroups.cfg"]
],
}
file {"${nagios::params::resourcedir}/base-servicegroup.cfg":
ensure => file,
owner => 'root',
mode => '0644',
}
nagios_servicegroup { 'default':
# lint:ignore:alias_parameter
alias => 'Default Service Group',
# lint:endignore
target => "${nagios::params::resourcedir}/base-servicegroup.cfg",
notify => Exec['nagios-restart'],
require => File["${nagios::params::resourcedir}/base-servicegroup.cfg"],
}
}
|