From 323c07667e9fd6f1573388d1bfe32683d3107c0b Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 25 Apr 2008 16:14:08 +0000 Subject: release new nagios stuff, should be much more modular now and using native types by puppet --- manifests/init.pp | 438 +++++++++++++++++++++++++++++------------------------- 1 file changed, 237 insertions(+), 201 deletions(-) (limited to 'manifests/init.pp') diff --git a/manifests/init.pp b/manifests/init.pp index 6504736..93032c0 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,10 +1,12 @@ # nagios.pp - everything nagios related # Copyright (C) 2007 David Schmitt # See LICENSE for the full license granted to you. +# adapted and improved by admin(at)immerda.ch +# adapted by Puzzle ITC - haerry+puppet(at)puzzle.ch # the directory containing all nagios configs: -$nagios_cfgdir = "/var/lib/puppet/modules/nagios" +$nagios_cfgdir = '/var/lib/puppet/modules/nagios' modules_dir{ nagios: } class nagios { @@ -15,96 +17,24 @@ class nagios { } } -class nagios::debian inherits nagios::base { - Package [nagios]{ - name => "nagios2", - } - package { - "nagios-plugins-standard": - ensure => installed, - } - Service[nagios] { - # Current Debian/etch pattern - pattern => "/usr/sbin/nagios2 -d /etc/nagios2/nagios.cfg", - subscribe => File [ $nagios_cfgdir ] - } - File["$etc_nagios_path/htpasswd.users"]{ - group => www-data, - } - - file { - [ "/etc/nagios2/conf.d/localhost_nagios2.cfg", - "/etc/nagios2/conf.d/extinfo_nagios2.cfg", - "/etc/nagios2/conf.d/services_nagios2.cfg" ]: - ensure => absent, - notify => Service[nagios2]; - } - # permit external commands from the CGI - file { - "/var/lib/nagios2": - ensure => directory, mode => 751, - owner => nagios, group => nagios, - notify => Service[nagios2]; - } - file{ - "/var/lib/nagios2/rw": - ensure => directory, mode => 2710, - owner => nagios, group => www-data, - notify => Service[nagios2]; - - } - - # TODO: these are not very robust! - replace { - # Debian installs a default check for the localhost. Since VServers - # usually have no localhost IP, this fixes the definition to check the - # real IP - fix_default_config: - file => "/etc/nagios2/conf.d/localhost_nagios2.cfg", - pattern => "address *127.0.0.1", - replacement => "address $ipaddress", - notify => Service[nagios2]; - # enable external commands from the CGI - enable_extcommands: - file => "/etc/nagios2/nagios.cfg", - pattern => "check_external_commands=0", - replacement => "check_external_commands=1", - notify => Service[nagios2]; - # put a cap on service checks - cap_service_checks: - file => "/etc/nagios2/nagios.cfg", - pattern => "max_concurrent_checks=0", - replacement => "max_concurrent_checks=30", - notify => Service[nagios2]; - } - -} -# end nagios::debian - -class nagios::centos inherits nagios::base { - package { [ 'nagios-plugins-smtp','nagios-plugins-http', 'nagios-plugins-ssh', 'nagios-plugins-udp', 'nagios-plugins-tcp', 'nagios-plugins-dig', 'nagios-plugins-nrpe', 'nagios-plugins-load', 'nagios-plugins-dns', 'nagios-plugins-ping', 'nagios-plugins-procs', 'nagios-plugins-users', 'nagios-plugins-ldap', 'nagios-plugins-disk', 'nagios-devel', 'nagios-plugins-swap', 'nagios-plugins-nagios', 'nagios-plugins-perl' ]: - ensure => 'present', - } - Service[nagios]{ - hasstatus => true, - } - -} - class nagios::vars { case $operatingsystem { debian: { - $etc_nagios_path = "/etc/nagios2" + $etc_nagios_path = '/etc/nagios2' } default: { - $etc_nagios_path = "/etc/nagios" + $etc_nagios_path = '/etc/nagios' } } } - class nagios::base { + include nagios::vars + + # needs apache to work + include apache + package { nagios: ensure => present, } @@ -116,145 +46,251 @@ class nagios::base { require => Package[nagios], } - include nagios::vars - - # import the various definitions - File <<| tag == 'nagios' |>> - - file { - "$etc_nagios_path/htpasswd.users": + # manage nagios cfg files + file {nagios_cfg_dir: + path => "$etc_nagios_path", + source => "puppet://$server/nagios/empty", + ensure => directory, + recurse => true, + purge => true, + notify => Service[nagios], + mode => 0755, owner => root, group => root; + } + # this file should contain _only_ the nagios_puppet_template-path: + # cfg_file=/etc/nagios/puppet_cfgpaths.cfg + file {nagios_main_cfg: + path => "$etc_nagios_path/nagios.cfg", + source => [ "puppet://$server/files/nagios/${fqdn}/nagios.cfg", + "puppet://$server/files/nagios/$operatingsystem/nagios.cfg.$lsbdistrelease", + "puppet://$server/files/nagios/$operatingsystem/nagios.cfg", + "puppet://$server/files/nagios/nagios.cfg", + "puppet://$server/nagios/$operatingsystem/nagios.cfg.$lsbdistrelease", + "puppet://$server/nagios/$operatingsystem/nagios.cfg", + "puppet://$server/nagios/nagios.cfg" ], + notify => Service[nagios], + mode => 0644, owner => root, group => root; + } + # here is this magic file containing all relevant paths + file {nagios_puppet_cfg_paths: + path => "$etc_nagios_path/puppet_cfgpaths.cfg", + source => [ "puppet://$server/files/nagios/${fqdn}/puppet_cfgpaths.cfg", + "puppet://$server/files/nagios/$operatingsystem/puppet_cfgpaths.cfg.$lsbdistrelease", + "puppet://$server/files/nagios/$operatingsystem/puppet_cfgpaths.cfg", + "puppet://$server/files/nagios/puppet_cfgpaths.cfg", + "puppet://$server/nagios/$operatingsystem/puppet_cfgpaths.cfg.$lsbdistrelease", + "puppet://$server/nagios/$operatingsystem/puppet_cfgpaths.cfg", + "puppet://$server/nagios/puppet_cfgpaths.cfg" ], + notify => Service[nagios], + mode => 0644, owner => root, group => root; + } + file { nagios_cgi_cfg: + path => "$etc_nagios_path/cgi.cfg", + source => [ "puppet://$server/files/nagios/${fqdn}/cgi.cfg", + "puppet://$server/files/nagios/$operatingsystem/cgi.cfg.$lsbdistrelease", + "puppet://$server/files/nagios/$operatingsystem/cgi.cfg", + "puppet://$server/files/nagios/cgi.cfg", + "puppet://$server/nagios/$operatingsystem/cgi.cfg.$lsbdistrelease", + "puppet://$server/nagios/$operatingsystem/cgi.cfg", + "puppet://$server/nagios/cgi.cfg" ], + owner => 'root', + group => 0, + mode => '0644', + notify => Service['apache'], + } + + file {"$etc_nagios_path/htpasswd.users": source => [ "puppet://$server/files/nagios/htpasswd.users", "puppet://$server/nagios/htpasswd.users" ], mode => 0640, owner => root, group => apache; } - - file { - "$nagios_cfgdir/hosts.d": - ensure => directory, - owner => root, - group => root, - mode => 0755, - } - define command($command_line) { - file { "$nagios_cfgdir/hosts.d/${name}_command.cfg": - ensure => present, content => template( "nagios/command.erb" ), - mode => 644, owner => root, group => root, - notify => Service[nagios2], - } - } + file{[ "$etc_nagios_path/nagios_command.cfg", + "$etc_nagios_path/nagios_contact.cfg", + "$etc_nagios_path/nagios_contactgroup.cfg", + "$etc_nagios_path/nagios_host.cfg", + "$etc_nagios_path/nagios_hostextinfo.cfg", + "$etc_nagios_path/nagios_hostgroup.cfg", + "$etc_nagios_path/nagios_hostgroupescalation.cfg", + "$etc_nagios_path/nagios_service.cfg", + "$etc_nagios_path/nagios_servicedependency.cfg", + "$etc_nagios_path/nagios_serviceescalation.cfg", + "$etc_nagios_path/nagios_serviceextinfo.cfg", + "$etc_nagios_path/nagios_timeperdiod.cfg" ]: + ensure => file, + replace => false, + notify => Service[nagios], + mode => 0644, owner => root, group => root; + } - nagios2::command { - # from ssh.pp - ssh_port: - command_line => '/usr/lib/nagios/plugins/check_ssh -p $ARG1$ $HOSTADDRESS$'; + # old way of commands to not break the current config + # TODO: integrate these commands into native nagios types + file{ "$etc_nagios_path/legacy": + source => "puppet://$server/files/nagios/legacy" + ensure => directory, + recurse => true, + purge => true, + notify => Service[nagios], + mode => 0755, owner => root, group => 0; + } + + nagios_command{ssh_port: + command_line => '$USER1/check_ssh -p $ARG1$ $HOSTADDRESS$'; # from apache2.pp http_port: - command_line => '/usr/lib/nagios/plugins/check_http -p $ARG1$ -H $HOSTADDRESS$ -I $HOSTADDRESS$'; + command_line => '$USER1/check_http -p $ARG1$ -H $HOSTADDRESS$ -I $HOSTADDRESS$'; # from bind.pp - nameserver: command_line => '/usr/lib/nagios/plugins/check_dns -H www.edv-bus.at -s $HOSTADDRESS$'; - # TODO: debug this, produces copious false positives: - # check_dig2: command_line => '/usr/lib/nagios/plugins/check_dig -H $HOSTADDRESS$ -l $ARG1$ --record_type=$ARG2$ --expected_address=$ARG3$ --warning=2.0 --critical=4.0'; - check_dig2: command_line => '/usr/lib/nagios/plugins/check_dig -H $HOSTADDRESS$ -l $ARG1$ --record_type=$ARG2$' - } - - define host($ip = $fqdn, $short_alias = $fqdn) { - @@file { - "$nagios_cfgdir/hosts.d/${name}_host.cfg": - ensure => present, content => template( "nagios/host.erb" ), - mode => 644, owner => root, group => root, - tag => 'nagios' - } + check_dig2: + command_line => '$USER1/check_dig -H $HOSTADDRESS$ -l $ARG1$ --record_type=$ARG2$' } - define service($check_command = '', - $nagios2_host_name = $fqdn, $nagios2_description = '') - { - # this is required to pass nagios' internal checks: - # every service needs to have a defined host - include nagios2::target - $real_check_command = $check_command ? { - '' => $name, - default => $check_command - } - $real_nagios2_description = $nagios2_description ? { - '' => $name, - default => $nagios2_description - } - @@file { - "$nagios_cfgdir/hosts.d/${nagios2_host_name}_${name}_service.cfg": - ensure => present, content => template( "nagios/service.erb" ), - mode => 644, owner => root, group => root, - tag => 'nagios' - } - } + Nagios_command <<||>> + Nagios_contact <<||>> + Nagios_contactgroup <<||>> + Nagios_host <<||>> + Nagios_hostextinfo <<||>> + Nagios_hostgroup <<||>> + Nagios_hostgroupescalation <<||>> + Nagios_service <<||>> + Nagios_servicedependency <<||>> + Nagios_serviceescalation <<||>> + Nagios_serviceextinfo <<||>> + Nagios_timeperiod <<||>> - define extra_host($ip = $fqdn, $short_alias = $fqdn, $parent = "none") { - $nagios_parent = $parent - file { - "$nagios_cfgdir/hosts.d/${name}_host.cfg": - ensure => present, content => template( "nagios/host.erb" ), - mode => 644, owner => root, group => root, - notify => Service[nagios2], - } - } + if defined(Class["munin::client"] { + include munin::plugins::nagios + } +} # end nagios::base - # additional hosts - - file { - "$etc_nagios_path/hosts.cfg": - source => [ - "puppet://$server/files/nagios/hosts.cfg", - "puppet://$server/nagios/hosts.cfg" - ], - mode => 0644, owner => nagios, group => nagios; +class nagios::centos inherits nagios::base { + package { [ 'nagios-plugins-smtp','nagios-plugins-http', 'nagios-plugins-ssh', 'nagios-plugins-udp', 'nagios-plugins-tcp', 'nagios-plugins-dig', 'nagios-plugins-nrpe', 'nagios-plugins-load', 'nagios-plugins-dns', 'nagios-plugins-ping', 'nagios-plugins-procs', 'nagios-plugins-users', 'nagios-plugins-ldap', 'nagios-plugins-disk', 'nagios-devel', 'nagios-plugins-swap', 'nagios-plugins-nagios', 'nagios-plugins-perl' ]: + ensure => 'present', + before => Service[nagios], + } + + Service[nagios]{ + hasstatus => true, + } + # default cmd file from rpm + # don't forget it to add to the puppet paths + file { nagios_commands_cfg: + path => "$etc_nagios_path/commands.cfg", + source => [ "puppet://$server/nagios/$operatingsystem/commands.cfg.$lsbdistrelease", + "puppet://$server/nagios/$operatingsystem/commands.cfg" ], + owner => 'root', + group => 0, + mode => '0644', + notify => Service['apache'], } + file{"$etc_nagios_path/private/": + source => "puppet://$server/nagios/empty", + ensure => directory, + purge => true, + recurse => true, + mode => '0750', owner => root, group => nagios; + } + file{"$etc_nagios_path/private/resource.cfg": + source => "puppet://$server/nagios/$operatingsystem/private/resource.cfg.$architecture", + owner => root, group => nagios, mode => '0640'; + } +} - # nagios cfg includes $nagios_cfgdir/hosts.d - file { - "$etc_nagios_path/nagios.cfg": - ensure => present, content => template( "nagios/nagioscfg.erb" ), - mode => 0644, owner => nagios, group => nagios; +class nagios::target { + include nagios::target::host + nagios::service::ping{$fqdn:} +} + +class nagios::target::host { + $real_nagios_parent = $nagios_parent ? { + '' => 'none', + default => $nagios_parent } + nagios::host { $fqdn: parents => $real_nagios_parent } +} + +# defines +define nagios::host( + $ip = $fqdn, + $alias = $hostname, + $use = 'generic-host', + $parents = 'none' ) +{ + @@nagios_host { $name: + ensure => present, + alias => $alias, + address => $ip. + use => $use, + } + case $parents { + 'none': {} + default: { + Nagios_host[$name]{ + parents => $parents, + } + } + } +} + +# this will define a host which isn't managed by puppet. +# a ping serivce is automatically added +# please note: +# - you can use it only on the nagios master (no exported resources) +# - you can not use this host for any other services! +define nagios::extra_host($ip, $alias, $host_use = 'generic-host', $parents = 'none' ) { + nagios::host{$name: + ip => $ip, + alias = $alias, + $use = $use, + parents = $parents + } + nagios_service { "check_ping_${name}": + check_command => "check_ping!100.0,20%!500.0,60%", + use => "generic-service", + host_name => $ip, + notification_period => "24x7", + service_description => "${alias}_check_ping" + } +} + +define nagios::service( + $check_command, + $host_name = $fqdn, + $use = 'generic-service', + notification_period = "24x7", + $service_description = ''){ - # include this class in every host that should be monitored by nagios - class target { - nagios2::host { $fqdn: } - debug ( "$fqdn has $nagios_parent as parent" ) - } -} # end nagios::base -##################################################################################################### -## The main nagios monitor class -#class nagios2 { -# -# file { -# "/etc/nagios2/conf.d/hostgroups_nagios2.cfg": -# source => "puppet://$server/nagios/hostgroups_nagios2.cfg", -# mode => 0644, owner => root, group => www-data, -# notify => Service[nagios2]; -# } -# -## line { include_cfgdir: -## file => "/etc/nagios2/nagios.cfg", -## line => "cfg_dir=$nagios_cfgdir", -## notify => Service[nagios2], -## } -# -# munin::plugin { -# nagios_hosts: script_path => "/usr/local/bin"; -# nagios_svc: script_path => "/usr/local/bin"; -# nagios_perf_hosts: ensure => nagios_perf_, script_path => "/usr/local/bin"; -# nagios_perf_svc: ensure => nagios_perf_, script_path => "/usr/local/bin"; -# } -# -# file { "/etc/munin/plugin-conf.d/nagios": -# content => "[nagios_*]\nuser root\n", -# mode => 0655, owner => root, group => root, -# notify => Service[munin-node] -# } -# -#} + # this is required to pass nagios' internal checks: + # every service needs to have a defined host + include nagios::target::host + @@nagios_service {$name: + check_command => $check_command, + use => $use, + host_name => $host_name, + notification_period => $notification_period, + } + # if no service_description is set it is a namevar + case $service_description { + '': {} + default: { + Nagios_service[$name]{ + service_description => $service_description, + } + } + } +} + +define nagios::service::ping($host_name = $hostname ){ + nagios::service{ "check_ping_${hostname}": + check_command => "check_ping!100.0,20%!500.0,60%", + host_name => $host_name, + } +} +define nagios::service::ntp($host_name = $hostname ){ + nagios::service{ "check_ntp_${hostname}": + check_command => "check_ntp", + host_name => $host_name, + } +} -- cgit v1.2.3