]>
Commit | Line | Data |
---|---|---|
e64a4968 IB |
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 |