Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
1  
On what platform are the USB printers connected? –  SvW 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
add comment

1 Answer

up vote 8 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 http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx
$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 http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx for further information about possible information you can get from the win32_printer WMI object.

share|improve this answer
1  
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
add comment

Your Answer

 
discard

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.