How to check connection between windows and anywhere usb with nagios

The easiest way to monitor the connection between your Digi Anywhere USB device and a server is to monitor the USB device connected it. I use Nagios to monitor several indicators in each server, and the following script can be used to monitor if USB devices are connected:

strComputer = "."
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colDevices = objWMIService.ExecQuery ("Select * From Win32_USBControllerDevice")
 
For Each objDevice in colDevices
    strDeviceName = objDevice.Dependent
    strQuotes = Chr(34)
    strDeviceName = Replace(strDeviceName, strQuotes, "")
    arrDeviceNames = Split(strDeviceName, "=")
    strDeviceName = arrDeviceNames(1)
    Set colUSBDevices = objWMIService.ExecQuery ("Select * From Win32_PnPEntity Where DeviceID = '" & strDeviceName & "'")
    For Each objUSBDevice in colUSBDevices
        'Wscript.Echo objUSBDevice.Description
        If objUSBDevice.Description="SCR3311 USB Smart Card Reader" Then
           WScript.Echo "OK - Card reader detected"
           WScript.Quit 0
        End If
    Next
Next
 
WScript.Echo "WARNING - No card reader detected"
WScript.Quit 1

In my case, I monitor a card reader that identifies as "SCR3311 USB Smart Card Reader". You should type the exact name of the device you're monitoring at that spot. If you don't know the exact name of the device, uncomment the line
'Wscript.Echo objUSBDevice.Description
and then execute
cscript //nologo //t:10 "check_cardreader.vbs"

Put above file in c:\program files (x86)\nrpe\check_cardreader.vbs and update nrpe.cfg to contain:
command[check_cardreader]=cscript //nologo //t:10 "c:\program files (x86)\nrpe\check_cardreader.vbs"

After restarting the NRPE service, you're ready to monitor the USB device.

© GeekLabInfo How to check connection between windows and anywhere usb with nagios is a post from GeekLab.info. You are free to copy materials from GeekLab.info, but you are required to link back to http://www.geeklab.info

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Leave a Reply