Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a bunch of computers with local USB attached printers. I'd like to be able to monitor things like paper jams and toner levels with Nagios but all I've been able to find involves using SNMP.

How can I use Nagios to monitor local USB printers?

share|improve this question
On what platform are the USB printers connected? – Sven Feb 28 '12 at 23:56
If it's Windows I could see using check_wmic and a WMI query, if the data is available there. – SpacemanSpiff Feb 29 '12 at 0:23
@SvenW It's Windows XP. – Kalamane Feb 29 '12 at 4:37
up vote 9 down vote accepted

A PowerShell script like this should do the trick. This can be called via Nagios and will return an exit code of 0 and "OK: All printers are normal" or an exit code of 2 and information about the printer(s) that have a problem.

#Initialize variables
$nagiosStatus = "0"
$nagiosDescription = ""
$detectedErrorStateDescriptions = New-Object string[] 12

#Assign error state descriptions - see
$detectedErrorStateDescriptions[0] = "Unknown"
$detectedErrorStateDescriptions[1] = "Other"
$detectedErrorStateDescriptions[2] = "No Error"
$detectedErrorStateDescriptions[3] = "Low Paper"
$detectedErrorStateDescriptions[4] = "No Paper"
$detectedErrorStateDescriptions[5] = "Low Toner"
$detectedErrorStateDescriptions[6] = "No Toner"
$detectedErrorStateDescriptions[7] = "Door Open"
$detectedErrorStateDescriptions[8] = "Jammed"
$detectedErrorStateDescriptions[9] = "Offline"
$detectedErrorStateDescriptions[10] = "Service Requested"
$detectedErrorStateDescriptions[11] = "Output Bin Full"

#Check the status of each printer on the system
ForEach ( $printer in ( Get-WmiObject win32_printer ) ) {
    If ( ( $printer.DetectedErrorState -ne "0" ) -and ( $printer.DetectedErrorState -ne "2" ) ) {
        $nagiosStatus = "2"
        If ($nagiosDescription -ne "") {
            $nagiosDescription = $nagiosDescription + ", "
        $nagiosDescription = $nagiosDescription + $printer.Name + ":" + $detectedErrorStateDescriptions[$printer.DetectedErrorState]

#Output the status
If ( $nagiosStatus -eq "2" ) {
    Write-Host "CRITICAL: " $nagiosDescription
Else {
    Write-Host "OK: All printers are normal"

exit $nagiosStatus

I do not have a Nagios installation available to me for testing at the moment, but this is modified from another PowerShell script that I used to use with Nagios.

See for further information about possible information you can get from the win32_printer WMI object.

share|improve this answer
Thats a nifty script +1 – Jacob Feb 29 '12 at 2:57
Tested with Nagios, works as is. – Kalamane Mar 2 '12 at 20:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.