]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Refactor a bit monitoring profile
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 11 Jul 2018 05:45:22 +0000 (07:45 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Wed, 11 Jul 2018 06:02:15 +0000 (08:02 +0200)
modules/profile/manifests/monitoring.pp
modules/profile/manifests/monitoring/commands.pp
modules/profile/manifests/monitoring/contacts.pp
modules/profile/manifests/monitoring/hosts.pp
modules/profile/manifests/monitoring/local_service.pp
modules/profile/manifests/monitoring/params.pp [new file with mode: 0644]
modules/profile/manifests/monitoring/times.pp
modules/profile/templates/monitoring/naemon.cfg.erb
modules/profile/templates/monitoring/resource.cfg.erb

index 7df4ce944f5109243b00db7b7d0c0521ebbd58f9..8633626f512fcd53df96f2a51bb7b85704890368 100644 (file)
@@ -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",
index 4ccc816ccbccb4483d75ef64ded962464ad45e80..1c8d0b46997a53edd05bd39fda1b49a57c8c1750 100644 (file)
@@ -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) {
index 107af18364ca20c74ebfa95f6be72241056e0b46..a751153b8f171517c6cf686e63bbe7882320b100 100644 (file)
@@ -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"],
index 3c8bc73cd4c284dbdfc604607674140c7d36c70f..f7802bec8a2e5d421e49ceaa56391abc4c198983 100644 (file)
@@ -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"],
index 9af7c7af2b600e711d231de88ec49239664566c4..9544fdf45070c611323e4136bd512797d15a6b68 100644 (file)
@@ -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 (file)
index 0000000..a647130
--- /dev/null
@@ -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",
+    })
+
+}
index 25bf86b0def6ffc293a0905531700cbd8b95d16f..42f5d9c3d595619039f8d97ae215a331c8dc736c 100644 (file)
@@ -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"],
index 78bada3f8f165de500719221c44261efb2320170..bacbe043c976a909af811b359b4af615206091fd 100644 (file)
@@ -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
index 7da5e66c0ef66e98d85c6b4f9eac38a46d290f3c..5a5c3eec9aa5ef061dcf36ef68a2b1f24a8594b4 100644 (file)
@@ -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