Closed xasz closed 1 year ago
If you specify -Verbose
you can see the exact API requests a given PrtgAPI command executes
Get-Group -ID $PRTGGroupID -Verbose
Get-Sensor -Group $prtgGroup.Id -Verbose
The PRTG HTTP API provides the following filters for querying based on a parent object
Based on this, it is not valid to do -Group $prtgGroup.Id
. The -Group
parameter allows you to specify either the name of the group to query, or a Group
object (from which the Name
is extracted)
Get-Group Servers | Get-Sensor
Get-Sensor -Group Servers
The issue with filtering by name however is that it is possible that you could have multiple groups with a given name all across your hierarchy. As such, filtering for sensors under the group "Servers" may be completely ambiguous. PrtgAPI is able to resolve this ambiguity automatically for you, at the cost of needing to execute additional API requests. You can disable this behavior by specifying -Recurse:$false
Get-Group Servers | Get-Sensor -Recurse:$false
However, I would note that you have a bigger issue here: it should not take 10 seconds for the Get-Sensor
command to run. I would recommend focusing on improving the performance of your PRTG server. Specifying -Recurse:$false
may make your scripts run faster, however as noted above if you have multiple groups with the same name you may introduce some unexpected side effects.
Well, after further testing. it does not seem to do the same thng. Sorry, you was faster thatn me. wanted to close right now.
Correction: theres two reasons piping from a group is slower than not.
-Recurse:$false
disables this behaviorI believe Get-Sensor will always attempt to resolve ambiguous groups when a Group
object is specified. If you don't want to do that, you have to specify the name of the group instead.
What are you trying to do, and to what extent does PrtgAPI provide existing functionality around this?
I am manipulate a bunch of sensors and try to optimize my scripts and found this:
There is a 10 seconds difference just by how you use
Get-Sensor
I tried to figure it out in the code, but could not figure it out. I never wrapped C# in Powershell and did not quite understand from just looking at your code, otherwise i would have tried to pull.
I just do not understand who
Get-Sensor -Group <>
is differently handelt then Piping a Object into it. There has to be some Object-Type resolving which seems so take about 10 seconds.I am changing my script from piping the
$Group
object into Get-Sensor to use the-Group
Parameter, so far i can improve my script runtime by alot and i mean really, a lot. Call this 6 times and you have a minute and i am not sure if i am saving perfomance on my prtg core server.Perhaps someone can point me to the Object resolving in the code and perhaps i can work on a optimization.
Is this something that has some sort of parallel in the PRTG UI? If so where do you go/how do you normally do it?
No
Due Dilligance