#!/bin/sh # Little check for device errors on Btrfs volumes # # GPL v3+ (copyright chl-dev@bugness.org) PROGPATH=$( echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,' ) REVISION="0.1" # Stop at the first non-catched error set -e # Include check_range() # Not needed at the moment #. $PROGPATH/utils.sh STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 # Default values WARNING_STATS=0 CRITICAL_STATS=0 # Output OUTPUT_EXIT_STATUS=$STATE_OK OUTPUT_DETAIL_OK="" OUTPUT_DETAIL_WARNING="" OUTPUT_DETAIL_CRITICAL="" OUTPUT_PERFDATA="" NB_DEVICES=0 # # Help function # usage() { cat </dev/null 2>&1 # if [ "$?" -eq "2" ]; then # return 1 # Some early checks if ! which btrfs 2>&1 >/dev/null; then echo "UNKNOWN 'btrfs' command not found." exit $STATE_UNKNOWN fi # # Loop on parameters + tests # while getopts hw:c:V: f; do case "$f" in 'h') usage exit ;; 'V') VOLUME="$OPTARG" # Quickly check if we have enough permission to launch btrfs commands if ! btrfs device stats "$VOLUME" >/dev/null 2>&1 ; then echo "UNKNOWN: unable to launch 'btrfs device stats $VOLUME' command (permissions ?)." exit $STATE_UNKNOWN fi # For information, add the number of devices to the perfdata NB_DEVICES="$(( $NB_DEVICES + $( btrfs fi show --raw "$VOLUME" | sed -n 's/^[[:space:]]*Total devices \([0-9]\+\) .*/\1/p' ) ))" # Check the device stats # (the kinda weird <