diff options
author | Stonewall Jackson <stonewall@sacredheartsc.com> | 2023-02-04 01:23:43 -0500 |
---|---|---|
committer | Stonewall Jackson <stonewall@sacredheartsc.com> | 2023-02-04 01:52:13 -0500 |
commit | 0261e875679f1bf63c8d689da7fc7e014597885d (patch) | |
tree | 3f19cd74a0c1070944f75437f30b098d6ef2ffcb /roles/nagios_client/files/usr/lib64/nagios/plugins/check_zpools | |
download | selfhosted-0261e875679f1bf63c8d689da7fc7e014597885d.tar.gz selfhosted-0261e875679f1bf63c8d689da7fc7e014597885d.zip |
initial commit
Diffstat (limited to 'roles/nagios_client/files/usr/lib64/nagios/plugins/check_zpools')
-rw-r--r-- | roles/nagios_client/files/usr/lib64/nagios/plugins/check_zpools | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/roles/nagios_client/files/usr/lib64/nagios/plugins/check_zpools b/roles/nagios_client/files/usr/lib64/nagios/plugins/check_zpools new file mode 100644 index 0000000..30e11e5 --- /dev/null +++ b/roles/nagios_client/files/usr/lib64/nagios/plugins/check_zpools @@ -0,0 +1,74 @@ +#!/bin/bash + +set -Eeu -o pipefail +shopt -s lastpipe + +trap 'exit 3' ERR + +usage() { + echo 'usage: check_zpool -w WARN_THRESHOLD -c CRIT_THRESHOLD' 1>&2 + exit 3 +} + +while getopts ':w:c:' opt; do + case $opt in + w) WARN_THRESHOLD=${OPTARG//%/} ;; + c) CRIT_THRESHOLD=${OPTARG//%/} ;; + *) usage ;; + esac +done +shift $((OPTIND-1)) + +if [ -z "${WARN_THRESHOLD:-}" -o -z "${CRIT_THRESHOLD:-}" ]; then + usage +fi + +if (( WARN_THRESHOLD < CRIT_THRESHOLD )); then + echo 'WARN must be greater than CRIT' 1>&2 + exit 3 +fi + +CRIT=() +WARN=() +OK=() + +zpool list -Ho name,free,capacity,health | while read -r name free capacity health; do + capacity=${capacity//%/} + percent_free=$(( 100 - capacity )) + output="${name} $health: $free free (${percent_free}%)" + + if [ "$health" != ONLINE ]; then + output="$output"$'\n'"$(zpool status "$name")" + fi + + if (( percent_free < CRIT_THRESHOLD )) || [ "$health" != ONLINE ]; then + CRIT+=("$output") + elif (( percent_free < WARN_THRESHOLD )); then + WARN+=("$output") + else + OK+=("$output") + fi +done + +if [ -z "${CRIT[*]}${WARN[*]}${OK[*]}" ]; then + echo 'OK - no zpools present' + exit 0 +fi + +rc=0 + +for line in "${CRIT[@]}"; do + echo "CRIT - ${line}" + rc=3 +done + +for line in "${WARN[@]}"; do + echo "WARN - ${line}" + (( rc )) || rc=2 +done + +for line in "${OK[@]}"; do + echo "OK - ${line}" +done + +exit $rc |