i've not done that (i dont think) so unless it happens without knowing......
i've not done that (i dont think) so unless it happens without knowing......

distro dependant.
Ubuntu 7.04
after a bit more research it seems that expr doesnt like the values that snmpget gets. It seems to think they are not "non-numeric arguments". The values seem to have a space after them. Is there a way to cast to a value? Or atleast trim the trailing space off the value?
Thanks

Yes, use the 'cut' command.
It's all sorted. For some reason re-typing the variable assignments and the expr statement fixed it. Not sure if it's because i'd downloaded it off the net and ended up with some hidden chars maybe? I did run tofrodos and that solved some other problems but not that one. Just in the process of upgrading the firmware on some of the older printers now as they dont give the toner levels out via snmp without it.
Also changed way the original calculated the usage as it gave the amount used rather than amount remaining. The adjusted script is below in case anybody wants to check their HP toner usage in nagios.
Last edited by Lee_K_81; 15th May 2008 at 09:47 AM.
Here's the modified script. Hope this helps somebody else.
usage (based on HP LaserJet 2600n retrieving black toner usage):
./check_hp_toners -H 10.122.1.10 -OC .1.3.6.1.2.1.43.11.1.1.9.1 -OM .1.3.6.1.2.1.43.11.1.1.8.1.1 -p 2500 -C public
where:
-H = host address
-OC = oid for current toner remaining
-OM = oid for maximum toner
-p = approx pages specified by manufacturer
-C = community string
LeeCode:#! /bin/bash # # Original Script # Nagios-Plugin zum überprüfen von Verbrauchsmaterialien in HP Druckern # Last Modified: 20-10-2006 # # Modified by Lee Kilcullen # Date: 14-05-2008 # Paths to commands used in this script. These # may have to be modified to match your system setup. PATH="/usr/local/nagios/" SNMPGET="/usr/bin/snmpget" EXPR="/usr/bin/expr" PROGNAME=`/usr/bin/basename $0` PROGPATH=`echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'` REVISION=`echo '$Revision: 1.4 $' | /bin/sed -e 's/[^0-9.]//g'` . $PROGPATH/utils.sh print_usage() { echo "Usage: $PROGNAME -H Host -OM OID-Max -OC OID-Cur -w Warn in % -c Critical in % -t Toner OID -C community string" echo "Usage: $PROGNAME --help" echo "Usage: $PROGNAME --version" } print_help() { print_revision $PROGNAME $REVISION echo "" print_usage echo "" echo "Überprüfe Verbrauchsmaterial von HP-Druckern" echo "" support } # Make sure the correct number of command line # arguments have been supplied if [ $# -lt 1 ]; then print_usage exit $STATE_UNKNOWN fi # Grab the command line arguments exitstatus=$STATE_WARNING #default while test -n "$1"; do case "$1" in --help) print_help exit $STATE_OK ;; -h) print_help exit $STATE_OK ;; --version) print_revision $PROGNAME $VERSION exit $STATE_OK ;; -V) print_revision $PROGNAME $VERSION exit $STATE_OK ;; --host) host=$2 shift ;; -H) host=$2 shift ;; --oidmax) oidmax=$2 shift ;; -OM) oidmax=$2 shift ;; --oidcur) oidcur=$2 shift ;; -OC) oidcur=$2 shift ;; --warn) warn=$2 shift ;; -w) warn=$2 shift ;; --current) critical=$2 shift ;; -c) critical=$2 shift ;; -x) exitstatus=$2 shift ;; --exitstatus) exitstatus=$2 shift ;; -p) pages=$2 shift ;; -C) comm=$2 shift ;; *) echo "Unknown argument: $1" print_usage exit $STATE_UNKNOWN ;; esac shift done #get maximum amount of toner max=`/usr/bin/snmpget -O Uvqs -v 1 -c $comm $host $oidmax` #get current amount of toner rem=`/usr/bin/snmpget -O Uvbqs -v 1 -c $comm $host $oidcur` hundred=100 #calculate approximate number of pages remaing based on maximum toner capacity, #manufacturer advised number of pages and remaing toner. rempages=`/usr/bin/expr $pages "/" $max "*" $rem` #calculate current percentage of toner remaining curpercent=`/usr/bin/expr $rem "*" $hundred "/" $max` if [[ -z $max ]]; then echo "CRITICAL - $host seems to be dead" exitstatus=2 elif [[ $curpercent -gt $critical ]]; then echo "OK - $host: $curpercent% remaining |Pages remaining=$rempages;" exitstatus=0 elif [[ $curpercent -lt $critical ]]; then echo "Critical - $host: $curpercent% remaining |Toner will need replacing soon - approx $rempages pages remaining;" exitstatus=2 elif [[ $curpercent -lt $warn ]]; then echo "Warning - $host: $curpercent% remaining |Toner needs ordering - approx $rempages pages remaining;" exitstatus=1 else echo "UNKNOWN - I see dead people - Something is wrong" exitstatus=3 fi exit $exitstatus
Last edited by Lee_K_81; 5th June 2008 at 10:12 AM.

Doesn't seem to work on my P2015's. Ok on my 5500 though.
Dont know about any other models, i've only tested with 2600n and 2605dn. You might want to try updating the firmware though. Some of my older 2600n's didnt give any data back until they were upgraded.

There doesn't appear to be a firmware update avalible for the P2015.
Not sure if this will help:
Hewlett-Packard LaserJet P2015 firmware upgrade 20061010
Also i'm not entirely sure what the oids may be for any other model. You could try doing an snmp walk of the device to see if it returns the values required.
There are currently 1 users browsing this thread. (0 members and 1 guests)