我有一堆电脑与本地USB连接的打印机。 我希望能够使用Nagios监控卡纸和碳粉水平等情况,但是我所能find的所有内容都涉及使用SNMP。
我如何使用Nagios来监视本地USB打印机?
像这样的PowerShell脚本应该可以做到这一点。 这可以通过Nagios调用,并返回一个退出代码0和“确定:所有打印机都正常”或退出代码2和关于有问题的打印机的信息。
#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
我目前还没有可用于testing的Nagios安装,但是这是从我以前用于Nagios的另一个PowerShell脚本中修改的。
请参阅http://msdn.microsoft.com/en-us/library/windows/desktop/aa394363(v=vs.85).aspx,以获取有关从win32_printer WMI对象获得的可能信息的更多信息。