diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-12 08:21:21 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-12 08:51:02 +0200 |
commit | 96f8d0f037f8b8e93315e864bdaf661f45e3c472 (patch) | |
tree | 96b09b188872a5d48385da467ea4a5990aeb90b0 /modules/profile/files/monitoring/check_date | |
parent | 21d531ee2e4a5952673d694342ff01822581a1f8 (diff) | |
download | Puppet-96f8d0f037f8b8e93315e864bdaf661f45e3c472.tar.gz Puppet-96f8d0f037f8b8e93315e864bdaf661f45e3c472.tar.zst Puppet-96f8d0f037f8b8e93315e864bdaf661f45e3c472.zip |
Add monitoring for cryptoportfolio
Diffstat (limited to 'modules/profile/files/monitoring/check_date')
-rw-r--r-- | modules/profile/files/monitoring/check_date | 32 |
1 files changed, 32 insertions, 0 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 | |||
3 | STATE_OK=0 | ||
4 | STATE_WARNING=1 | ||
5 | STATE_CRITICAL=2 | ||
6 | STATE_UNKNOWN=3 | ||
7 | |||
8 | run_command="$1" | ||
9 | hours="$2" | ||
10 | as_user="$3" | ||
11 | |||
12 | if [ -z "$as_user" ]; then | ||
13 | last_date=$($run_command 2>/dev/null | sort | tail -n 1) | ||
14 | else | ||
15 | last_date=$(sudo -u "$as_user" $run_command 2>/dev/null | sort | tail -n 1) | ||
16 | fi | ||
17 | |||
18 | if [ -z "$last_date" ]; then | ||
19 | echo "UNKNOWN: Could not read date" | ||
20 | exit $STATE_UNKNOWN | ||
21 | else | ||
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 | ||
32 | fi | ||