Use Nagios to monitor toner levels of local USB printers
772
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?
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.
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.
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.