Munin - SNMP plugin to display HP Color Laser printer Toner levels



Munin allows simple supervision of any SNMP enabled device.

As HP Color Laser Printers are SNMP enabled, it becomes possible to follow all printer internal levels thru Munin.

This article provides a plugin implementation that allows you to follow all 4 toner levels (black, cyan, magenta & yellow) on any HP Color Laser printer.

With the help of this plugin you'll be able to display you printer toner level in almost real time. As a pre-requisite, you need a fuly operational instance of Munin supervision.

This has been tested on a HP Color LaserJet CM1312nfi MFP with Munin running on a Debian server.

1. General Explanation

This plugin allows you to follow toner levels of a HP Color Laser Printer in a graphical way.

It supports all 3 Munin SNMP plugins calling modes :

  • snmpconf : to check if a given printer is compatible with the plugin
  • config : to describe the plugin
  • normal : to read toner levels

This plugin can run as a simple plugin with one graph display all 4 toner levels or as a multigraph plugin, displaying one graph per toner.

To configure its behaviour, you need to set the MULTIGRAPH parameter :

on (default) off
Uses Munin multigraph capabilities,
to display one graph per toner cartridge
Displays one unique graph,
with all 4 toner cartridges levels


2. Installation

First step is to download the plugin and to install the plugin from my GitHub Munin plugins repository.

# wget -O /usr/share/munin/plugins/snmp__tonerlevel_hp
# chmod +x /usr/share/munin/plugins/snmp__tonerlevel_hp

# -*- sh -*-
# -------------------------------------------------------
#  Munin node script
#  Monitor the toner level of HP color printers
#  Retrieves toner levels for black, cyan, magenta & yellow cartridges
#  Used in
#  Parameters : 
#    $1 : none, "snmpconf" or "config"
#  20/06/2014, V1.0 - Creation by N. Bernaerts
#  07/07/2014, V2.0 - Changed to multigraph
#  21/08/2014, V3.0 - Handle multigraph as an option
# -------------------------------------------------------

: << =cut

=head1 NAME

snmp__tonerlevel_hp - Munin plugin to monitor the toner level of HP Color Laser Printers


Any SNMP-capable HP Color Printer


No specific configuration needed.
This plugin uses public community.


The level in percentage of printer toner cartridges


This plugin requires support for the cartridge level MIBs.


  #%# family=snmpauto
  #%# capabilities=snmpconf

=head1 VERSION


=head1 BUGS

None known.

=head1 AUTHOR

Copyright (C) 2014 Nicolas Bernaerts

=head1 LICENSE



# -------------------------------------------------------
#  User defined configuration
# -------------------------------------------------------

# if defines if display is multigraph (one graph per toner)
# or if you want to get all toner levels on the same graph
#  on  : one graph per toner
#  off : all toner levels on the same graph

# set levels for warning in percent remaining
# values as defined in

# -------------------------------------------------------
#  Configure all MIBs adresses
# -------------------------------------------------------

# printer name

# cartridge colors max level

# cartridge colors current level

# -------------------------------------------------------
#  Get printer specs
# -------------------------------------------------------

# get printer name from script name
PRINTER_IP=$(basename $0 | cut -d'_' -f2)

# -------------------------------------------------------
#  Read all MIBs data from the printer
# -------------------------------------------------------

# if not in autoconf process, read SNMP data
if [ "$1" != "snmpconf" ]; then 
  # read SNMP MIB
  MIB_RESULT=$(snmpget -v1 -One -c public $PRINTER_IP $MIB_NAME \

  # get values from result
  PRINTER_NAME=$(echo $MIB_RESULT | sed 's/.*'$MIB_NAME'[^"]*"\([^"]*\).*/\1/g')
  MAX_BLACK=$(echo $MIB_RESULT | sed 's/.*'$MIB_MAX_BLACK'[ =:A-Z]*\([0-9]*\).*/\1/g')
  MAX_CYAN=$(echo $MIB_RESULT | sed 's/.*'$MIB_MAX_CYAN'[ =:A-Z]*\([0-9]*\).*/\1/g')
  MAX_MAGENTA=$(echo $MIB_RESULT | sed 's/.*'$MIB_MAX_MAGENTA'[ =:A-Z]*\([0-9]*\).*/\1/g')
  MAX_YELLOW=$(echo $MIB_RESULT | sed 's/.*'$MIB_MAX_YELLOW'[ =:A-Z]*\([0-9]*\).*/\1/g')
  LEVEL_BLACK=$(echo $MIB_RESULT | sed 's/.*'$MIB_LEVEL_BLACK'[ =:A-Z]*\([0-9]*\).*/\1/g')
  LEVEL_CYAN=$(echo $MIB_RESULT | sed 's/.*'$MIB_LEVEL_CYAN'[ =:A-Z]*\([0-9]*\).*/\1/g')
  LEVEL_MAGENTA=$(echo $MIB_RESULT | sed 's/.*'$MIB_LEVEL_MAGENTA'[ =:A-Z]*\([0-9]*\).*/\1/g')
  LEVEL_YELLOW=$(echo $MIB_RESULT | sed 's/.*'$MIB_LEVEL_YELLOW'[ =:A-Z]*\([0-9]*\).*/\1/g')

# -------------------------------------------------------
#  Handle SNMP autoconf call
# -------------------------------------------------------

# snmpconf : announce required MIBs
if [ "$1" = "snmpconf" ]; then
  echo "require $MIB_NAME"
  echo "require $MIB_MAX_BLACK"
  echo "require $MIB_MAX_CYAN"
  echo "require $MIB_MAX_MAGENTA"
  echo "require $MIB_MAX_YELLOW"
  echo "require $MIB_LEVEL_BLACK"
  echo "require $MIB_LEVEL_CYAN"
  echo "require $MIB_LEVEL_MAGENTA"
  echo "require $MIB_LEVEL_YELLOW"

# -------------------------------------------------------
#  Handle configuration call
# -------------------------------------------------------

# config : read node configuration
elif [ "$1" = "config" ]; then

  # printer general infos
  echo "host_name $PRINTER_IP"

  if [ "$MULTIGRAPH" = "off" ]; then
    echo "graph_title Printer Toners"
    echo "graph_vlabel Cartridge level (%)"
    echo "graph_category toner"
    echo "graph_info This graph shows all toner levels in %"
    echo "graph_args --upper-limit 400 -l 0 --rigid"

  # --------------------
  # Black cartridge
  # --------------------

  if [ "$MULTIGRAPH" = "on" ]; then
    echo "multigraph black"
    echo "graph_title Black Toner"
    echo "graph_vlabel Cartridge level (%)"
    echo "graph_category toner"
    echo "graph_info This graph shows the Black toner level in %"
    echo "graph_args --upper-limit 100 -l 0 --rigid"

  echo " $PRINTER_NAME black toner level is $LEVEL_BLACK out of $MAX_BLACK"
  echo "black-left.label Black available"
  echo "black-left.draw AREASTACK"
  echo "black-left.colour 000000"
  echo "black-left.min 0"
  echo "black-left.max 100"
  echo "black-used.label Black used"
  echo "black-used.draw AREASTACK"
  echo "black-used.colour d0d0d0"
  echo "black-used.min 0"
  echo "black-used.max 100"
  [ "$CRITICAL" ] && echo "black-left.critical $CRITICAL"
  [ "$WARNING" ] && echo "black-left.warning $WARNING"

  # --------------------
  # Cyan cartridge
  # --------------------

  if [ "$MULTIGRAPH" = "on" ]; then
    echo "multigraph cyan"
    echo "graph_title Cyan Toner"
    echo "graph_vlabel Cartridge level (%)"
    echo "graph_category toner"
    echo "graph_info This graph shows the Cyan toner level in %"
    echo "graph_args --upper-limit 100 -l 0 --rigid"

  echo " $PRINTER_NAME cyan toner level is $LEVEL_CYAN out of $MAX_CYAN"
  echo "cyan-left.label Cyan available"
  echo "cyan-left.draw AREASTACK"
  echo "cyan-left.colour 00ffff"
  echo "cyan-left.min 0"
  echo "cyan-left.max 100"
  echo "cyan-used.label Cyan used"
  echo "cyan-used.draw AREASTACK"
  echo "cyan-used.colour d0ffff"
  echo "cyan-used.min 0"
  echo "cyan-used.max 100"
  [ "$CRITICAL" ] && echo "cyan-left.critical $CRITICAL"
  [ "$WARNING"  ] && echo "cyan-left.warning $WARNING"

  # --------------------
  # Magenta cartridge
  # --------------------

  if [ "$MULTIGRAPH" = "on" ]; then
    echo "multigraph magenta"
    echo "graph_title Magenta Toner"
    echo "graph_vlabel Cartridge level (%)"
    echo "graph_category toner"
    echo "graph_info This graph shows the Magenta toner level in %"
    echo "graph_args --upper-limit 100 -l 0 --rigid"

  echo " $PRINTER_NAME magenta toner level is $LEVEL_MAGENTA out of $MAX_MAGENTA"
  echo "magenta-left.label Magenta available"
  echo "magenta-left.draw AREASTACK"
  echo "magenta-left.colour ff00ff"
  echo "magenta-left.min 0"
  echo "magenta-left.max 100"
  echo "magenta-used.label Magenta used"
  echo "magenta-used.draw AREASTACK"
  echo "magenta-used.colour ffd0ff"
  echo "magenta-used.min 0"
  echo "magenta-used.max 100"
  [ "$CRITICAL" ] && echo "magenta-left.critical $CRITICAL"
  [ "$WARNING"  ] && echo "magenta-left.warning $WARNING"

  # --------------------
  # Yellow cartridge
  # --------------------

  if [ "$MULTIGRAPH" = "on" ]; then
    echo "multigraph yellow"
    echo "graph_title Yellow Toner"
    echo "graph_vlabel Cartridge level (%)"
    echo "graph_category toner"
    echo "graph_info This graph shows the Yellow toner level in %"
    echo "graph_args --upper-limit 100 -l 0 --rigid"

  echo " $PRINTER_NAME yellow toner level is $LEVEL_YELLOW out of $MAX_YELLOW"
  echo "yellow-left.label Yellow available"
  echo "yellow-left.draw AREASTACK"
  echo "yellow-left.colour ffff00"
  echo "yellow-left.min 0"
  echo "yellow-left.max 100"
  echo "yellow-used.label Yellow used"
  echo "yellow-used.draw AREASTACK"
  echo "yellow-used.colour ffffa0"
  echo "yellow-used.min 0"
  echo "yellow-used.max 100"
  [ "$CRITICAL" ] && echo "yellow-left.critical $CRITICAL"
  [ "$WARNING"  ] && echo "yellow-left.warning $WARNING"

# -------------------------------------------------------
#  Handle data read call
# -------------------------------------------------------

# normal case : read cartridge levels

  # --------------------
  # Black level
  # --------------------

  [ "$MULTIGRAPH" = "on" ] && echo "multigraph black"
  echo "black-left.value $BLACK_AVAILABLE" 
  echo "black-used.value $BLACK_USED" 

  # --------------------
  # Cyan level
  # --------------------

  [ "$MULTIGRAPH" = "on" ] && echo "multigraph cyan"
  echo "cyan-left.value $CYAN_AVAILABLE" 
  echo "cyan-used.value $CYAN_USED" 

  # --------------------
  # Magenta level
  # --------------------

  [ "$MULTIGRAPH" = "on" ] && echo "multigraph magenta"
  echo "magenta-left.value $MAGENTA_AVAILABLE" 
  echo "magenta-used.value $MAGENTA_USED" 

  # --------------------
  # Yellow level
  # --------------------

  [ "$MULTIGRAPH" = "on" ] && echo "multigraph yellow"
  echo "yellow-left.value $YELLOW_AVAILABLE" 
  echo "yellow-used.value $YELLOW_USED" 

exit 0

It's now time to disable multigraph mode (set MULTIGRAPH parameter to off) if needed.

By default it is working as a multigraph plugin (one graph per toner cartridge).

3. Activation

As with any SNMP plugin, you first need to declare your SNMP enabled printer in your Munin server /etc/hosts.


# printer    hp1312cm

You can now declare your printer in Munin configuration file /etc/munin/munin.conf.

As we are dealing with an SNMP plugin, the printer should be declared as follow :


    use_node_name no

Once your printer is declared, you just need to activate the plugin like any other Munin SNMP plugin with a symbolic link including your printer name.

Munin-mode needs to be restarted for the new node to become active.

# ln -s /usr/share/munin/plugins/snmp__tonerlevel_hp /etc/munin/plugins/snmp_hp1312cm_tonerlevel_hp
# service munin-node restart

4. Test

You are now ready to test your plugin with munin-run :

# munin-run snmp_hp1312cm_tonerlevel_hp config
host_name hp1312cm
multigraph black
graph_title Black Toner
graph_vlabel Cartridge level (%)
graph_category toner
graph_info This graph shows the Black toner level in %
graph_args --upper-limit 100 -l 0 --rigid HP Color LaserJet CM1312nfi MFP black toner level is 1170411 out of 3442386
black-left.label Black available
black-left.draw AREASTACK
black-left.colour 000000
black-left.min 0
black-left.max 100
black-used.label Black used
black-used.draw AREASTACK
black-used.colour d0d0d0
black-used.min 0
black-used.max 100
multigraph cyan
# munin-run snmp_hp1312cm_tonerlevel_hp
multigraph black
black-left.value 33
black-used.value 67
multigraph cyan
cyan-left.value 51
cyan-used.value 49
multigraph magenta
magenta-left.value 45
magenta-used.value 55
multigraph yellow
yellow-left.value 45
yellow-used.value 55

Everything is working.

You should start to follow your HP Color Laser printer toner levels after few minutes.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus