]> git.immae.eu Git - perso/Immae/Projets/Puppet.git/commitdiff
Add monitoring for cryptoportfolio
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 12 Jul 2018 06:21:21 +0000 (08:21 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Thu, 12 Jul 2018 06:51:02 +0000 (08:51 +0200)
modules/profile/files/monitoring/check_date [new file with mode: 0644]
modules/profile/files/monitoring/check_last_file_date
modules/profile/manifests/monitoring/commands.pp
modules/role/manifests/cryptoportfolio/bot.pp
modules/role/manifests/cryptoportfolio/front.pp
readme.md

diff --git a/modules/profile/files/monitoring/check_date b/modules/profile/files/monitoring/check_date
new file mode 100644 (file)
index 0000000..e7ac38a
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+STATE_OK=0
+STATE_WARNING=1
+STATE_CRITICAL=2
+STATE_UNKNOWN=3
+  
+run_command="$1"
+hours="$2"
+as_user="$3"
+
+if [ -z "$as_user" ]; then
+  last_date=$($run_command 2>/dev/null | sort | tail -n 1)
+else
+  last_date=$(sudo -u "$as_user" $run_command 2>/dev/null | sort | tail -n 1)
+fi
+
+if [ -z "$last_date" ]; then
+  echo "UNKNOWN: Could not read date"
+  exit $STATE_UNKNOWN
+else
+  last_date=$(date -d "$last_date" "+%s")
+  LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
+  min_date=$(date -d "$hours hours ago" "+%s")
+  if [ "$min_date" -lt "$last_date" ]; then
+    echo "OK: Last date $(date -d @$last_date)"
+    exit $STATE_OK
+  else
+    echo "CRITICAL: Last date $(date -d @$last_date)"
+    exit $STATE_CRITICAL
+  fi
+fi
index 8eabb57455175d6e99493a5fa1aef9755d9ed5a8..d520a84c75e9bf8c50dd6e212dc5ff788e7d2568 100644 (file)
@@ -22,10 +22,10 @@ else
   LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
   min_date=$(date -d "$hours hours ago" "+%s")
   if [ "$min_date" -lt "$last_date" ]; then
-    echo "OK: Last backup $(date -d @$last_date)"
+    echo "OK: Last file $(date -d @$last_date)"
     exit $STATE_OK
   else
-    echo "CRITICAL: Last backup $(date -d @$last_date)"
+    echo "CRITICAL: Last file $(date -d @$last_date)"
     exit $STATE_CRITICAL
   fi
 fi
index 1c8d0b46997a53edd05bd39fda1b49a57c8c1750..7c5d8ed7a3e24be70e4a0cbe288b930731f6f6c8 100644 (file)
@@ -12,6 +12,7 @@ class profile::monitoring::commands inherits profile::monitoring {
     "check_command",
     "check_md_raid",
     "check_postgres_replication",
+    "check_date",
     "check_last_file_date",
   ].each |$file| {
     file { "$plugins/$file":
@@ -57,7 +58,10 @@ class profile::monitoring::commands inherits profile::monitoring {
       require      => File["$plugins/check_postgres_replication"];
     "check_last_file_date":
       command_line => '$USER2$/check_last_file_date "$ARG1$" "$ARG2$" "$ARG3$"',
-      require      => File["$plugins/check_last_file_date"],
+      require      => File["$plugins/check_last_file_date"];
+    "check_date":
+      command_line => '$USER2$/check_date "$ARG1$" "$ARG2$" "$ARG3$"',
+      require      => File["$plugins/check_date"];
   }
 
   unless empty($naemon_url) {
index 2f01c98ab6735b59bdaa0267cadf6781c017b747..fd3ece37947cedf1c645174a84e67aec8ff25869 100644 (file)
@@ -81,6 +81,24 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio {
     ],
   }
 
+  if ($environment == "production") {
+    $monitored_key = 3
+    @profile::monitoring::local_service { "Last redis report is less than 2 hours old":
+      local => {
+        check_command => "check_date!redis-cli -s $redis_host GET /cryptoportfolio/$monitored_key/latest/date!2"
+      }
+    }
+
+    @profile::monitoring::local_service { "Last bot report is less than one week old":
+      sudos => {
+        "naemon-cryptoportfolio-bot" => "naemon  ALL=($user) NOPASSWD: /usr/bin/find $cf_bot_app_reports -mindepth 1 -maxdepth 1 -printf %T@?n",
+      },
+      local => {
+        check_command => "check_last_file_date!$cf_bot_app_reports!168!$user",
+      },
+    }
+  }
+
   if versioncmp($trader_version, "v1.3") >= 0 {
     file { $cf_bot_app_conf_hourly:
       owner   => $user,
index cf73a27054eff9939efdd3c84d32f8890c4d5832..5f7c09739d3989635362db3fc674065acd19d47c 100644 (file)
@@ -187,4 +187,16 @@ class role::cryptoportfolio::front inherits role::cryptoportfolio {
     }
   }
 
+  @profile::monitoring::external_service { "Cryptoportfolio website is running on $web_host":
+    type   => "web",
+    master => {
+      check_command => "check_https!$web_host!/!<title>Cryptoportfolio"
+    }
+  }
+  @profile::monitoring::external_service { "$web_host ssl certificate is up to date":
+    type   => "web",
+    master => {
+      check_command => "check_https_certificate!$web_host"
+    }
+  }
 }
index 74bb2945e2d19242a7bb5c39859d300c2610f6aa..379802e6d7df97222779d1b1fab76935e91da598 100644 (file)
--- a/readme.md
+++ b/readme.md
@@ -24,7 +24,7 @@ reusable component. (The structure is inspired from the tutorial at
   - modules/profile/manifests/postgresql/backup\_pgbouncer.pp (check pgbouncer works)
   - modules/profile/manifests/mail.pp (check e-mails are going through)
   - modules/profile/manifests/redis.pp (check redis is running)
-  - modules/role/manifests/cryptoportfolio (role-specific checks)
+    - LASTSAVE
 - Add redis replication and dumps
 - Restore backups for cryptoportfolio
 - Ensure latest by default for packages