#!/bin/bash # # Check the status of a Printronix P7000 / P7200 printer via its web GUI # # Expects the name or IP address of the printer with -p or -H # # 2014-05-21 0.1 TMP Initial edit # 2014-05-21 1.0 TMP Works. Adapted to also work as Nagios plug-in. # 2014-05-21 1.1 TMP Command line options # 2014-05-21 1.2 TMP Nagios-style output option # 2014-06-10 1.3 TMP Minor cleanup and released under GPL # # 2014 Thomas M. Peters / MCTS. Released under the GNU General Public License. # No warranty, express or implied. # You may redistribute copies of the plugins under the terms of the GNU General Public License. # # To use this as a Nagios plug-in, refer to the sample services.cfg entry below: # #define service { # service_description printronix # use generic-service # max_check_attempts 2 # host_name %HOSTS% # check_command check_printronix #} # # And this sample commands.cfg entry: # # define command{ # command_name check_printronix # command_line $USER1$/check_printronix -v -p $HOSTADDRESS$ # } # VER="1.3" ME=`basename $0` TMPFILE="/var/tmp/$$.tmp" PRTR="" WARNINGS="RIBBON UNDER Change RBN Soon Half Speed Mode OLD RIBBON Install New RBN POWER SUPPLY HOT PRINTER HOT RBN AT END POINT Change Ribbon" # Nagios stuff STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 NOW=`date +'%F %R'` usage() { echo "$ME $VER - Report status of Printronix P7000/P7200 series printers." echo " Checks the state of the INTERFACE (online or not) " echo " and the STATUS (idle, busy, etc)." echo "Usage:" echo " $ME [-v|-q][-n][t secs][-h] [-p printer|-H printer]" echo "" echo " -p printr You must specify printer with -p option, by name or IP" echo " -H printr Synonym for -p" echo " -v verbose: Add some additional fields (e.g. status & LCD display.)" echo " Note: If the status is WARNING or worse, the LCD contents " echo " is always shown." echo " If specified, turns off -q" echo " -V Very verbose; implies -v; turns off -q" echo " -l Log format; prints timestamp first." echo " -q Report nothing, exit with status code only." echo " Exits with 0 if online, 2 if not." echo " Exit code of 3 indicates parameter error." echo " -t secs Timeout between attempts in seconds. Makes 5 attempts." echo " -n Nagios-style messages (optional- If you want to use this as " echo " a Nagios plugin, -n is nice but optional)" echo " -h Show this help text and exit." exit $STATE_UNKNOWN } OPTV=0 OPTQ=0 OPTD=0 OPTN=0 OPTV=0 OPTT=0 OPTL=0 OPTVV=0 while getopts 'p:H:t:vVqhndl' opt do case "$opt" in h) usage ;; p) PRTR=${OPTARG} ;; H) PRTR=${OPTARG} ;; q) OPTQ=1 ;; v) OPTV=1;OPTQ=0 ;; V) OPTV=1;OPTVV=1;OPTQ=0 ;; l) OPTL=1 ;; d) OPTD=1 ;; n) OPTN=1 ;; t) OPTT=1;TOUT=${OPTARG} ;; esac done [ -z "$PRTR" ] && usage [ "$PRTR" == "" ] && usage if [ $OPTT -gt 0 ]; then TOUTSTR="-T${TOUT}" else TOUTSTR="-T20" fi WGCMD="wget --no-cache -q ${TOUTSTR} -t5 -O${TMPFILE} http://${PRTR}/ioPortStatus.html" [ $OPTD -gt 0 ] && echo "[TEMPFILE: ${TMPFILE}]" [ $OPTD -gt 0 ] && echo "[COMMAND: ${WGCMD}]" [ $OPTD -gt 0 ] && echo "[PRINTER: ${PRTR}]" WGETERR=0 # ===================================================================================== wget ${WGCMD} WGETERR=$? # ===================================================================================== [ $OPTD -gt 0 ] && echo "[WGETERR: ${WGETERR}]" # wget ALWAYS returns exit code of 4 (network error) in a script-- anyone know why?? #if [ $WGETERR -ne 0 ]; then # echo "Error: Could not get status from web interface--" # echo "Check that ${PRTR} is spelled correctly and reachable." # echo "You might have to specify a fully qualified name, or an IP." # # rm -f ${TMPFILE} # exit 1 #fi if [ -s "${TMPFILE}" ]; then # Grab the Interface status (online or offline) then isolate the status itself, # then de-HTML-ify it. ONLINE=`/bin/grep -i -A2 'label for="Status"' ${TMPFILE} |/bin/grep -i -A2 'Interface:'|/usr/bin/tail -n1|/bin/sed -e :a -e 's/<[^>]*>//g;/]*>//g;/