Jump to content

Recommended Posts

Posted

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

Posted

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

Posted
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.

Posted
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).
Posted
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.
Posted

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.

Posted

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

Posted (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 by Lee_K_81
Posted (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 by Lee_K_81
Posted
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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...