diff options
author | mh <mh@immerda.ch> | 2010-05-05 23:22:10 +0200 |
---|---|---|
committer | mh <mh@immerda.ch> | 2010-05-05 23:22:10 +0200 |
commit | 33b091b896fbb0b54ee9968c452ef2a8867893d8 (patch) | |
tree | 863c61e2de0c258c859527e14e86b47ffd8f0bb1 /manifests | |
parent | 77f601607093b7fb22f3498574d0dedd2cbe01d9 (diff) | |
parent | 5d5ec8c28d0fe39359af8db159b14faeae397e1f (diff) |
merged with lavamind
Diffstat (limited to 'manifests')
32 files changed, 634 insertions, 256 deletions
diff --git a/manifests/apache.pp b/manifests/apache.pp new file mode 100644 index 0000000..36994f8 --- /dev/null +++ b/manifests/apache.pp @@ -0,0 +1,4 @@ +class nagios::apache { + $nagios_httpd = 'apache' + include nagios +} diff --git a/manifests/base.pp b/manifests/base.pp index bd55ff9..6106ab2 100644 --- a/manifests/base.pp +++ b/manifests/base.pp @@ -1,110 +1,73 @@ class nagios::base { - # needs apache to work - include apache - - package { nagios: - ensure => present, + package { 'nagios': + alias => 'nagios', + ensure => present, } - service{nagios: + service { 'nagios': ensure => running, enable => true, #hasstatus => true, #fixme! - require => Package[nagios], + require => Package['nagios'], } - # manage nagios cfg files - file {nagios_cfg_dir: - path => '/etc/nagios', - source => "puppet://$server/modules/common/empty", - ensure => directory, - recurse => true, - purge => true, - notify => Service[nagios], - mode => 0755, owner => root, group => root; - } # this file should contain all the nagios_puppet-paths: - file {nagios_main_cfg: - path => "/etc/nagios/nagios.cfg", - source => [ "puppet://$server/modules/site-nagios/configs/${fqdn}/nagios.cfg", + file { 'nagios_main_cfg': + path => "${nagios_cfgdir}/nagios.cfg", + source => [ "puppet://$server/modules/site-nagios/configs/${fqdn}/nagios.cfg", "puppet://$server/modules/site-nagios/configs/${operatingsystem}/nagios.cfg", "puppet://$server/modules/site-nagios/configs/nagios.cfg", "puppet://$server/modules/nagios/configs/${operatingsystem}/nagios.cfg", "puppet://$server/modules/nagios/configs/nagios.cfg" ], - notify => Service[nagios], + notify => Service['nagios'], mode => 0644, owner => root, group => root; - } - file { nagios_cgi_cfg: - path => "/etc/nagios/cgi.cfg", + } + + file { 'nagios_cgi_cfg': + path => "${nagios_cfgdir}/cgi.cfg", source => [ "puppet://$server/modules/site-nagios/configs/${fqdn}/cgi.cfg", "puppet://$server/modules/site-nagios/configs/${operatingsystem}/cgi.cfg", "puppet://$server/modules/site-nagios/configs/cgi.cfg", "puppet://$server/modules/nagios/configs/${operatingsystem}/cgi.cfg", "puppet://$server/modules/nagios/configs/cgi.cfg" ], - owner => 'root', - group => 0, - mode => '0644', + mode => '0644', owner => 'root', group => 0, notify => Service['apache'], } - file {"/etc/nagios/htpasswd.users": - source => [ - "puppet://$server/modules/site-nagios/htpasswd.users", - "puppet://$server/modules/nagios/htpasswd.users" ], - mode => 0640, owner => root, group => apache; - } - file{[ "/etc/nagios/nagios_command.cfg", - "/etc/nagios/nagios_contact.cfg", - "/etc/nagios/nagios_contactgroup.cfg", - "/etc/nagios/nagios_host.cfg", - "/etc/nagios/nagios_hostextinfo.cfg", - "/etc/nagios/nagios_hostgroup.cfg", - "/etc/nagios/nagios_hostgroupescalation.cfg", - "/etc/nagios/nagios_service.cfg", - "/etc/nagios/nagios_servicedependency.cfg", - "/etc/nagios/nagios_serviceescalation.cfg", - "/etc/nagios/nagios_serviceextinfo.cfg", - "/etc/nagios/nagios_timeperdiod.cfg" ]: - ensure => file, - replace => false, - notify => Service[nagios], - mode => 0644, owner => root, group => 0; + file { 'nagios_htpasswd': + path => "${nagios_cfgdir}/htpasswd.users", + source => [ "puppet://$server/modules/site-nagios/htpasswd.users", + "puppet://$server/modules/nagios/htpasswd.users" ], + mode => 0640, owner => root, group => apache; } - nagios::plugin{'check_jabber_login': } + file { 'nagios_private': + path => "${nagios_cfgdir}/private/", + source => "puppet://$server/modules/common/empty", + ensure => directory, + purge => true, + recurse => true, + notify => Service['nagios'], + mode => '0750', owner => root, group => nagios; + } - nagios::command{ - ssh_port: - command_line => '$USER1$/check_ssh -p $ARG1$ $HOSTADDRESS$'; - # from apache2.pp - http_port: - command_line => '$USER1$/check_http -p $ARG1$ -H $HOSTADDRESS$ -I $HOSTADDRESS$'; - # from bind.pp - check_dig2: - command_line => '$USER1$/check_dig -H $HOSTADDRESS$ -l $ARG1$ --record_type=$ARG2$'; - check_ntp_time: - command_line => '$USER1$/check_ntp_time -H $HOSTADDRESS$ -w 0.5 -c 1'; - check_http_url: - command_line => '$USER1$/check_http -H $ARG1$ -u $ARG2$'; - check_http_url_regex: - command_line => '$USER1$/check_http -H $ARG1$ -u $ARG2$ -e $ARG3$'; - check_https_url: - command_line => '$USER1$/check_http --ssl -H $ARG1$ -u $ARG2$'; - check_https_url_regex: - command_line => '$USER1$/check_http --ssl -H $ARG1$ -u $ARG2$ -e $ARG3$'; - check_https: - command_line => '$USER1$/check_http -S -H $HOSTADDRESS$'; - check_silc: - command_line => '$USER1$/check_tcp -p 706 -H $ARG1$'; - check_sobby: - command_line => '$USER1$/check_tcp -H $ARG1$ -p $ARG2$'; - check_jabber: - command_line => '$USER1$/check_jabber -H $ARG1$'; - check_jabber_login: - command_line => '$USER1$/check_jabber_login $ARG1$ $ARG2$', - require => Nagios::Plugin['check_jabber_login']; - } + file { 'nagios_private_resource_cfg': + path => "${nagios_cfgdir}/private/resource.cfg", + source => "puppet://$server/nagios/configs/${operatingsystem}/private/resource.cfg.${architecture}", + notify => Service['nagios'], + owner => root, group => nagios, mode => '0640'; + } + + file { 'nagios_confd': + path => "${nagios_cfgdir}/conf.d/", + source => "puppet://$server/modules/common/empty", + ensure => directory, + purge => true, + recurse => true, + notify => Service['nagios'], + mode => '0750', owner => root, group => nagios; + } Nagios_command <<||>> Nagios_contact <<||>> @@ -119,15 +82,87 @@ class nagios::base { Nagios_serviceextinfo <<||>> Nagios_timeperiod <<||>> - if $use_munin { - include munin::plugins::nagios + Nagios_command <||> { + target => "${nagios_cfgdir}/conf.d/nagios_command.cfg", + notify => Service['nagios'], + } + Nagios_contact <||> { + target => "${nagios_cfgdir}/conf.d/nagios_contact.cfg", + notify => Service['nagios'], + } + Nagios_contactgroup <||> { + target => "${nagios_cfgdir}/conf.d/nagios_contactgroup.cfg", + notify => Service['nagios'], + } + Nagios_host <||> { + target => "${nagios_cfgdir}/conf.d/nagios_host.cfg", + notify => Service['nagios'], + } + Nagios_hostextinfo <||> { + target => "${nagios_cfgdir}/conf.d/nagios_hostextinfo.cfg", + notify => Service['nagios'], + } + Nagios_hostgroup <||> { + target => "${nagios_cfgdir}/conf.d/nagios_hostgroup.cfg", + notify => Service['nagios'], + } + Nagios_hostgroupescalation <||> { + target => "${nagios_cfgdir}/conf.d/nagios_hostgroupescalation.cfg", + notify => Service['nagios'], + } + Nagios_service <||> { + target => "${nagios_cfgdir}/conf.d/nagios_service.cfg", + notify => Service['nagios'], + } + Nagios_servicedependency <||> { + target => "${nagios_cfgdir}/conf.d/nagios_servicedependency.cfg", + notify => Service['nagios'], + } + Nagios_serviceescalation <||> { + target => "${nagios_cfgdir}/conf.d/nagios_serviceescalation.cfg", + notify => Service['nagios'], + } + Nagios_serviceextinfo <||> { + target => "${nagios_cfgdir}/conf.d/nagios_serviceextinfo.cfg", + notify => Service['nagios'], + } + Nagios_timeperiod <||> { + target => "${nagios_cfgdir}/conf.d/nagios_timeperiod.cfg", + notify => Service['nagios'], + } + + file{[ "${nagios_cfgdir}/conf.d/nagios_command.cfg", + "${nagios_cfgdir}/conf.d/nagios_contact.cfg", + "${nagios_cfgdir}/conf.d/nagios_contactgroup.cfg", + "${nagios_cfgdir}/conf.d/nagios_host.cfg", + "${nagios_cfgdir}/conf.d/nagios_hostextinfo.cfg", + "${nagios_cfgdir}/conf.d/nagios_hostgroup.cfg", + "${nagios_cfgdir}/conf.d/nagios_hostgroupescalation.cfg", + "${nagios_cfgdir}/conf.d/nagios_service.cfg", + "${nagios_cfgdir}/conf.d/nagios_servicedependency.cfg", + "${nagios_cfgdir}/conf.d/nagios_serviceescalation.cfg", + "${nagios_cfgdir}/conf.d/nagios_serviceextinfo.cfg", + "${nagios_cfgdir}/conf.d/nagios_timeperiod.cfg" ]: + ensure => file, + replace => false, + notify => Service['nagios'], + mode => 0644, owner => root, group => 0; } - if $nagios_allow_external_cmd { - file{'/var/spool/nagios/cmd': - ensure => 'directory', - require => Package['nagios'], - owner => apache, group => nagios, mode => 2660; - } + # manage nagios cfg files + # must be defined after exported resource overrides and cfg file defs + file { 'nagios_cfgdir': + path => "${nagios_cfgdir}/", + source => "puppet://$server/modules/common/empty", + ensure => directory, + recurse => true, + purge => true, + notify => Service['nagios'], + mode => 0755, owner => root, group => root; + } + + if $use_munin { + include nagios::munin } + } diff --git a/manifests/centos.pp b/manifests/centos.pp index 95c8749..4d9507b 100644 --- a/manifests/centos.pp +++ b/manifests/centos.pp @@ -1,47 +1,19 @@ class nagios::centos inherits nagios::base { + package { [ 'nagios-plugins', '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-plugins-swap', 'nagios-plugins-nagios', 'nagios-plugins-perl', 'nagios-plugins-ntp', 'nagios-plugins-snmp' ]: ensure => 'present', - notify => Service[nagios], + notify => 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/commands.cfg", - source => [ "puppet://$server/modules/site-nagios/configs/${fqdn}/commands.cfg", - "puppet://$server/modules/site-nagios/configs/${operatingsystem}/commands.cfg", - "puppet://$server/modules/nagios/configs/${operatingsystem}/commands.cfg" ], - owner => 'root', - group => 0, - mode => '0644', - notify => Service[nagios], - } - # default file from rpm - file { nagios_localhost_cfg: - path => "/etc/nagios/localhost.cfg", - source => [ "puppet://$server/modules/site-nagios/configs/${fqdn}/localhost.cfg", - "puppet://$server/modules/site-nagios/configs/${operatingsystem}/localhost.cfg", - "puppet://$server/modules/nagios/configs/${operatingsystem}/localhost.cfg" ], - owner => 'root', - group => 0, - mode => '0644', - notify => Service[nagios], - } - file{"/etc/nagios/private": - source => "puppet://$server/modules/common/empty", - ensure => directory, - purge => true, - recurse => true, - notify => Service[nagios], - mode => '0750', owner => root, group => nagios; - } - file{"/etc/nagios/private/resource.cfg": - source => "puppet://$server/modules/nagios/configs/${operatingsystem}/private/resource.cfg.${architecture}", - notify => Service[nagios], - owner => root, group => nagios, mode => '0640'; + if ($nagios_allow_external_cmd) { + file { '/var/spool/nagios/cmd': + ensure => 'directory', + require => Package['nagios'], + mode => 2660, owner => apache, group => nagios, + } } } diff --git a/manifests/command.pp b/manifests/command.pp deleted file mode 100644 index 066189c..0000000 --- a/manifests/command.pp +++ /dev/null @@ -1,11 +0,0 @@ -# just a wrapper to make the notify more easy -define nagios::command( - $ensure = present, - $command_line -){ - nagios_command{$name: - ensure => $ensure, - command_line => $command_line, - notify => Service[nagios], - } -} diff --git a/manifests/debian.pp b/manifests/debian.pp new file mode 100644 index 0000000..a503324 --- /dev/null +++ b/manifests/debian.pp @@ -0,0 +1,41 @@ +class nagios::debian inherits nagios::base { + + Package['nagios'] { name => 'nagios3' } + + package { [ 'nagios-plugins', 'nagios-snmp-plugins','nagios-nrpe-plugin' ]: + ensure => 'present', + notify => Service['nagios'], + } + + Service['nagios'] { + name => 'nagios3', + hasstatus => true, + } + + File['nagios_htpasswd', 'nagios_cgi_cfg'] { group => 'www-data' } + + file { "${nagios_cfgdir}/stylesheets": + ensure => directory, + purge => false, + recurse => true, + } + + if ($nagios_allow_external_cmd) { + exec { 'nagios_external_cmd_perms_overrides': + command => 'dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw && dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3', + unless => 'dpkg-statoverride --list nagios www-data 2710 /var/lib/nagios3/rw && dpkg-statoverride --list nagios nagios 751 /var/lib/nagios3', + logoutput => false, + notify => Service['nagios'], + } + exec { 'nagios_external_cmd_perms_1': + command => 'chmod 0751 /var/lib/nagios3 && chown nagios:nagios /var/lib/nagios3', + unless => 'test "`stat -c "%a %U %G" /var/lib/nagios3`" = "751 nagios nagios"', + notify => Service['nagios'], + } + exec { 'nagios_external_cmd_perms_2': + command => 'chmod 2751 /var/lib/nagios3/rw && chown nagios:www-data /var/lib/nagios3/rw', + unless => 'test "`stat -c "%a %U %G" /var/lib/nagios3/rw`" = "2751 nagios www-data"', + notify => Service['nagios'], + } + } +} diff --git a/manifests/defaults.pp b/manifests/defaults.pp new file mode 100644 index 0000000..32ba335 --- /dev/null +++ b/manifests/defaults.pp @@ -0,0 +1,12 @@ +class nagios::defaults { + + # include some default nagios objects + + include nagios::defaults::commands + include nagios::defaults::contactgroups + include nagios::defaults::contacts + include nagios::defaults::hostgroups + include nagios::defaults::templates + include nagios::defaults::timeperiods + +} diff --git a/manifests/defaults/commands.pp b/manifests/defaults/commands.pp new file mode 100644 index 0000000..c3190af --- /dev/null +++ b/manifests/defaults/commands.pp @@ -0,0 +1,75 @@ +class nagios::defaults::commands { + + # common service commands + + nagios_command { + check_dummy: + command_line => '$USER1$/check_dummy $ARG1$'; + check_ping: + command_line => '$USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$'; + check-host-alive: + command_line => '$USER1$/check_ping -H $HOSTADDRESS$ -w 5000,100% -c 5000,100% -p 1'; + check_tcp: + command_line => '$USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$'; + check_udp: + command_line => '$USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$'; + check_load: + command_line => '$USER1$/check_load --warning=$ARG1$,$ARG2$,$ARG3$ --critical=$ARG4$,$ARG5$,$ARG6$'; + check_disk: + command_line => '$USER1$/check_disk -w $ARG1$ -c $ARG2$ -e -p $ARG3$'; + check_all_disks: + command_line => '$USER1$/check_disk -w $ARG1$ -c $ARG2$ -e'; + check_ssh: + command_line => '$USER1$/check_ssh $HOSTADDRESS$'; + check_ssh_port: + command_line => '$USER1$/check_ssh -p $ARG1$ $HOSTADDRESS$'; + check_http: + command_line => '$USER1$/check_http -H $HOSTADDRESS$ -I $HOSTADDRESS$'; + check_https: + command_line => '$USER1$/check_http --ssl -H $HOSTADDRESS$ -I $HOSTADDRESS$'; + check_https_cert: + command_line => '$USER1$/check_http --ssl -C 20 -H $HOSTADDRESS$ -I $HOSTADDRESS$'; + check_http_url: + command_line => '$USER1$/check_http -H $ARG1$ -u $ARG2$'; + check_http_url_regex: + command_line => '$USER1$/check_http -H $ARG1$ -u $ARG2$ -e $ARG3$'; + check_https_url: + command_line => '$USER1$/check_http --ssl -H $ARG1$ -u $ARG2$'; + check_https_url_regex: + command_line => '$USER1$/check_http --ssl -H $ARG1$ -u $ARG2$ -e $ARG3$'; + check_mysql: + command_line => '$USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$'; + check_mysql_db: + command_line => '$USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$'; + check_ntp_time: + command_line => '$USER1$/check_ntp_time -H $HOSTADDRESS$ -w 0.5 -c 1'; + check_silc: + command_line => '$USER1$/check_tcp -p 706 -H $ARG1$'; + check_sobby: + command_line => '$USER1$/check_tcp -H $ARG1$ -p $ARG2$'; + check_jabber: + command_line => '$USER1$/check_jabber -H $ARG1$'; + } + + # commands for services defined by other modules + + nagios_command { + # from apache module + http_port: + command_line => '$USER1$/check_http -p $ARG1$ -H $HOSTADDRESS$ -I $HOSTADDRESS$'; + # from bind module + check_dig2: + command_line => '$USER1$/check_dig -H $HOSTADDRESS$ -l $ARG1$ --record_type=$ARG2$'; + } + + # notification commands + + nagios_command { + 'notify-host-by-email': + command_line => '/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$'; + 'notify-service-by-email': + command_line => '/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$' + + } + +} diff --git a/manifests/defaults/contactgroups.pp b/manifests/defaults/contactgroups.pp new file mode 100644 index 0000000..f5affc6 --- /dev/null +++ b/manifests/defaults/contactgroups.pp @@ -0,0 +1,9 @@ +class nagios::defaults::contactgroups { + + nagios_contactgroup { + 'admins': + alias => 'Nagios Administrators', + members => 'root', + } + +} diff --git a/manifests/defaults/contacts.pp b/manifests/defaults/contacts.pp new file mode 100644 index 0000000..0252b5a --- /dev/null +++ b/manifests/defaults/contacts.pp @@ -0,0 +1,15 @@ +class nagios::defaults::contacts { + + nagios_contact { + 'root': + alias => 'Root', + 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@localhost', + } + +} diff --git a/manifests/defaults/host_templates.pp b/manifests/defaults/host_templates.pp new file mode 100644 index 0000000..699b965 --- /dev/null +++ b/manifests/defaults/host_templates.pp @@ -0,0 +1,24 @@ +class nagios::defaults::host_templates { + + # this inoperative for the moment, see : + # http://projects.reductivelabs.com/issues/1180 + + nagios_host { + 'generic-host': + notifications_enabled => '1', + event_handler_enabled => '1', + flap_detection_enabled => '1', + failure_prediction_enabled => '1', + process_perf_data => '1', + retain_status_information => '1', + retain_nonstatus_information => '1', + check_command => 'check-host-alive', + max_check_attempts => '10', + notification_interval => '0', + notification_period => '24x7', + notification_options => 'd,u,r', + contact_groups => 'admins', + register => '0', + } + +} diff --git a/manifests/defaults/hostgroups.pp b/manifests/defaults/hostgroups.pp new file mode 100644 index 0000000..3a4f4d1 --- /dev/null +++ b/manifests/defaults/hostgroups.pp @@ -0,0 +1,13 @@ +class nagios::defaults::hostgroups { + + nagios_hostgroup { + 'all': + alias => 'All Servers', + members => '*'; + 'debian-servers': + alias => 'Debian GNU/Linux Servers'; + 'centos-servers': + alias => 'CentOS GNU/Linux Servers'; + } + +} diff --git a/manifests/defaults/service_templates.pp b/manifests/defaults/service_templates.pp new file mode 100644 index 0000000..326ce05 --- /dev/null +++ b/manifests/defaults/service_templates.pp @@ -0,0 +1,32 @@ +class nagios::defaults::service_templates { + + # this inoperative for the moment, see : + # http://projects.reductivelabs.com/issues/1180 + + nagios_service { + 'generic-service': + active_checks_enabled => '1', + passive_checks_enabled => '1', + parallelize_check => '1', + obsess_over_service => '1', + check_freshness => '0', + notifications_enabled => '1', + event_handler_enabled => '1', + flap_detection_enabled => '1', + failure_prediction_enabled => '1', + process_perf_data => '1', + retain_status_information => '1', + retain_nonstatus_information => '1', + notification_interval => '0', + is_volatile => '0', + check_period => '24x7', + normal_check_interval => '5', + retry_check_interval => '1', + max_check_attempts => '4', + notification_period => '24x7', + notification_options => 'w,u,c,r', + contact_groups => 'admins', + register => '0', + } + +} diff --git a/manifests/defaults/templates.pp b/manifests/defaults/templates.pp new file mode 100644 index 0000000..5a3d23d --- /dev/null +++ b/manifests/defaults/templates.pp @@ -0,0 +1,14 @@ +class nagios::defaults::templates { + + file { 'nagios_templates': + path => "${nagios::nagios_cfgdir}/conf.d/nagios_templates.cfg", + source => [ "puppet://$server/modules/site-nagios/configs/${fqdn}/nagios_templates.cfg", + "puppet://$server/modules/site-nagios/configs/${operatingsystem}/nagios_templates.cfg", + "puppet://$server/modules/site-nagios/configs/nagios_templates.cfg", + "puppet://$server/modules/nagios/configs/${operatingsystem}/nagios_templates.cfg", + "puppet://$server/modules/nagios/configs/nagios_templates.cfg" ], + notify => Service['nagios'], + mode => 0644, owner => root, group => root; + } + +} diff --git a/manifests/defaults/timeperiods.pp b/manifests/defaults/timeperiods.pp new file mode 100644 index 0000000..0d05118 --- /dev/null +++ b/manifests/defaults/timeperiods.pp @@ -0,0 +1,33 @@ +class nagios::defaults::timeperiods { + + nagios_timeperiod { + '24x7': + alias => '24 Hours A Day, 7 Days A Week', + sunday => '00:00-24:00', + monday => '00:00-24:00', + tuesday => '00:00-24:00', + wednesday => '00:00-24:00', + thursday => '00:00-24:00', + friday => '00:00-24:00', + saturday => '00:00-24:00'; + 'workhours': + alias => 'Standard Work Hours', + monday => '09:00-17:00', + tuesday => '09:00-17:00', + wednesday => '09:00-17:00', + thursday => '09:00-17:00', + friday => '09:00-17:00'; + 'nonworkhours': + alias => 'Non-Work Hours', + sunday => '00:00-24:00', + monday => '00:00-09:00,17:00-24:00', + tuesday => '00:00-09:00,17:00-24:00', + wednesday => '00:00-09:00,17:00-24:00', + thursday => '00:00-09:00,17:00-24:00', + friday => '00:00-09:00,17:00-24:00', + saturday => '00:00-24:00'; + 'never': + alias => 'Never'; + } + +} diff --git a/manifests/extra_host.pp b/manifests/extra_host.pp deleted file mode 100644 index 8f52de0..0000000 --- a/manifests/extra_host.pp +++ /dev/null @@ -1,27 +0,0 @@ -# this will define a host which isn't managed by puppet. -# a ping serivce is automatically added -define nagios::extra_host( - $ensure = present, - $ip = 'absent', - $nagios_alias = 'absent', - $use = 'generic-host', - $parents = 'localhost' -) { - if $ensure == 'present' and ($ip == 'absent' or $nagios_alias == 'absent'){ - fail("You need to define \$ip and \$nagios_alias if extra_host should be present!") - } - nagios::host{$name: - ensure => $ensure, - ip => $ip, - nagios_alias => $nagios_alias, - use => $use, - parents => $parents - } - - nagios::service { "check_ping_${name}": - ensure => $ensure, - host_name => $name, - check_command => 'check_ping!100.0,20%!500.0,60%', - service_description => "check_ping_${nagios_alias}", - } -} diff --git a/manifests/headless.pp b/manifests/headless.pp new file mode 100644 index 0000000..cccfce7 --- /dev/null +++ b/manifests/headless.pp @@ -0,0 +1,4 @@ +class nagios::headless { + $nagios_httpd = 'absent' + include nagios +} diff --git a/manifests/host.pp b/manifests/host.pp deleted file mode 100644 index 8814738..0000000 --- a/manifests/host.pp +++ /dev/null @@ -1,37 +0,0 @@ -define nagios::host( - $ensure = present, - $ip = $fqdn, - $nagios_alias = $hostname, - $check_command = 'check-host-alive', - $max_check_attempts = 4, - $notification_interval = 120, - $notification_period = '24x7', - $notification_options = 'd,r', - $use = 'generic-host', - $nagios_contact_groups_in = $nagios_contact_groups, - $parents = 'localhost' ) -{ - $real_nagios_contact_groups = $nagios_contact_groups_in ? { - '' => 'admins', - default => $nagios_contact_groups_in - } - $real_nagios_parents = $parents ? { - '' => 'localhost', - default => $parents - } - - @@nagios_host { $name: - ensure => $ensure, - address => $ip, - alias => $nagios_alias, - check_command => $check_command, - max_check_attempts => $max_check_attempts, - notification_interval => $notification_interval, - notification_period => $notification_period, - notification_options => $notification_options, - parents => $real_nagios_parents, - contact_groups => $real_nagios_contact_groups, - use => $use, - notify => Service[nagios], - } -} diff --git a/manifests/init.pp b/manifests/init.pp index 6eca55f..1aecc3a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -15,8 +15,21 @@ # class nagios { + case $nagios_httpd { + 'absent': { } + 'lighttpd': { include lighttpd } + 'apache': { include apache } + default: { include apache } + } case $operatingsystem { - centos: { include nagios::centos } + 'centos': { + $nagios_cfgdir = '/etc/nagios' + include nagios::centos + } + 'debian': { + $nagios_cfgdir = '/etc/nagios3' + include nagios::debian + } default: { fail("No such operatingsystem: $operatingsystem yet defined") } } } diff --git a/manifests/lighttpd.pp b/manifests/lighttpd.pp new file mode 100644 index 0000000..27aff43 --- /dev/null +++ b/manifests/lighttpd.pp @@ -0,0 +1,4 @@ +class nagios::lighttpd { + $nagios_httpd = 'lighttpd' + include nagios +} diff --git a/manifests/munin.pp b/manifests/munin.pp new file mode 100644 index 0000000..92a389f --- /dev/null +++ b/manifests/munin.pp @@ -0,0 +1,28 @@ +class nagios::munin inherits munin::plugins::base { + + munin::plugin::deploy { + nagios_hosts: + source => 'nagios/munin/nagios_hosts', + config => 'user root'; + nagios_svc: + source => 'nagios/munin/nagios_svc', + config => 'user root'; + nagios_perf_hosts: + source => 'nagios/munin/nagios_perf', + config => 'user root'; + nagios_perf_svc: + source => 'nagios/munin/nagios_perf', + config => 'user root'; + } + + exec { 'munin_nagios2stats_link': + command => 'ln -s /usr/sbin/nagios2stats /usr/local/sbin/nagiostats', + onlyif => ["test ! -e /usr/local/sbin/nagiostats", "test -e /usr/sbin/nagios2stats"], + } + + exec { 'munin_nagios3stats_link': + command => 'ln -s /usr/sbin/nagios3stats /usr/local/sbin/nagiostats', + onlyif => ["test ! -e /usr/local/sbin/nagiostats", "test -e /usr/sbin/nagios3stats"], + } + +} diff --git a/manifests/nsca.pp b/manifests/nsca.pp new file mode 100644 index 0000000..d5be298 --- /dev/null +++ b/manifests/nsca.pp @@ -0,0 +1,3 @@ +class nagios::nsca { + include nagios::nsca::server +} diff --git a/manifests/nsca/client.pp b/manifests/nsca/client.pp new file mode 100644 index 0000000..b4ca878 --- /dev/null +++ b/manifests/nsca/client.pp @@ -0,0 +1,14 @@ +class nagios::nsca::client { + + package { 'nsca': ensure => installed } + + file { '/etc/send_nsca.cfg': + source => [ "puppet://${server}/site-nagios/nsca/{$fqdn}/send_nsca.cfg", + "puppet://${server}/site-nagios/nsca/send_nsca.cfg", + "puppet://${server}/nagios/nsca/send_nsca.cfg" ], + owner => 'nagios', + group => 'nogroup', + mode => '400', + } + +} diff --git a/manifests/nsca/server.pp b/manifests/nsca/server.pp new file mode 100644 index 0000000..c682e24 --- /dev/null +++ b/manifests/nsca/server.pp @@ -0,0 +1,21 @@ +class nagios::nsca::server { + + package { 'nsca': ensure => installed } + + service { 'nsca': + ensure => running, + hasstatus => false, + hasrestart => true, + } + + file { '/etc/nsca.cfg': + source => [ "puppet://${server}/site-nagios/nsca/{$fqdn}/nsca.cfg", + "puppet://${server}/site-nagios/nsca/nsca.cfg", + "puppet://${server}/nagios/nsca/nsca.cfg" ], + owner => 'nagios', + group => 'nogroup', + mode => '400', + notify => Service['nsca'], + } + +} diff --git a/manifests/service.pp b/manifests/service.pp index bb9b187..3e732b7 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -1,56 +1,69 @@ -define nagios::service( +define nagios::service ( $ensure = present, - $check_command = absent, $host_name = $fqdn, - $use = 'generic-service', - $notification_period = "24x7", - $max_check_attempts = 4, - $retry_check_interval = 1, - $notification_interval = 960, - $normal_check_interval = 5, - $check_period = "24x7", - $nagios_contact_groups_in = $nagios_contact_groups, - $service_description = 'absent') + $check_command, + $check_period = '', + $normal_check_interval = '', + $retry_check_interval = '', + $max_check_attempts = '', + $notification_interval = '', + $notification_period = '', + $notification_options = '', + $contact_groups = '', + $use = 'absent', + $service_description = 'absent' ) { - if $ensure == present and $check_command == absent { - fail("You have to define \$check_command if nagios::service shoudl be present!") - } + # TODO: this resource should normally accept all nagios_host parameters - # this ensures nagios internal check, that every - # service has it's host - # temporary disabled. - # include nagios::target::host + $real_name = "${hostname}_${name}" - $real_nagios_contact_groups = $nagios_contact_groups_in ? { - '' => 'admins', - default => $nagios_contact_groups_in - } - @@nagios_service {$name: + @@nagios_service { "${real_name}": ensure => $ensure, check_command => $check_command, - use => $use, host_name => $host_name, - notification_period => $notification_period, - max_check_attempts => $max_check_attempts, - retry_check_interval => $retry_check_interval, - notification_interval => $notification_interval, - normal_check_interval => $normal_check_interval, - contact_groups => $real_nagios_contact_groups, - check_period => $check_period, notify => Service[nagios], } - case $service_description { - 'absent': { - Nagios_service[$name]{ - service_description => $name, - } - } - default: { - Nagios_service[$name]{ - service_description => $service_description, - } - } + + if ($check_period != '') { + Nagios_service["${real_name}"] { check_period => $check_period } + } + + if ($normal_check_interval != '') { + Nagios_service["${real_name}"] { normal_check_interval => $normal_check_interval } + } + + if ($retry_check_interval != '') { + Nagios_service["${real_name}"] { retry_check_interval => $retry_check_interval } + } + + if ($max_check_attempts != '') { + Nagios_service["${real_name}"] { max_check_attempts => $max_check_attempts } + } + + if ($notification_interval != '') { + Nagios_service["${real_name}"] { notification_interval => $notification_interval } + } + + if ($notification_period != '') { + Nagios_service["${real_name}"] { notification_period => $notification_period } + } + + if ($notification_options != '') { + Nagios_service["${real_name}"] { notification_options => $notification_options } } + + if ($use == 'absent') { + Nagios_service["${real_name}"] { use => 'generic-service' } + } else { + Nagios_service["${real_name}"] { use => $use } + } + + if ($service_description == 'absent') { + Nagios_service["${real_name}"] { service_description => $name } + } else { + Nagios_service["${real_name}"] { service_description => $service_description } + } + } diff --git a/manifests/service/http.pp b/manifests/service/http.pp index 5c6cda1..5fd9890 100644 --- a/manifests/service/http.pp +++ b/manifests/service/http.pp @@ -16,13 +16,13 @@ define nagios::service::http( } case $ssl_mode { 'force',true,'only': { - nagios::service{"https_${name}_${check_code}_${hostname}": + nagios::service{"https_${name}_${check_code}": ensure => $ensure, check_command => "check_https_url_regex!${real_check_domain}!${check_url}!'${check_code}'", } case $ssl_mode { 'force': { - nagios::service{"httprd_${name}_${hostname}": + nagios::service{"httprd_${name}": ensure => $ensure, check_command => "check_http_url_regex!${real_check_domain}!${check_url}!'301'", } @@ -32,7 +32,7 @@ define nagios::service::http( } case $ssl_mode { false,true: { - nagios::service{"http_${name}_${check_code}_${hostname}": + nagios::service{"http_${name}_${check_code}": ensure => $ensure, check_command => "check_http_url_regex!${real_check_domain}!${check_url}!'${check_code}'", } diff --git a/manifests/service/mysql.pp b/manifests/service/mysql.pp new file mode 100644 index 0000000..ca2ae15 --- /dev/null +++ b/manifests/service/mysql.pp @@ -0,0 +1,48 @@ +# Checks a mysql instance via tcp or socket + +define nagios::service::mysql( + $ensure = present, + $check_hostname = 'absent', + $check_port = '3306', + $check_username = 'nagios', + $check_password = '', + $check_database = 'absent', + $check_mode = 'tcp' +){ + if ($check_hostname == 'absent') { + fail("Please specify a hostname, ip address or socket to check a mysql instance.") + } + + case $check_mode { + 'tcp': { + if ($check_hostname == 'localhost') { + $real_check_hostname = '127.0.0.1' + } + else { + $real_check_hostname = $check_hostname + } + } + default: { + if ($check_hostname == '127.0.0.1') { + $real_check_hostname = 'localhost' + } + else { + $real_check_hostname = $check_hostname + } + } + } + + if ($check_database == 'absent') { + nagios::service { 'mysql': + ensure => $ensure, + check_command => "check_mysql!${real_check_hostname}!${check_port}!${check_username}!${check_password}", + } + } + else { + nagios::service { "mysql_${check_database}": + ensure => $ensure, + check_command => "check_mysql_db!${real_check_hostname}!${check_port}!${check_username}!${check_password}!${check_database}", + } + } + +} diff --git a/manifests/service/ntp.pp b/manifests/service/ntp.pp index c07177d..eca255a 100644 --- a/manifests/service/ntp.pp +++ b/manifests/service/ntp.pp @@ -1,7 +1,7 @@ # manifests/service/ntp.pp class nagios::service::ntp { - nagios::service{ "check_ntp_${hostname}": + nagios::service{ "check_ntp": check_command => "check_ntp_time", host_name => $fqdn, } diff --git a/manifests/service/passive.pp b/manifests/service/passive.pp new file mode 100644 index 0000000..f3df1e8 --- /dev/null +++ b/manifests/service/passive.pp @@ -0,0 +1,18 @@ +define nagios::service::passive( + $ensure = present, + $notification_interval = '', + $notification_period = '', + $notification_options = '', + $contact_groups = '' +) { + + nagios::service { $name: + use => 'passive-service', + check_command => 'check_dummy!0', + notification_interval => $notification_interval, + notification_period => $notification_period, + notification_options => $notification_options, + contact_groups => $contact_groups, + } + +} diff --git a/manifests/service/ping.pp b/manifests/service/ping.pp index 63a5400..c705c68 100644 --- a/manifests/service/ping.pp +++ b/manifests/service/ping.pp @@ -6,7 +6,7 @@ define nagios::service::ping( default => $nagios_ping_rate } - nagios::service{ "check_ping_${hostname}": + nagios::service{ "check_ping": ensure => $ensure, check_command => "check_ping${real_nagios_ping_rate}", } diff --git a/manifests/target.pp b/manifests/target.pp index 07aae93..675ac1a 100644 --- a/manifests/target.pp +++ b/manifests/target.pp @@ -1,6 +1,15 @@ # manifests/target.pp class nagios::target { - include nagios::target::host - nagios::service::ping{$fqdn:} + + @@nagios_host { "${fqdn}": + address => $ipaddress, + alias => $hostname, + use => 'generic-host', + } + + if ($nagios_parents != '') { + Nagios_host["${fqdn}"] { parents => $nagios_parents } + } + } diff --git a/manifests/target/host.pp b/manifests/target/host.pp deleted file mode 100644 index 8ba4e77..0000000 --- a/manifests/target/host.pp +++ /dev/null @@ -1,6 +0,0 @@ -# manifests/target/host.pp - -class nagios::target::host { - nagios::host { $fqdn: parents => $nagios_parent } -} - diff --git a/manifests/target/nat.pp b/manifests/target/nat.pp new file mode 100644 index 0000000..abb0a1e --- /dev/null +++ b/manifests/target/nat.pp @@ -0,0 +1,5 @@ +class nagios::target::nat inherits nagios::target { + + Nagios_host["${fqdn}"] { address => "${fqdn}" } + +} |