Commit 3a244ae1b86c448fbb4e28850aa2c4c5bac7dd4e

Authored by Imanol-Mikel Barba Sabariego
1 parent 55296ee6

Adding btrfs check plugin

Showing 1 changed file with 81 additions and 0 deletions
check_btrfs/check_btrfs.sh 0 → 100755
  1 +#!/bin/bash
  2 +
  3 +function smart_disks() {
  4 + if [[ $# != 1 ]]; then
  5 + echo "Wrong number of arguments"
  6 + return 3
  7 + fi
  8 +
  9 + POOL=$1
  10 + DISKS=$(btrfs device stats / | grep -oP "^\[[^\]]+\]" | sed 's/[][]//g' | sort -u)
  11 + ERR_OUTPUT=""
  12 + HIGHEST_RES=0
  13 + for disk in $DISKS; do
  14 + OUTPUT=""
  15 + RES=0
  16 + if echo $disk | grep "nvme" > /dev/null; then
  17 + OUTPUT=$(/usr/lib64/nagios/plugins/check_nvme $disk)
  18 + RES=$?
  19 + else
  20 + OUTPUT=$(/usr/lib64/nagios/plugins/check_smart $disk)
  21 + RES=$?
  22 + fi
  23 + if [[ $RES != 0 ]]; then
  24 + ERR_OUTPUT="$ERR_OUTPUT - $OUTPUT"
  25 + fi
  26 + if [[ $RES -gt $HIGHEST_RES ]]; then
  27 + HIGHEST_RES=$RES
  28 + fi
  29 + done
  30 +
  31 + echo -n "BTRFS POOL SMART $POOL "
  32 + if [[ $HIGHEST_RES == 1 ]]; then
  33 + echo "WARNING${ERR_OUTPUT}"
  34 + return 1
  35 + elif [[ $HIGHEST_RES == 2 ]]; then
  36 + echo "CRITICAL${ERR_OUTPUT}"
  37 + return 2
  38 + elif [[ $HIGHEST_RES == 3 ]]; then
  39 + echo "UNKNOWN${ERR_OUTPUT}"
  40 + return 3
  41 + fi
  42 +
  43 + echo "OK"
  44 + return 0
  45 +}
  46 +
  47 +function pool_errors() {
  48 + if [[ $# != 1 ]]; then
  49 + echo "Wrong number of arguments"
  50 + return 3
  51 + fi
  52 +
  53 + OUTPUT="$(btrfs device stats -c $1)"
  54 + STATUS=$?
  55 +
  56 + if [[ $STATUS != 0 ]]; then
  57 + echo "BTRFS POOL ERRORS $1 - CRITICAL: $OUTPUT"
  58 + return 2
  59 + fi
  60 +
  61 + echo "BTRFS POOL ERRORS $1 - OK"
  62 + return 0
  63 +}
  64 +
  65 +if [[ $# -lt 2 ]]; then
  66 + echo "Wrong number of arguments"
  67 + exit 3
  68 +fi
  69 +
  70 +ACTION=$1
  71 +POOL=$2
  72 +
  73 +if [[ $ACTION == "smart" ]]; then
  74 + smart_disks $POOL
  75 + exit $?
  76 +elif [[ $ACTION == "errors" ]]; then
  77 + pool_errors $POOL
  78 + exit $?
  79 +fi
  80 +echo "Unknown command: $ACTION"
  81 +exit 3