#!/usr/bin/bash # (Solaris) #--!/bin/bash # (Linux) # (Use the applicable line) # # A Nagios plugin to check Oracle StorageTek ACSLS status. # Tested with SL8500 libraries, but possibly also works on other SL libraries as long as ACSLS is used. # Tested on Solaris 11 x86 / ACSLS 8.5.0 and Solaris 10 x86 / ACSLS 8.3.0 # but should work on Linux and ACSLS 8.0 and higher. # # by Tristan Zondag # tzondag@beeldengeluid.nl # # version 1.0 2019-06-07 # version 1.1 2019-10-31 # - fixed typo in portcheck() function # me="$(basename $0)" usage () { cat < A Nagios plugin to check Oracle StorageTek ACSLS status. Options: --lsm, -l Checks for any LSMs in offline (critical) or recovery (warning) state --ports, -p Checks for offline ports (one warning two critical) --services, -s Checks if ACSDB and ACSLS services are running --watchvols, -w Checks if watch_vols is running --help, -h Print this help text. EOF } ## exit statuses recognized by Nagios OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3 TMPFILE=/tmp/$$check_acsls.tmp ACSLSENV=/var/tmp/acsls/.acsls_env # source acsss environment variables if [ -e $ACSLSENV ]; then . $ACSLSENV else echo "Could not source $ACSLSENV!" exit $UNKNOWN fi ## helper functions die () { rc="$1" txt="$2" shift echo "$me: ERROR: $txt"; exit $rc } warn () { (echo -n "$me: WARNING: "; if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2 } have_command () { type "$1" >/dev/null 2>/dev/null } require_command () { if ! have_command "$1"; then die 1 "Could not find required command '$1' in system PATH. Aborting." fi } is_absolute_path () { expr match "$1" '/' >/dev/null 2>/dev/null } servicecheck () { STATUS=$OK require_command acsss ACSDBSTAT=$(acsss status | grep acsdb | awk '{print $2}') if [ $? -ne 0 ] then echo "acsss command failed!" die $UNKNOWN fi ACSLSSTAT=$(acsss status | grep acsls | awk '{print $2}') if [ $? -ne 0 ] then echo "acsss command failed!" die $UNKNOWN fi if [ $ACSDBSTAT != 'online' ] then STATUS=$CRITICAL MESSAGE="ACSDB not running!" fi if [ $ACSLSSTAT != 'online' ] then STATUS=$CRITICAL MESSAGE="${message} ACSLS not running!" fi if [ $STATUS -eq $OK ] then MESSAGE="ACSLS services online." fi } exitwithstatus () { # RETURN OUTPUT TO NAGIOS if [ $STATUS -eq $OK ] then echo "OK - ${MESSAGE}" exit $OK else echo "NOK - ${MESSAGE}" exit $STATUS fi } querycmdproc () { require_command cmd_proc echo $1 | cmd_proc -lq > $TMPFILE 2>&1 if [ $? -ne 0 ] then echo "cmd_proc command failed!" exit $UNKNOWN fi } lsmcheck () { querycmdproc "query lsm all" ONLINE=$(grep online $TMPFILE | wc -l | tr -s " ") OFFLINE=$(grep offline $TMPFILE | wc -l | tr -s " ") RECOVERY=$(grep recovery $TMPFILE | wc -l | tr -s " ") DIAGNOSTIC=$(grep diagnostic $TMPFILE | wc -l | tr -s " ") STATUS=$OK MESSAGE="${ONLINE} LSM(s) are online." if [ $RECOVERY -ne 0 ]; then STATUS=$WARNING MESSAGE="${RECOVERY} LSM(s) are in recovery mode!" fi if [ $DIAGNOSTIC -ne 0 ]; then STATUS=$WARNING MESSAGE="$DIAGNOSTIC LSM(s) are in diagnostic mode!" fi if [ $OFFLINE -ne 0 ]; then STATUS=$CRITICAL MESSAGE="${MESSAGE} ${OFFLINE} LSM(s) are offline!" fi rm -f $TMPFILE } portcheck () { querycmdproc "query port all" ONLINE=$(grep online $TMPFILE | wc -l | tr -s " ") OFFLINE=$(grep offline $TMPFILE | wc -l | tr -s " ") AMOUNTPORTS=$(grep 0\, $TMPFILE | wc -l | tr -s " ") STATUS=$OK MESSAGE="$ONLINE Port(s) are online." if [ $OFFLINE -gt 0 ]; then STATUS=$WARNING MESSAGE="${OFFLINE} port is offline!" fi if [ $OFFLINE -eq $AMOUNTPORTS ]; then STATUS=$CRITICAL MESSAGE="All $AMOUNTPORTS ports are offline!" fi rm -f $TMPFILE } watchvolscheck () { WATCHVOLS=$(watch_vols) STATUS=$OK MESSAGE=$WATCHVOLS if [ $(echo $WATCHVOLS | grep off | wc -l) -eq 1 ]; then STATUS=$WARNING MESSAGE=$WATCHVOLS fi } ## parse command-line # allowed options short_opts='lspwh' long_opts='lsm,services,ports,watchvols,help' if [ $# -eq 0 ] then usage; exit 0 fi # test which `getopt` version is available: # - GNU `getopt` will generate no output and exit with status 4 # - POSIX `getopt` will output `--` and exit with status 0 getopt -T > /dev/null rc=$? if [ "$rc" -eq 4 ]; then # GNU getopt args=$(getopt --name "$me" --shell sh -l "$long_opts" -o "$short_opts" -- "$@") if [ $? -ne 0 ]; then die 1 "Type '$me --help' to get usage information." fi # use 'eval' to remove getopt quoting eval set -- $args else # old-style getopt, use compatibility syntax args=$(getopt "$short_opts" "$@") if [ $? -ne 0 ]; then die 1 "Type '$me --help' to get usage information." fi set -- $args fi while [ $# -gt 0 ]; do case "$1" in --lsm|-l) lsmcheck;; --services|-s) servicecheck;; --ports|-p) portcheck;; --watchvols|-w) watchvolscheck;; --help|-h) usage; exit 0 ;; --) shift; break ;; esac shift done exitwithstatus