From: Ismaƫl Bouya Date: Wed, 11 Jul 2018 05:45:22 +0000 (+0200) Subject: Refactor a bit monitoring profile X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=0363f38e186b8c942a6db2de4974befbc373f618;p=perso%2FImmae%2FProjets%2FPuppet.git Refactor a bit monitoring profile --- diff --git a/modules/profile/manifests/monitoring.pp b/modules/profile/manifests/monitoring.pp index 7df4ce9..8633626 100644 --- a/modules/profile/manifests/monitoring.pp +++ b/modules/profile/manifests/monitoring.pp @@ -1,7 +1,7 @@ class profile::monitoring ( Optional[String] $naemon_url = undef, Optional[String] $naemon_token = undef, -) { +) inherits profile::monitoring::params { ensure_packages(["naemon", "cnagios"]) file { "/etc/naemon": @@ -28,7 +28,7 @@ class profile::monitoring ( content => template("profile/monitoring/naemon.cfg.erb"), } -> - file { "/etc/naemon/objects.cfg": + file { $objects: ensure => "file", owner => "naemon", group => "naemon", diff --git a/modules/profile/manifests/monitoring/commands.pp b/modules/profile/manifests/monitoring/commands.pp index 4ccc816..1c8d0b4 100644 --- a/modules/profile/manifests/monitoring/commands.pp +++ b/modules/profile/manifests/monitoring/commands.pp @@ -1,7 +1,7 @@ class profile::monitoring::commands inherits profile::monitoring { ensure_packages(["monitoring-plugins"]) - file { "/etc/naemon/monitoring-plugins": + file { $plugins: ensure => "directory", owner => "root", group => "naemon", @@ -14,7 +14,7 @@ class profile::monitoring::commands inherits profile::monitoring { "check_postgres_replication", "check_last_file_date", ].each |$file| { - file { "/etc/naemon/monitoring-plugins/$file": + file { "$plugins/$file": ensure => "present", owner => "root", group => "naemon", @@ -27,7 +27,7 @@ class profile::monitoring::commands inherits profile::monitoring { ensure => "present", owner => "naemon", group => "naemon", - target => "/etc/naemon/objects.cfg", + target => $objects, notify => Service["naemon"], before => Service["naemon"], require => File["/etc/naemon"], @@ -48,16 +48,16 @@ class profile::monitoring::commands inherits profile::monitoring { command_line => '$USER1$/check_ntp_time -H 0.arch.pool.ntp.org'; "check_md_raid": command_line => '$USER2$/check_md_raid', - require => File["/etc/naemon/monitoring-plugins/check_md_raid"]; + require => File["$plugins/check_md_raid"]; "check_command_output": command_line => '$USER2$/check_command -c "$ARG1$" -o "$ARG2$" $ARG3$', - require => File["/etc/naemon/monitoring-plugins/check_command"]; + require => File["$plugins/check_command"]; "check_postgresql_replication": command_line => '/usr/bin/sudo -u postgres $USER2$/check_postgres_replication "$ARG1$" "$ARG2$" "$ARG3$"', - require => File["/etc/naemon/monitoring-plugins/check_postgres_replication"]; + require => File["$plugins/check_postgres_replication"]; "check_last_file_date": command_line => '$USER2$/check_last_file_date "$ARG1$" "$ARG2$" "$ARG3$"', - require => File["/etc/naemon/monitoring-plugins/check_last_file_date"], + require => File["$plugins/check_last_file_date"], } unless empty($naemon_url) { diff --git a/modules/profile/manifests/monitoring/contacts.pp b/modules/profile/manifests/monitoring/contacts.pp index 107af18..a751153 100644 --- a/modules/profile/manifests/monitoring/contacts.pp +++ b/modules/profile/manifests/monitoring/contacts.pp @@ -1,9 +1,9 @@ -class profile::monitoring::contacts { +class profile::monitoring::contacts inherits profile::monitoring::params { Nagios_contactgroup { ensure => "present", owner => "naemon", group => "naemon", - target => "/etc/naemon/objects.cfg", + target => $objects, notify => Service["naemon"], before => Service["naemon"], require => File["/etc/naemon"], diff --git a/modules/profile/manifests/monitoring/hosts.pp b/modules/profile/manifests/monitoring/hosts.pp index 3c8bc73..f7802be 100644 --- a/modules/profile/manifests/monitoring/hosts.pp +++ b/modules/profile/manifests/monitoring/hosts.pp @@ -1,11 +1,11 @@ -class profile::monitoring::hosts { +class profile::monitoring::hosts inherits profile::monitoring::params { $real_hostname = lookup("base_installation::real_hostname") Nagios_hostgroup { ensure => "present", owner => "naemon", group => "naemon", - target => "/etc/naemon/objects.cfg", + target => $objects, notify => Service["naemon"], before => Service["naemon"], require => File["/etc/naemon"], @@ -15,7 +15,7 @@ class profile::monitoring::hosts { ensure => "present", owner => "naemon", group => "naemon", - target => "/etc/naemon/objects.cfg", + target => $objects, notify => Service["naemon"], before => Service["naemon"], require => File["/etc/naemon"], diff --git a/modules/profile/manifests/monitoring/local_service.pp b/modules/profile/manifests/monitoring/local_service.pp index 9af7c7a..9544fdf 100644 --- a/modules/profile/manifests/monitoring/local_service.pp +++ b/modules/profile/manifests/monitoring/local_service.pp @@ -4,8 +4,9 @@ define profile::monitoring::local_service ( Optional[Hash] $master = {}, Optional[Hash] $local = {}, ) { + include profile::monitoring::params + $service_description = $title - $real_hostname = lookup("base_installation::real_hostname") Nagios_service { ensure => "present", @@ -16,35 +17,6 @@ define profile::monitoring::local_service ( 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 => "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", - }) - $sudos.each |$sudo_name, $content| { ensure_resource("sudo::conf", $sudo_name, { content => $content, @@ -56,17 +28,20 @@ define profile::monitoring::local_service ( 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", + target => $::profile::monitoring::params::services_for_master, + check_interval => $::profile::monitoring::params::service_local["check_interval"], + retry_interval => $::profile::monitoring::params::service_local["retry_interval"], + host_name => $::profile::monitoring::params::service_local["host_name"], + use => "external-passive-service", notify => [], } $t = "master - " $services_key = $master } else { - $default_local = merge($service_local, { target => "/etc/naemon/objects.cfg" }) + $default_local = merge( + $::profile::monitoring::params::service_local, + { target => $::profile::monitoring::params::objects } + ) $t = "" $services_key = $local } diff --git a/modules/profile/manifests/monitoring/params.pp b/modules/profile/manifests/monitoring/params.pp new file mode 100644 index 0000000..a647130 --- /dev/null +++ b/modules/profile/manifests/monitoring/params.pp @@ -0,0 +1,37 @@ +class profile::monitoring::params { + $real_hostname = lookup("base_installation::real_hostname") + + $services_for_master = "/etc/naemon/services_for_master.cfg" + $objects = "/etc/naemon/objects.cfg" + $plugins = "/etc/naemon/monitoring-plugins" + + $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", + }) + +} diff --git a/modules/profile/manifests/monitoring/times.pp b/modules/profile/manifests/monitoring/times.pp index 25bf86b..42f5d9c 100644 --- a/modules/profile/manifests/monitoring/times.pp +++ b/modules/profile/manifests/monitoring/times.pp @@ -1,9 +1,9 @@ -class profile::monitoring::times { +class profile::monitoring::times inherits profile::monitoring::params { Nagios_timeperiod { ensure => "present", owner => "naemon", group => "naemon", - target => "/etc/naemon/objects.cfg", + target => $objects, notify => Service["naemon"], before => Service["naemon"], require => File["/etc/naemon"], diff --git a/modules/profile/templates/monitoring/naemon.cfg.erb b/modules/profile/templates/monitoring/naemon.cfg.erb index 78bada3..bacbe04 100644 --- a/modules/profile/templates/monitoring/naemon.cfg.erb +++ b/modules/profile/templates/monitoring/naemon.cfg.erb @@ -26,7 +26,7 @@ log_file=/var/log/naemon/naemon.log # if you wish (as shown below), or keep them all in a single config file. # You can specify individual object config files as shown below: -cfg_file=/etc/naemon/objects.cfg +cfg_file=<%= @objects %> #cfg_file=/etc/naemon/objects/commands.cfg #cfg_file=/etc/naemon/objects/contacts.cfg #cfg_file=/etc/naemon/objects/timeperiods.cfg diff --git a/modules/profile/templates/monitoring/resource.cfg.erb b/modules/profile/templates/monitoring/resource.cfg.erb index 7da5e66..5a5c3ee 100644 --- a/modules/profile/templates/monitoring/resource.cfg.erb +++ b/modules/profile/templates/monitoring/resource.cfg.erb @@ -20,7 +20,7 @@ # Sets $USER1$ to be the path to the plugins $USER1$=/usr/lib/monitoring-plugins -$USER2$=/etc/naemon/monitoring-plugins +$USER2$=<%= @plugins %> # Sets $USER2$ to be the path to event handlers #$USER2$=/usr/lib/monitoring-plugins/eventhandlers