Nagios/Icinga: Veritas NetBackup Volume Pool Check Plug-In

To monitor the number of available tapes in a „Volume Pool“ of our Symantec/Veritas NetBackup installation, I was looking for a „Plug-In“ for Nagios/Icinga. And on „Jurry’s Blog„, I found a sample script, which I „enhanced“ a bit.

Here’s the script:

Nagios/Icinga Plug-In „check_nbu_pool“

#!/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 :
# 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.
#
# See http://wp.me/pA8p6-3a for a blog post and
# http://pastebin.ca/1606656 for pastebin, where you can download the script.
#
# Requirements:
# Veritas/Symantec NetBackup must be installed.
# User running the script (ie. usually Nagios) must be allowed to run
# vmquery from NetBackup with Super User rights using SUDO.
# Add something like this to sudoers configuration file using visudo:
# nagios  ALL = NOPASSWD : /usr/openv/volmgr/bin/vmquery *

# Where is Veritas/Symantec NetBackup installed?
vmquery="/usr/openv/volmgr/bin/vmquery"
# Where is sudo?
sudo="/opt/csw/bin/sudo"
# What user should sudo run the vmquery command as?
sudo_user="root"

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 https://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 "The script requires sudo access, so that it can run vmquery from"
    echo "NetBackup with superuser rights."
    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 okay
if [[ $# -lt 3 ]]; then
    usage
elif [[ $# -gt 4 ]]; then
    usage
elif [[ $# -eq 3 ]]; then
    # Only 3 parameters given - set COUNT_TYPE to default value
    COUNT_TYPE="ALL"
elif [[ $# -eq 4 ]]; then
    COUNT_TYPE="$4"
fi

# Are the programs accessible?
if [[ ! -x "$sudo" ]]; then
    echo "Error! $sudo isn't executable for us!"
    ls -la "$sudo"
    usage
elif ! "$sudo" -u "$sudo_user" test -x "$vmquery"; then
    echo "Error! $vmquery isn't executable for sudo user $sudo_user with sudo!"
    ls -al "$vmquery"
    usage
fi

# Store parameters in variables
WARN_COUNT="$1"
CRIT_COUNT="$2"
POOL_NAME="$3"

# Get a listing of the tapes in the pool
TAPES_IN_POOL_COMPLETE="$( "$sudo" -u "$sudo_user" "$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
      ;;
esac

if [[ $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
    fi
else
    echo "$POOL_NAME $COUNT_TYPE count OK : available tapes $TAPES_COUNT|scratch=$TAPES_COUNT;$WARN_COUNT;$CRIT_COUNT"
    exit 0
fi
exit 3

# EOF #

What does it do?

Given a „POOL_NAME“ (3rd parameter), it issues a WARNING (or CRITICAL) if there are less then the number of tapes specified (WARNING → 1st parameter; CRITICAL → 2nd parameter). Optionally, it allows the user to say what kind of tapes he’s interested in (4th parmeter). Ie., „ALL“ tapes, or only the ones which are „ONLINE“ (ie. inserted into the library) or those, which are „OFFLINE“ (ie. not inserted into the library).

Nagios/Icinga integration

To integrate it into Nagios, copy it to the directory where all the other plug-ins are. Having done that, add the following statements to your Nagios configuration:

# commands.cfg:
define command {
       command_name                  		check_local_nbu_pool
       command_line                  		$USER1$/addons/check_nbu_pool $ARG1$ $ARG2$ $ARG3$ $ARG4$
}	

define command {
       command_name                  		check_remote_nbu_pool
       command_line                  		$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_nbu_pool -a $ARG1$ $ARG2$ $ARG3$ $ARG4$
}	

# services.cfg:
define service {
	service_description		Check NBU Pool
	use				generic-service
	check_command			check_local_nbu_pool!3!2!Scratch!ONLINE
	register			1
	}	


define service {
	host_name			winds06
	service_description		Check Remote NBU Pool
	use				generic-service
	check_command			check_remote_nbu_pool!3!2!Scratch!ONLINE
	register			1
	}	

NRPE

To be able to run it on a remote host, NRPE is to be installed. Configuration:

# /etc/nrpe.cfg:
command[check_nbu_pool]=/opt/csw/libexec/nagios-plugins/addons/check_nbu_pool $ARG1$ $ARG2$ $ARG3$ $ARG4$

Done

Yep, that’s it already – it really is THAT easy😉

2 thoughts on “Nagios/Icinga: Veritas NetBackup Volume Pool Check Plug-In

Schreibe einen Kommentar

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s