lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
305 stars 38 forks source link

How to add an exe-customsensor using prtgapi? #209

Closed gjh71 closed 3 years ago

gjh71 commented 3 years ago

I can add exexml customsensor using prtgapi, but NOT 'exe' customsensors I've created numerous custom powershell scripts which we deploy into the exexml directory of the target-probe. And where those sensors usually are more than sufficient for us, now I have one with which I would like to return 1 result with text. That leads me to the more 'simple' exe-script.

I can successfully add this through the user-interface of prtg. But as we are into scripting everything, I would also like to add this using our 'initialise-prtg' script.

When I try:

get-device "targetdevice" | get-sensortarget -type exexml

I get a complete list of all my 'exexml' script which reside in the C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML folder of the target. The scripts missing out are my 'exe' scripts. And to this point I understand, because (I assume) I would need to use:

get-device "targetdevice" | get-sensortarget -type exe

But that produces the -same- output.

lordmilko commented 3 years ago

Hi @gjh71,

PrtgAPI only natively supports creating a limited number of sensor types, including EXE/Script Advanced. For all other sensor types however, you can still create these by specifying you want a -RawType to cmdlets like Get-SensorTarget and New-SensorParameters

$device = Get-Device -Id 1001
$params | New-SensorParameters -RawType exe
$params.exefile = $params.Targets.exefile | where value -like "Load_Test_Memory*"
$device | Add-Sensor $params

For more information, please see the following article

Please let me know if you have any further questions

Regards, lordmilko