Closed BragaGuilherme closed 1 year ago
Hi @BragaGuilherme,
When you go to create a new sensor in the PRTG UI, it shows a variety of settings specific to the sensor type you are trying to create. PrtgAPI has a facility built in where it can load the Add Sensor page for a given sensor type, scrape all the input fields present on that page, and then wrap them up in an object that you can interact with. That object is the DynamicSensorParameters
object.
In the example listed, we scrape the parameters that would be required to create a vmwaredatastoreextern
sensor and then store the retrieved DynamicSensorParameters
object in a PowerShell variable called $params
. We then dump the contents of the $params
variable to show what parameters we have available for customization.
Thus, using this information, you might see the vmwarewriteresult
property, and guess that this property is probably related to the setting you'll see in the PRTG UI regarding whether the scan results should be saved to disk. You can then set this property to an appropriate value by perhaps doing
$params.vmwarewriteresult = 1
You can confirm which properties correspond to which input fields in the PRTG UI by doing Ctrl+Shift+J to being up the Chrome inspector and then using the selector button to select an element on the page. You can then see what the internal name of that property is, which will be what is shown on the DynamicSensorParameters
object
Thanks for anwser me @lordmilko
I followed your instructions, accessed the properties through Chrome, and added them as you indicated. However, I still couldn't get it to work. When using PowerShell, I'm getting the error message: "pythonscript : The term 'pythonscript' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:4 character:1 pythonscript : Modbus Python.py CategoryInfo : ObjectNotFound: (pythonscript:String) [], CommandNotFoundException FullyQualifiedErrorId : CommandNotFoundException
Am I doing something wrong and not realizing it?
The presence of >>
shows that there are extraneous newlines that should not be there, indicating you may have copied and pasted something containing multiple lines into PowerShell, or pressed Shift+Enter within PowerShell itself
Typing $params
and then hitting enter will dump the contents of $params
To set a value, do
$params.pythonscript = "Modbus Python.py"
What's going on?
I'm trying to create an Advanced Sensor Python script using your API, but I have doubts about the DynamicSensorParameters. In the example provided, the following parameters were shown:
C:> $params = Get-Device esxi-1 | New-SensorParameters -RawType vmwaredatastoreextern C:> $params
datafieldlist : 1 datafieldlistcheck : Datastore1 datastoreid : vmwarewriteresult : 0 Targets : {[datafieldlistcheck, PrtgAPI.GenericSensorTarget[]]} Source : esxi-1 SensorType : vmwaredatastoreextern Priority : Three InheritTriggers : True InheritInterval : True ...
"I didn't understand where these parameters came from or were derived. In my case, I want to use an Advanced Sensor Python script and should only specify which script to use and add the additional parameters. How should I proceed?
Due Dilligance