During an analysis of a PRTG deployment we found out that lots of groups, devices and sensors were configured to override the scanning interval and the preferred action for when a sensor query fails.
Because there are almost 6 thousand sensors, we don't want to do this manually, but unfortunately neither the HTTP API as the PowerShell module PrtgAPI doesn't return the preferred action for when a sensor query fails when requesting a list of all sensors. Paessler recommends using the option 'Set sensor to warning for 1 interval, then set to "down"', but we would like to know how many and which sensors have an alternative setting, so we'll have retrieve that information.
Fortunately the setting can be retrieved per sensor, by requesting the specific setting via the HTTP API.
Our solution is described below
It took a little effort to find out the name of the property, in the webportal described as "If a Sensor Query Fails". The name of property is actually "errorintervalsdown"
I'm using PowerShell as a language, so it's my preference to use the PowerShell module PrtgAPI and use web requests to the HTTP API to find that specific property.
Install the PowerShell module:
Find-Module -Name PrtgAPI | Install-Module
The code is as follows:
Param ( $prtgwebserviceurl = "prtg.contoso.com" $user = "username" $pass = "password" ) # Connect to the PRTG webservice Connect-PrtgServer -Server $prtgwebserviceurl # Get list of all sensors and predefined properties $Sensors = Get-Sensor # Add the value of the property errorintervalsdown to each sensor and name the property "ActionOnQueryFails" ForEach ( $Sensor in $Sensors ) { $uri = "HTTPS://$prtgwebserviceurl/api/getobjectproperty.htm?id=$($Sensor.ID)&name=errorintervalsdown&username=$user&password=$pass" Try { $R = [xml]( Invoke-WebRequest -Uri $uri | Select-Object -ExpandProperty Content ) $Sensor | Add-Member -MemberType NoteProperty -Name ActionOnQueryFails -Value ($R.prtg.result) } Catch { Write-Host -Object "Could not retrieve property for sensor ID: $($Sensor.ID)" $uri $Sensor | Add-Member -MemberType NoteProperty -Name ActionOnQueryFails -Value 9 # 9 is simply not used by PRTG, but can be used to find sensors for which the HTTP request failed for some reason } }
Add comment