From 3a244ae1b86c448fbb4e28850aa2c4c5bac7dd4e Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Mon, 1 Apr 2024 14:37:13 +0200 Subject: [PATCH] Adding btrfs check plugin --- check_btrfs/check_btrfs.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+), 0 deletions(-) create mode 100755 check_btrfs/check_btrfs.sh diff --git a/check_btrfs/check_btrfs.sh b/check_btrfs/check_btrfs.sh new file mode 100755 index 0000000..3b3ec95 --- /dev/null +++ b/check_btrfs/check_btrfs.sh @@ -0,0 +1,81 @@ +#!/bin/bash + +function smart_disks() { + if [[ $# != 1 ]]; then + echo "Wrong number of arguments" + return 3 + fi + + POOL=$1 + DISKS=$(btrfs device stats / | grep -oP "^\[[^\]]+\]" | sed 's/[][]//g' | sort -u) + ERR_OUTPUT="" + HIGHEST_RES=0 + for disk in $DISKS; do + OUTPUT="" + RES=0 + if echo $disk | grep "nvme" > /dev/null; then + OUTPUT=$(/usr/lib64/nagios/plugins/check_nvme $disk) + RES=$? + else + OUTPUT=$(/usr/lib64/nagios/plugins/check_smart $disk) + RES=$? + fi + if [[ $RES != 0 ]]; then + ERR_OUTPUT="$ERR_OUTPUT - $OUTPUT" + fi + if [[ $RES -gt $HIGHEST_RES ]]; then + HIGHEST_RES=$RES + fi + done + + echo -n "BTRFS POOL SMART $POOL " + if [[ $HIGHEST_RES == 1 ]]; then + echo "WARNING${ERR_OUTPUT}" + return 1 + elif [[ $HIGHEST_RES == 2 ]]; then + echo "CRITICAL${ERR_OUTPUT}" + return 2 + elif [[ $HIGHEST_RES == 3 ]]; then + echo "UNKNOWN${ERR_OUTPUT}" + return 3 + fi + + echo "OK" + return 0 +} + +function pool_errors() { + if [[ $# != 1 ]]; then + echo "Wrong number of arguments" + return 3 + fi + + OUTPUT="$(btrfs device stats -c $1)" + STATUS=$? + + if [[ $STATUS != 0 ]]; then + echo "BTRFS POOL ERRORS $1 - CRITICAL: $OUTPUT" + return 2 + fi + + echo "BTRFS POOL ERRORS $1 - OK" + return 0 +} + +if [[ $# -lt 2 ]]; then + echo "Wrong number of arguments" + exit 3 +fi + +ACTION=$1 +POOL=$2 + +if [[ $ACTION == "smart" ]]; then + smart_disks $POOL + exit $? +elif [[ $ACTION == "errors" ]]; then + pool_errors $POOL + exit $? +fi +echo "Unknown command: $ACTION" +exit 3 -- libgit2 0.22.2