From 96f8d0f037f8b8e93315e864bdaf661f45e3c472 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 12 Jul 2018 08:21:21 +0200 Subject: [PATCH] Add monitoring for cryptoportfolio --- modules/profile/files/monitoring/check_date | 32 +++++++++++++++++++ .../files/monitoring/check_last_file_date | 4 +-- .../profile/manifests/monitoring/commands.pp | 6 +++- modules/role/manifests/cryptoportfolio/bot.pp | 18 +++++++++++ .../role/manifests/cryptoportfolio/front.pp | 12 +++++++ readme.md | 2 +- 6 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 modules/profile/files/monitoring/check_date 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 @@ +#!/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 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 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 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 { "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) { 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 { ], } + 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, 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 { } } + @profile::monitoring::external_service { "Cryptoportfolio website is running on $web_host": + type => "web", + master => { + check_command => "check_https!$web_host!/!Cryptoportfolio" + } + } + @profile::monitoring::external_service { "$web_host ssl certificate is up to date": + type => "web", + master => { + check_command => "check_https_certificate!$web_host" + } + } } 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 - 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 -- 2.41.0