]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Prepare master monitoring
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 8 Jul 2018 13:35:43 +0000 (15:35 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 9 Jul 2018 18:16:21 +0000 (20:16 +0200)
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 [new file with mode: 0644]
modules/profile/manifests/monitoring/services.pp
modules/profile/manifests/monitoring/times.pp

index 7e9683f70809ebe8373ad6de6c0a681876f3149a..a25f7b3e6af655e42da1523e7c1252a53c9ee2ab 100644 (file)
@@ -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 {
index 284d51c9b536b24541cce096c12b068eaf6ce50e..107af18364ca20c74ebfa95f6be72241056e0b46 100644 (file)
@@ -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":
index 306fe3e5a9e89bd56fa27967f10791a7a48f5f87..3c8bc73cd4c284dbdfc604607674140c7d36c70f 100644 (file)
@@ -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 (file)
index 0000000..3b39d1f
--- /dev/null
@@ -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
+    }
+  }
+}
index 39c2deff73194733f6169153b2d65b272593f7f6..6e59ab1f91c21937c611f2b6ed3bf93a7e5e09df 100644 (file)
@@ -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",
+      };
   }
 }
index fb61acc341662cf15d8a9f525154bad0ac709e76..25bf86b0def6ffc293a0905531700cbd8b95d16f 100644 (file)
@@ -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":