aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-07-12 08:51:22 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-07-12 08:51:22 +0200
commitde68b72374231be37df7c171596672a21a218958 (patch)
tree96b09b188872a5d48385da467ea4a5990aeb90b0
parent21d531ee2e4a5952673d694342ff01822581a1f8 (diff)
parent96f8d0f037f8b8e93315e864bdaf661f45e3c472 (diff)
downloadPuppet-de68b72374231be37df7c171596672a21a218958.tar.gz
Puppet-de68b72374231be37df7c171596672a21a218958.tar.zst
Puppet-de68b72374231be37df7c171596672a21a218958.zip
Merge branch 'monitoring' into dev
-rw-r--r--modules/profile/files/monitoring/check_date32
-rw-r--r--modules/profile/files/monitoring/check_last_file_date4
-rw-r--r--modules/profile/manifests/monitoring/commands.pp6
-rw-r--r--modules/role/manifests/cryptoportfolio/bot.pp18
-rw-r--r--modules/role/manifests/cryptoportfolio/front.pp12
-rw-r--r--readme.md2
6 files changed, 70 insertions, 4 deletions
diff --git a/modules/profile/files/monitoring/check_date b/modules/profile/files/monitoring/check_date
new file mode 100644
index 0000000..e7ac38a
--- /dev/null
+++ b/modules/profile/files/monitoring/check_date
@@ -0,0 +1,32 @@
1#!/bin/bash
2
3STATE_OK=0
4STATE_WARNING=1
5STATE_CRITICAL=2
6STATE_UNKNOWN=3
7
8run_command="$1"
9hours="$2"
10as_user="$3"
11
12if [ -z "$as_user" ]; then
13 last_date=$($run_command 2>/dev/null | sort | tail -n 1)
14else
15 last_date=$(sudo -u "$as_user" $run_command 2>/dev/null | sort | tail -n 1)
16fi
17
18if [ -z "$last_date" ]; then
19 echo "UNKNOWN: Could not read date"
20 exit $STATE_UNKNOWN
21else
22 last_date=$(date -d "$last_date" "+%s")
23 LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
24 min_date=$(date -d "$hours hours ago" "+%s")
25 if [ "$min_date" -lt "$last_date" ]; then
26 echo "OK: Last date $(date -d @$last_date)"
27 exit $STATE_OK
28 else
29 echo "CRITICAL: Last date $(date -d @$last_date)"
30 exit $STATE_CRITICAL
31 fi
32fi
diff --git a/modules/profile/files/monitoring/check_last_file_date b/modules/profile/files/monitoring/check_last_file_date
index 8eabb57..d520a84 100644
--- a/modules/profile/files/monitoring/check_last_file_date
+++ b/modules/profile/files/monitoring/check_last_file_date
@@ -22,10 +22,10 @@ else
22 LC_ALL=C last_date=$(printf "%.*f" 0 $last_date) 22 LC_ALL=C last_date=$(printf "%.*f" 0 $last_date)
23 min_date=$(date -d "$hours hours ago" "+%s") 23 min_date=$(date -d "$hours hours ago" "+%s")
24 if [ "$min_date" -lt "$last_date" ]; then 24 if [ "$min_date" -lt "$last_date" ]; then
25 echo "OK: Last backup $(date -d @$last_date)" 25 echo "OK: Last file $(date -d @$last_date)"
26 exit $STATE_OK 26 exit $STATE_OK
27 else 27 else
28 echo "CRITICAL: Last backup $(date -d @$last_date)" 28 echo "CRITICAL: Last file $(date -d @$last_date)"
29 exit $STATE_CRITICAL 29 exit $STATE_CRITICAL
30 fi 30 fi
31fi 31fi
diff --git a/modules/profile/manifests/monitoring/commands.pp b/modules/profile/manifests/monitoring/commands.pp
index 1c8d0b4..7c5d8ed 100644
--- a/modules/profile/manifests/monitoring/commands.pp
+++ b/modules/profile/manifests/monitoring/commands.pp
@@ -12,6 +12,7 @@ class profile::monitoring::commands inherits profile::monitoring {
12 "check_command", 12 "check_command",
13 "check_md_raid", 13 "check_md_raid",
14 "check_postgres_replication", 14 "check_postgres_replication",
15 "check_date",
15 "check_last_file_date", 16 "check_last_file_date",
16 ].each |$file| { 17 ].each |$file| {
17 file { "$plugins/$file": 18 file { "$plugins/$file":
@@ -57,7 +58,10 @@ class profile::monitoring::commands inherits profile::monitoring {
57 require => File["$plugins/check_postgres_replication"]; 58 require => File["$plugins/check_postgres_replication"];
58 "check_last_file_date": 59 "check_last_file_date":
59 command_line => '$USER2$/check_last_file_date "$ARG1$" "$ARG2$" "$ARG3$"', 60 command_line => '$USER2$/check_last_file_date "$ARG1$" "$ARG2$" "$ARG3$"',
60 require => File["$plugins/check_last_file_date"], 61 require => File["$plugins/check_last_file_date"];
62 "check_date":
63 command_line => '$USER2$/check_date "$ARG1$" "$ARG2$" "$ARG3$"',
64 require => File["$plugins/check_date"];
61 } 65 }
62 66
63 unless empty($naemon_url) { 67 unless empty($naemon_url) {
diff --git a/modules/role/manifests/cryptoportfolio/bot.pp b/modules/role/manifests/cryptoportfolio/bot.pp
index 2f01c98..fd3ece3 100644
--- a/modules/role/manifests/cryptoportfolio/bot.pp
+++ b/modules/role/manifests/cryptoportfolio/bot.pp
@@ -81,6 +81,24 @@ class role::cryptoportfolio::bot inherits role::cryptoportfolio {
81 ], 81 ],
82 } 82 }
83 83
84 if ($environment == "production") {
85 $monitored_key = 3
86 @profile::monitoring::local_service { "Last redis report is less than 2 hours old":
87 local => {
88 check_command => "check_date!redis-cli -s $redis_host GET /cryptoportfolio/$monitored_key/latest/date!2"
89 }
90 }
91
92 @profile::monitoring::local_service { "Last bot report is less than one week old":
93 sudos => {
94 "naemon-cryptoportfolio-bot" => "naemon ALL=($user) NOPASSWD: /usr/bin/find $cf_bot_app_reports -mindepth 1 -maxdepth 1 -printf %T@?n",
95 },
96 local => {
97 check_command => "check_last_file_date!$cf_bot_app_reports!168!$user",
98 },
99 }
100 }
101
84 if versioncmp($trader_version, "v1.3") >= 0 { 102 if versioncmp($trader_version, "v1.3") >= 0 {
85 file { $cf_bot_app_conf_hourly: 103 file { $cf_bot_app_conf_hourly:
86 owner => $user, 104 owner => $user,
diff --git a/modules/role/manifests/cryptoportfolio/front.pp b/modules/role/manifests/cryptoportfolio/front.pp
index cf73a27..5f7c097 100644
--- a/modules/role/manifests/cryptoportfolio/front.pp
+++ b/modules/role/manifests/cryptoportfolio/front.pp
@@ -187,4 +187,16 @@ class role::cryptoportfolio::front inherits role::cryptoportfolio {
187 } 187 }
188 } 188 }
189 189
190 @profile::monitoring::external_service { "Cryptoportfolio website is running on $web_host":
191 type => "web",
192 master => {
193 check_command => "check_https!$web_host!/!<title>Cryptoportfolio"
194 }
195 }
196 @profile::monitoring::external_service { "$web_host ssl certificate is up to date":
197 type => "web",
198 master => {
199 check_command => "check_https_certificate!$web_host"
200 }
201 }
190} 202}
diff --git a/readme.md b/readme.md
index 74bb294..379802e 100644
--- a/readme.md
+++ b/readme.md
@@ -24,7 +24,7 @@ reusable component. (The structure is inspired from the tutorial at
24 - modules/profile/manifests/postgresql/backup\_pgbouncer.pp (check pgbouncer works) 24 - modules/profile/manifests/postgresql/backup\_pgbouncer.pp (check pgbouncer works)
25 - modules/profile/manifests/mail.pp (check e-mails are going through) 25 - modules/profile/manifests/mail.pp (check e-mails are going through)
26 - modules/profile/manifests/redis.pp (check redis is running) 26 - modules/profile/manifests/redis.pp (check redis is running)
27 - modules/role/manifests/cryptoportfolio (role-specific checks) 27 - LASTSAVE
28- Add redis replication and dumps 28- Add redis replication and dumps
29- Restore backups for cryptoportfolio 29- Restore backups for cryptoportfolio
30- Ensure latest by default for packages 30- Ensure latest by default for packages