From 96f8d0f037f8b8e93315e864bdaf661f45e3c472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Thu, 12 Jul 2018 08:21:21 +0200 Subject: Add monitoring for cryptoportfolio --- modules/profile/files/monitoring/check_date | 32 ++++++++++++++++++++++ .../profile/files/monitoring/check_last_file_date | 4 +-- modules/profile/manifests/monitoring/commands.pp | 6 +++- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 modules/profile/files/monitoring/check_date (limited to 'modules/profile') 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) { -- cgit v1.2.3