Lee_K_81 Posted May 6, 2008 Posted May 6, 2008 I'm using nagios to monitor my network and i want to add the network printers to it. They are mostly HP 2600N's. I've manged to find the OID for the maximum amount of toner, and the OID for the current amount of toner remaining. This is a little annoying as the maximum (M) is 470, the current © is 38. These values dont really imply much. I would prefer to do a quick calculation i.e. (C/M)*100 to get the percentage remaining. Any body got any ideas on how to do the calculations? Thanks in advance
Geoff Posted May 6, 2008 Posted May 6, 2008 Isn't using 'check_printer' and/or 'check_hpjd' sufficient for you?
Lee_K_81 Posted May 6, 2008 Author Posted May 6, 2008 Thanks Geoff, Could have put money on you being first to respond! I've looked at check_hpjd and it's great for telling me the status i.e. on the one i've set it up on at the moment it says " Toner Low ("Ready") " the problem being it doesnt say which toner is low. Unless i'm missing some vital arguments which is always possible / likely. Lee
Ric_ Posted May 6, 2008 Posted May 6, 2008 I think that you need to write your own plugin if you want to be more specific - or you might find what you are looking for on NagiosExchange if you are lucky. 1
Geoff Posted May 6, 2008 Posted May 6, 2008 This Cacti forum thread will help you out developing a plugin. Monitoring HP Printer Toner Levels At the moment, I just look at the printers web status page when I get a warning. 1
Lee_K_81 Posted May 6, 2008 Author Posted May 6, 2008 This Cacti forum thread will help you out developing a plugin. Monitoring HP Printer Toner Levels At the moment, I just look at the printers web status page when I get a warning. I'd found that, but it seems to be discussing milligrams of toner remaining, i'd like percentage. I think i may just have to stick with the milligrams or write my own plug in.
Geoff Posted May 6, 2008 Posted May 6, 2008 Well you can work back to a percentage based on mg. Assuming you know the total mg (hint: it's written in the toner specs).
Lee_K_81 Posted May 6, 2008 Author Posted May 6, 2008 as i said, i can get the total capacity (470mg) and the current (38mg) but i want the percentage (8% i.e. (38/470)*100), i might just have to show the values as is.
Ric_ Posted May 6, 2008 Posted May 6, 2008 NagiosExchange: check_hp_verbrauch should be exactly what you want! 1
Lee_K_81 Posted May 7, 2008 Author Posted May 7, 2008 Thanks _Ric, that script looks like it will work brilliantly once i've got it working, which is why it's taken me so long to get back. One thing i'm having trouble with at the moment is calculating the percentage, see code below: MAX=`snmpget -O Uvbqs -v 1 -c Public $host $oidmax REST=`snmpget -O Uvbqs -v 1 -c Public $host $oidcur HUNDRED=100 CURRENT=`expr $MAX - $REST` CURPERCENT=`expr $CURRENT "*" $HUNDRED "/" $MAX` [snip] echo "OK - $host: $CURRENT / $CURPERCENT% | Pages=$CURRENT [snip] the host name shows correctly but everything else is blank. For testing i've tried: echo "MAX=$MAX REST=$REST CURRENT=$CURRENT CURPERCENT=$CURPERCENT" MAX and REST show up the correct values but CURRENT and CURPERCENT don't. I figured maybe expr wasnt working correctly but changing it to: CURRENT=`expr 10 + 1` Correctly gives 11 but: CURRENT=`expr $HUNDRED + 1` is blank. Seems to be an issue with doing an expression on a variable. Any ideas anybody? Thanks.
Lee_K_81 Posted May 7, 2008 Author Posted May 7, 2008 It works ok here. What shell are you using? erm que? echo $SHELL gives me /bin/bash is that right?
Geoff Posted May 7, 2008 Posted May 7, 2008 and bash is really bash and not symlinked to something else?
Lee_K_81 Posted May 7, 2008 Author Posted May 7, 2008 i've not done that (i dont think) so unless it happens without knowing......
Lee_K_81 Posted May 8, 2008 Author Posted May 8, 2008 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
Lee_K_81 Posted May 14, 2008 Author Posted May 14, 2008 (edited) 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. Edited May 15, 2008 by Lee_K_81
Lee_K_81 Posted May 14, 2008 Author Posted May 14, 2008 (edited) 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 #! /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 Lee Edited June 5, 2008 by Lee_K_81
Geoff Posted May 14, 2008 Posted May 14, 2008 Doesn't seem to work on my P2015's. Ok on my 5500 though.
Lee_K_81 Posted May 14, 2008 Author Posted May 14, 2008 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.
Geoff Posted May 14, 2008 Posted May 14, 2008 There doesn't appear to be a firmware update avalible for the P2015.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now