Monitoring if we have a USB device connected

How great it is to have the entire organization monitored, ¿truth? I leave you another quite interesting post if you want to know if you have a USB device connected to a computer, we will monitor it from Centreon and we can rest assured, that if the USB is disconnected, Monitoring will alert us! Ideal for all these USB license backpacks, For example!

 

We'll do this using a simple Powershell script, which when executed will tell if we have a USB device connected or not, we will execute this script remotely through NRPE and we will obtain its results in the monitoring we have, Centreon, Nagios… If you want to take a look at how NRPE works, Reviewed This document. By the way, this script is passed to me by a client, A friend, A great! Mikel is coming for you 😉

 

This will be the script that we need to place in our scripts folder, you edit it and enter your device identifier, you execute it and you will see how simple its output is.

 

[SourceCode]$USB_Conecta = get-wmiobject -class "Win32_USBController" -namespace "rootCIMV2" | Select -ExpandProperty DeviceID
If ($USB_Conecta -eq "USBVID_0529&PID_0001AC101401&VUSB005&1") {
# If the service is running, we return the corresponding text and status 0
Write-Host "OK"! USB is in $service_status status"
Exit 0
}
Else {
# If the service is not running, we return the corresponding text and status 2
Write-Host "CRITICAL! USB is in $service_status status"
Exit 2
}[/SourceCode]

 

Then as always, We will modify the nsclient.ini of the computer where we will add the alias with which we will call the command to execute, I leave you an example of the part you will need:

[SourceCode][/settings/external scripts/scripts]

check_USB = cmd /c echo scriptscheck_USB.ps1; exit($lastexitcode) | powershell.exe -command –

[/settings/external scripts/alias]

check_USB = check_USB

…[/SourceCode]

 

 

And nothing, The usual, you create the Service with the check_nrpe Command, we associate it with a Host and in the Argument we put the alias that we use in the NSClient configuration file and hint that the motorist comes! I hope you found it interesting!

 

Recommended Posts

Author

nheobug@bujarra.com
Autor del blog Bujarra.com Cualquier necesidad que tengas, Do not hesitate to contact me, I will try to help you whenever I can, Sharing is living ;) . Enjoy documents!!!