What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How to get the preferred action for when a sensor query fails?

Votes:

1

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
	}

}

api query sensor

Created on Oct 26, 2018 9:24:22 AM

Last change on Oct 26, 2018 11:16:13 AM by  Dariusz Gorka [Paessler Support]



Best Answer

Accepted Answer

Votes:

1

Hi Roderick,

For reference, PrtgAPI *does* allow you to retrieve this property, however in order to do so you need to use the Get-ObjectProperty cmdlet

C:\> Get-Sensor -count 1 | Get-ObjectProperty | select *interval*

InheritInterval Interval  IntervalErrorMode
--------------- --------  -----------------
           True 00:01:00 OneWarningThenDown

PrtgAPI also allows retrieving properties not currently supported via the -RawProperty and -Raw parameters of Get-ObjectProperty. For more information on retrieving object properties, see the wiki|

Regards,

lordmilko

Created on Oct 26, 2018 12:04:21 PM



2 Replies

Votes:

0

Hi Roderick,

Thanks for sharing your solution! I just changed the layout a bit so other users can read it a bit better. :)

Best regards.

Created on Oct 26, 2018 11:16:43 AM by  Dariusz Gorka [Paessler Support]



Accepted Answer

Votes:

1

Hi Roderick,

For reference, PrtgAPI *does* allow you to retrieve this property, however in order to do so you need to use the Get-ObjectProperty cmdlet

C:\> Get-Sensor -count 1 | Get-ObjectProperty | select *interval*

InheritInterval Interval  IntervalErrorMode
--------------- --------  -----------------
           True 00:01:00 OneWarningThenDown

PrtgAPI also allows retrieving properties not currently supported via the -RawProperty and -Raw parameters of Get-ObjectProperty. For more information on retrieving object properties, see the wiki|

Regards,

lordmilko

Created on Oct 26, 2018 12:04:21 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.