Closed bryanmcgrath-payroc closed 5 months ago
I see several inefficiencies in the above code
$item_sensors = Get-Device $item.Name | Get-Sensor * | Select *
- when you do | Select *
this converts the Sensor
objects emitted by Get-Sensor
into PSCustomObject
objects, which prevents you from using them with any further PrtgAPI cmdlets. You should just do $item_sensors = Get-Device $item.Name | Get-Sensor
Get-Sensor
twice for Sensor
objects that you already have, but are now unusable because you converted them into PSCustomObject
objects. Once you get rid of the Select
as mentioned above, $sensor
will have a Sensor
object in it alreadyGet-Channel
multiple times for a single channel, due to the fact that one of the API calls made during Get-Channel
contains part of the information of all channels anyway, so by calling Get-Channel
twice you're executing potentially 4 API requests, whereas calling it once might result in just 3 requestsSo, with these changes in mind, your code might look something like this
$item_sensors = Get-Device $item.Name | Get-Sensor
foreach($sensor in $item_sensors)
{
if($sensor.DisplayType -eq "SNMP Traffic 64bit")
{
$channels = $sensor | Get-Channel *traffic*
$in_channel = $channels | where Name -eq "Traffic In"
$out_channel = $channels | where Name -eq "Traffic Out"
}
}
This advice gave me exactly what I needed, the script completes in 2 hours now and has been restored as a daily run.
Thanks LordMilko!
What's going on?
I've designed a Powershell Script to query our PRTG Probes and return a CSV on all Sensors and Devices - This allows us to build telemetry on our Sensors configuration Standards and correct drift via automation. Such as, the Device Name is incorrect or a Device is missing a memory sensor, etc.
The Script works, however we have 15+ Probes and 10K Sensors so it can take quite some time to complete. We get around 2 runs a day before we added an enhancement, now we can barely get on run a day. The enhancement is to gather channel information for SNMP Traffic Sensors.
What we would ideally like to have is a fast and efficient method of polling all Sensors, Channels, Devices and Groups within PRTG and return all configuration. We would then store this data in our Data Visualisation Tool in CSV format and build reports around our Standards and current Monitoring.
Is there an easier way to achieve this than the above method? Is there a more efficient way to run the script perhaps?
Thanks for the PRTG API and for this thread.
Script: `$probes = Get-Probe *
foreach($probe in $probes) { $devices = Get-Probe $probe | Get-Device | Select
} Disconnect-PrtgServer`
Due Dilligance