All pastes #1606560 Raw Edit

check_nbu_pool

public shellscript v1 · immutable
#1606560 ·published 2009-10-09 08:47 UTC
rendered paste body
#!/bin/bash# Based on a script from "Jurry"# -> http://jurrys.blogspot.com/2008/09/nagios-plug-in-for-netbackup-scartch.html# Changes by Alexander Skwar <alexander@skwar.name>:# 2009-10-09:# - Allow the user to specify the name of the pool which is to be checked# - Allow the user to specify if *ALL* tapes in the pool are to be#   counted (default), only the *ONLINE* tapes or the tapes which aren't#   assigned to a slto (offline)#   For this, use $ARG4$ and set it to "all", "online" or "offline". If #   not set, "all" is assumed.function usage(){    echo "Usage: $0 WARN_COUNT CRIT_COUNT POOL_NAME [COUNT_TYPE]"    echo ""    echo "Counts how many tapes are in a Veritas/Symantec NetBackup pool"    echo "To be used as a Nagios/Icinga Plug-In"    echo "See http://esisteinfehleraufgetreten.wordpress.com/2009/10/09/nagios-icinga-veritas-netbackup-volume-pool-check-plug-in"    echo "Or: http://wp.me/pA8p6-3a"    echo ""    echo " - WARN_COUNT: Issue a WARNING, if there are LESS THEN this number of tapes in the pool"    echo " - CRIT_COUNT: Issue a CRITICAL, if there are LESS THEN this number of tapes in the pool"    echo " - POOL_NAME: Name of the pool which should be checked"    echo " - COUNT_TYPE: Optional. Count which kind of tapes. Possible values:"    echo "     ALL: Count ALL tapes in this pool"    echo "     ONLINE: Count ONLINE tapes. Ie. those tapes, which have been inserted into the library"    echo "     OFFLINE: Count OFFLINE tapes. Ie. tapes NOT in the library"    echo "     If 4. parameter isn't set, ALL is assumed"    echo ""    echo "Example:"    echo "$0 3 2 Scratch"    echo "-> Issue a warning, if there are less then 3 (ie. 0, 1 or 2) tapes in the Scratch"    echo "   pool. Critical, if there are less then 2 (0 or 1) tapes."    exit 4}# Verify that the parameters are okayif [[ $# -lt 3 ]]; then    usageelif [[ $# -gt 4 ]]; then    usageelif [[ $# -eq 3 ]]; then    # Only 3 parameters given - set COUNT_TYPE to default value    COUNT_TYPE="ALL"elif [[ $# -eq 4 ]]; then    COUNT_TYPE="$4"fi# Store parameters in variablesWARN_COUNT="$1"CRIT_COUNT="$2"POOL_NAME="$3"# Get a listing of the tapes in the poolTAPES_IN_POOL_COMPLETE="$( /usr/openv/volmgr/bin/vmquery -b -pn "$POOL_NAME" | sed '1,3d' )"# Which tapes are to be counted (online, offline, all)?case "$COUNT_TYPE" in    ALL|all)      # Count ALL tapes      TAPES_IN_POOL_COUNT_ALL="$( echo "$TAPES_IN_POOL_COMPLETE" | wc -l | sed 's,^ *,,' )"      TAPES_COUNT="$TAPES_IN_POOL_COUNT_ALL"      ;;    ONLINE|online)      # Only those, which are "online"      TAPES_IN_POOL_COUNT_ONLINE="$( echo "$TAPES_IN_POOL_COMPLETE" | grep -v '^.* .* NONE .*$' | wc -l | sed 's,^ *,,' )"      TAPES_COUNT="$TAPES_IN_POOL_COUNT_ONLINE"      ;;    OFFLINE|offline)      # Only those, which are "offline"      TAPES_IN_POOL_COUNT_OFFLINE="$( echo "$TAPES_IN_POOL_COMPLETE" | grep '^.* .* NONE .*$' | wc -l | sed 's,^ *,,' )"      TAPES_COUNT="$TAPES_IN_POOL_COUNT_OFFLINE"      ;;    *)      echo "CRITICAL : wrong parameter $4 specified!"      usage      ;;esacif [[ $TAPES_COUNT -lt $WARN_COUNT ]]; then    if [[ $TAPES_COUNT -lt $CRIT_COUNT ]]; then        echo "$POOL_NAME $COUNT_TYPE count CRITICAL : availbale tapes $TAPES_COUNT less then $CRIT_COUNT|$POOL_NAME=$TAPES_COUNT;$WARN_COUNT;$CRIT_COUNT"        exit 2    else        echo "$POOL_NAME $COUNT_TYPE count WARNING : available tapes $TAPES_COUNT less then $WARN_COUNT|$POOL_NAME=$TAPES_COUNT;$WARN_COUNT;$CRIT_COUNT"        exit 1    fielse    echo "$POOL_NAME $COUNT_TYPE count OK : available tapes $TAPES_COUNT|scratch=$TAPES_COUNT;$WARN_COUNT;$CRIT_COUNT"    exit 0fiexit 3# EOF #