From: Ismaƫl Bouya Date: Sun, 8 Jul 2018 13:35:43 +0000 (+0200) Subject: Prepare master monitoring X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FPuppet.git;a=commitdiff_plain;h=6962463657db999c33f1aabe60e0567be218918d Prepare master monitoring --- diff --git a/modules/profile/manifests/monitoring/commands.pp b/modules/profile/manifests/monitoring/commands.pp index 7e9683f..a25f7b3 100644 --- a/modules/profile/manifests/monitoring/commands.pp +++ b/modules/profile/manifests/monitoring/commands.pp @@ -31,6 +31,7 @@ class profile::monitoring::commands inherits profile::monitoring { target => "/etc/naemon/objects.cfg", notify => Service["naemon"], before => Service["naemon"], + require => File["/etc/naemon"], } nagios_command { diff --git a/modules/profile/manifests/monitoring/contacts.pp b/modules/profile/manifests/monitoring/contacts.pp index 284d51c..107af18 100644 --- a/modules/profile/manifests/monitoring/contacts.pp +++ b/modules/profile/manifests/monitoring/contacts.pp @@ -1,11 +1,12 @@ class profile::monitoring::contacts { Nagios_contactgroup { - ensure => "present", - owner => "naemon", - group => "naemon", - target => "/etc/naemon/objects.cfg", - notify => Service["naemon"], - before => Service["naemon"], + ensure => "present", + owner => "naemon", + group => "naemon", + target => "/etc/naemon/objects.cfg", + notify => Service["naemon"], + before => Service["naemon"], + require => File["/etc/naemon"], } nagios_contactgroup { "admins": diff --git a/modules/profile/manifests/monitoring/hosts.pp b/modules/profile/manifests/monitoring/hosts.pp index 306fe3e..3c8bc73 100644 --- a/modules/profile/manifests/monitoring/hosts.pp +++ b/modules/profile/manifests/monitoring/hosts.pp @@ -2,21 +2,23 @@ class profile::monitoring::hosts { $real_hostname = lookup("base_installation::real_hostname") Nagios_hostgroup { - ensure => "present", - owner => "naemon", - group => "naemon", - target => "/etc/naemon/objects.cfg", - notify => Service["naemon"], - before => Service["naemon"], + ensure => "present", + owner => "naemon", + group => "naemon", + target => "/etc/naemon/objects.cfg", + notify => Service["naemon"], + before => Service["naemon"], + require => File["/etc/naemon"], } Nagios_host { - ensure => "present", - owner => "naemon", - group => "naemon", - target => "/etc/naemon/objects.cfg", - notify => Service["naemon"], - before => Service["naemon"], + ensure => "present", + owner => "naemon", + group => "naemon", + target => "/etc/naemon/objects.cfg", + notify => Service["naemon"], + before => Service["naemon"], + require => File["/etc/naemon"], } nagios_hostgroup { "linux-servers": diff --git a/modules/profile/manifests/monitoring/local_service.pp b/modules/profile/manifests/monitoring/local_service.pp new file mode 100644 index 0000000..3b39d1f --- /dev/null +++ b/modules/profile/manifests/monitoring/local_service.pp @@ -0,0 +1,65 @@ +define profile::monitoring::local_service ( + Optional[Hash] $common = {}, + Optional[Hash] $master = {}, + Optional[Hash] $local = {}, +) { + $service_description = $title + $real_hostname = lookup("base_installation::real_hostname") + + $service_generic = { + active_checks_enabled => "1", + check_freshness => "0", + check_interval => "10", + check_period => "24x7", + contact_groups => "admins", + event_handler_enabled => "1", + flap_detection_enabled => "1", + is_volatile => "0", + max_check_attempts => "3", + notification_interval => "60", + notification_options => "w,u,c,r", + notification_period => "24x7", + notifications_enabled => "0", + obsess_over_service => "1", + passive_checks_enabled => "1", + process_perf_data => "1", + retain_nonstatus_information => "1", + retain_status_information => "1", + retry_interval => "2", + } + + $service_local = merge($service_generic, { + host_name => $real_hostname, + check_interval => "5", + max_check_attempts => "4", + retry_interval => "1", + }) + + + [true, false].each |$services_for_master| { + if $services_for_master { + $default_local = { + mode => "0644", + target => "/etc/naemon/services_for_master.cfg", + check_interval => $service_local["check_interval"], + retry_interval => $service_local["retry_interval"], + host_name => $service_local["host_name"], + use => "external-service", + notify => [], + } + $t = "master - " + $services_key = $master + } else { + $default_local = merge($service_local, { target => "/etc/naemon/objects.cfg" }) + $t = "" + $services_key = $local + } + + $hash = merge($default_local, $common, $services_key) + + nagios_service { "$t$service_description": + service_description => $service_description, + * => $hash + } + } +} diff --git a/modules/profile/manifests/monitoring/services.pp b/modules/profile/manifests/monitoring/services.pp index 39c2def..6e59ab1 100644 --- a/modules/profile/manifests/monitoring/services.pp +++ b/modules/profile/manifests/monitoring/services.pp @@ -1,45 +1,14 @@ class profile::monitoring::services { - $real_hostname = lookup("base_installation::real_hostname") Nagios_service { - ensure => "present", - owner => "naemon", - group => "naemon", - target => "/etc/naemon/objects.cfg", - notify => Service["naemon"], - before => Service["naemon"], + ensure => "present", + owner => "naemon", + group => "naemon", + notify => Service["naemon"], + before => Service["naemon"], + require => File["/etc/naemon"], } - $service_generic = { - active_checks_enabled => "1", - check_freshness => "0", - check_interval => "10", - check_period => "24x7", - contact_groups => "admins", - event_handler_enabled => "1", - flap_detection_enabled => "1", - is_volatile => "0", - max_check_attempts => "3", - notification_interval => "60", - notification_options => "w,u,c,r", - notification_period => "24x7", - notifications_enabled => "1", - obsess_over_service => "1", - passive_checks_enabled => "1", - process_perf_data => "1", - retain_nonstatus_information => "1", - retain_status_information => "1", - retry_interval => "2", - } - - - $service_local = merge($service_generic, { - host_name => $real_hostname, - check_interval => "5", - max_check_attempts => "4", - retry_interval => "1", - }) - sudo::conf { default: sudo_file_name => "naemon"; @@ -47,43 +16,38 @@ class profile::monitoring::services { content => "naemon ALL=(root) NOPASSWD: /usr/bin/fail2ban-client ping"; } - nagios_service { - default: * => $service_local; + profile::monitoring::local_service { "Size on root partition": - service_description => "Size on root partition", - check_command => "check_local_disk!20%!10%!/"; + local => { + check_command => "check_local_disk!20%!10%!/", + }; "Total number of process": - service_description => "Total number of process", - check_command => "check_local_procs!250!400!RSZDT"; + local => { + check_command => "check_local_procs!50!100!RSZDT", + }; "Average load": - service_description => "Average load", - check_command => "check_local_load!8.0,8.0,8.0!10.0,10.0,10.0"; + local => { + check_command => "check_local_load!8.0,8.0,8.0!10.0,10.0,10.0", + }; "Swap usage": - service_description => "Swap usage", - check_command => "check_local_swap!20!10"; + local => { + check_command => "check_local_swap!20!10", + }; "fail2ban is active": - service_description => "fail2ban is active", - check_command => "check_command_output!fail2ban-client ping!pong!-r root", - require => Sudo::Conf["naemon-fail2ban"]; + local => { + check_command => "check_command_output!fail2ban-client ping!pong!-r root", + require => Sudo::Conf["naemon-fail2ban"], + }; "NTP is activated and working": - service_description => "NTP is activated and working", - check_command => "check_ntp"; - } - - if empty(find_file("/proc/mdstat")) { - nagios_service { - default: * => $service_local; - "No mdadm array is degraded": - ensure => "absent", - service_description => "No mdadm array is degraded", - check_command => "check_md_raid"; - } - } else { - nagios_service { - default: * => $service_local; - "No mdadm array is degraded": - service_description => "No mdadm array is degraded", - check_command => "check_md_raid"; - } + local => { + check_command => "check_ntp", + }; + "No mdadm array is degraded": + common => { + ensure => (find_file("/proc/mdstat") == undef) ? { true => "absent", default =>"present" }, + }, + local => { + check_command => "check_md_raid", + }; } } diff --git a/modules/profile/manifests/monitoring/times.pp b/modules/profile/manifests/monitoring/times.pp index fb61acc..25bf86b 100644 --- a/modules/profile/manifests/monitoring/times.pp +++ b/modules/profile/manifests/monitoring/times.pp @@ -1,11 +1,12 @@ class profile::monitoring::times { Nagios_timeperiod { - ensure => "present", - owner => "naemon", - group => "naemon", - target => "/etc/naemon/objects.cfg", - notify => Service["naemon"], - before => Service["naemon"], + ensure => "present", + owner => "naemon", + group => "naemon", + target => "/etc/naemon/objects.cfg", + notify => Service["naemon"], + before => Service["naemon"], + require => File["/etc/naemon"], } nagios_timeperiod { "24x7":