Introduction


Entering host system data into Nagios can be cumbersome if we have hundreds of devices. An auto-discovery feature would be nice. something that could find systems on the network and automatically generates host configuration items for Nagios.
When I took the task to add 500 printers to Nagios, doing so by hand was out of the question. Luckily, our IP assignments for network printers fall into a certain IP range per network and, lucky for me while unlucky for security, all printers have an unchanged default SNMP community string "public". As a result, I could write a small script that checks if a IP responds to a SNMP query returning the device type, then using this device type to identify printer types and finally writing it out to a Nagios configuration file. To help with naming the printer, I generated a network list source file containing a network name and network base IP which is read by the script.

About an hour later, I had my first configuration file containing the details of 382 printers located in 120 networks, ready to load into Nagios. I run a slightly modified script again for a second set of networks, since I wanted to separate them into a different nagios configuration file. In less then 90 minutes, I had the full 528 printers ready for monitoring, using the printer plugin from monitoring exchange. This search method could be applied to auto-discover other SNMP-enabled systems, our biggest device group in monitoring are network devices such as switches and routers (Currently, I have 700+).

Here is a example output, generated with the printerconf-gen-so.sh script above.

 ... headers above omitted ...
###############################################################################
# PRINTER DEFINITIONS below
###############################################################################
define host{
  use                   xerox-printer-so
  host_name             tokyochuo-printer-3
  alias                 tokyochuo-printer-3 (FUJI XEROX DocuCentre-III C440 3)
  address               192.49.64.10
}
define host{
  use                   xerox-printer-so
  host_name             tokyochuo-printer-4
  alias                 tokyochuo-printer-4 (FUJI XEROX DocuPrint 3050 4)
  address               192.49.64.11
}
define host{
  use                   kyocera-printer-so
  host_name             yokohama-printer-1
  alias                 yokohama-printer-1 (KYOCERA LS-C5016N 1)
  address               192.49.67.4
}
... and so on ...

After finishing the "discovery" and loading the configuration into nagios.cfg, the main printer hostgroup is showing all 528 printers.

nagios printer monitoring 1

After we got the printer hosts defined, we only need to add a health check service to monitor their status. Picking out one printer close by as a test object, I decided to try the check_printer-0.13.tar.gz plugin, available from monitoring exchange (local copy).

 libexec/check_printer -H 192.168.103.61 -C public
CRITICAL - "004-416 The Second Bias Transfer Roll assembly must be replaced.
Call your System Administrator. Printing can continue."

Depending on the point of view: We got lucky, our printer responds, and already reports an error. Before we continue, lets verify directly on the printers web management interface if the reported error is correct.

xerox printer error detail 1

Indeed, we have an issue with the second Bias transfer roll on this printer, so the plugin works. Now we can create the plugin command and service definition. I am adding all printers to the new service, using their respective groups.

 vi /srv/app/nagios/etc/objects/commands.cfg
# 'define check_printer' test with ./check_printer -H 192.168.103.61 -C public
define command{
  command_name check_printer
  command_line $USER1$/check_printer -H $HOSTADDRESS$ -C $ARG1$
}

vi /srv/app/nagios/etc/objects/printer-services.cfg
###############################################################################
# printer-services.cfg - First define a servicegroup for printer services
###############################################################################
define servicegroup{
  servicegroup_name        printer-checks        ; The name of the hostgroup
  alias                    Printer Health Checks ; Long name of the group
}
###############################################################################
# Define the memory check template service
###############################################################################
define service{
  name                          generic-printer-service
  active_checks_enabled         1
  passive_checks_enabled        1
  parallelize_check             1
  obsess_over_service           1
  check_freshness               0
  notifications_enabled         1
  event_handler_enabled         1
  flap_detection_enabled        1
  failure_prediction_enabled    1
  process_perf_data             1
  retain_status_information     1
  retain_nonstatus_information  1
  is_volatile                   0
  check_period                  12x5_weekdays	; nobody cares about nighttime
  max_check_attempts            3
  normal_check_interval         30
  retry_check_interval          2
  contact_groups                printer-admins
  notification_options          u,c,r
  notification_interval         1440            ; notify only once a day
  notification_period           12x5_weekdays	; don't wake anybody up
  register                      0
  servicegroups                 printer-checks
}
###############################################################################
# Check Printer Status using the generic check_printer plugin
###############################################################################
define service {
  use                           generic-printer-service
  hostgroup                     printers-headoffice
  service_description           printer-check
  check_command                 check_printer!public
}
define service {
  use                           generic-printer-service
  hostgroup                     printers-salesoffice
  service_description           printer-check
  check_command                 check_printer!public
} 

After enabling the service in nagios.cfg, the printer health monitoring was complete. And just by sheer numbers, some printers have issues. They might be simply switched off, have a hardware issue, the toner gets low... Enough work to follow up for the printer admins. With email notification and online monitoring our printer management is now pro-active, identifying HW issues and ordering toner before printing stops.

Credits, Links and additonal information


More Information:

Example images from Nagios, showing the printer monitoring


nagios printer servicegroup nagios printer monitoring detail critical 1 nagios printer monitoring detail critical 2 nagios printer monitoring detail warning 1