diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-05-02 15:14:43 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2021-05-02 15:14:43 +0200 |
commit | e64a496820b90607cba3762db3ce77847aaac22d (patch) | |
tree | c7cb1c0e536ff75e3b523de7759c13e7b7a8a381 /modules/private/monitoring/plugins | |
parent | acab8301f6a0a76d97b36d009a60d4172bf62981 (diff) | |
download | Nix-e64a496820b90607cba3762db3ce77847aaac22d.tar.gz Nix-e64a496820b90607cba3762db3ce77847aaac22d.tar.zst Nix-e64a496820b90607cba3762db3ce77847aaac22d.zip |
Add monitoring for quatresaisons
Diffstat (limited to 'modules/private/monitoring/plugins')
-rwxr-xr-x | modules/private/monitoring/plugins/check_postgres_database_count | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/private/monitoring/plugins/check_postgres_database_count b/modules/private/monitoring/plugins/check_postgres_database_count new file mode 100755 index 0000000..43bdd8c --- /dev/null +++ b/modules/private/monitoring/plugins/check_postgres_database_count | |||
@@ -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 | host=$1 | ||
9 | port=$2 | ||
10 | min=$3 | ||
11 | |||
12 | count=$(psql -h $host -p $port -A -q -c '\t' -c 'select count(datname) from pg_catalog.pg_database' postgres 2>&1) | ||
13 | exit_code=$? | ||
14 | |||
15 | if [[ $exit_code -ne 0 ]]; then | ||
16 | echo "UNKNOWN - Impossible to run psql command: $count" | ||
17 | exit $STATE_UNKNOWN | ||
18 | elif [[ -z "$count" ]]; then | ||
19 | echo "UNKNOWN - No database found" | ||
20 | exit $STATE_UNKNOWN | ||
21 | else | ||
22 | output="Database count is $count" | ||
23 | LC_ALL=C count=$(printf "%.*f" 0 $count) | ||
24 | |||
25 | if [[ $count -gt $min ]]; then | ||
26 | echo "OK - $output | count=${count};$min;$min;0;" | ||
27 | exit $STATE_OK | ||
28 | else | ||
29 | echo "CRITICAL - $output | count=${count};$min;$min;0;" | ||
30 | exit $STATE_CRITICAL | ||
31 | fi | ||
32 | fi | ||