-
-
Notifications
You must be signed in to change notification settings - Fork 38
Probes
Probes can be retrieved from a PRTG Server via the GetProbes
method
var probes = client.GetProbes();
If you wish to filter for probes that meet certain search criteria you can specify a Property
to filter on using one of several overloads
//Get probes whose name match "Contoso (Head Office)"
var groups = client.GetProbes(Property.Name, "Contoso (Head Office)");
//Get probes containing more than 20 devices
var groups = client.GetProbes(Property.TotalDevices, FilterOperator.GreaterThan, 20);
Queries can also be specified via LINQ style query expressions, allowing high performance queries to be executed via dynamically generated request parameters.
var names = client.QueryProbes(s => s.Name == "Contoso")
.Select(s => s.Name)
.Take(20);
For more information on using LINQ style queries, see Queries.
When retrieving a particular probe you insist should exist, it is possible to use the singular GetProbe
method, returning a single Probe
rather than a List<Probe>
as with GetProbes
.
var probe = client.GetProbe(1234);
If a probe with the specified object ID cannot be found (or somehow multiple objects were found) GetProbe
will throw an InvalidOperationException
. If you are not sure whether a probe exists, you should use GetProbes
instead and check for the presence of any results.
var probe = client.GetProbes(Property.Id, 1234).FirstOrDefault();
if (probe != null)
Console.WriteLine($"Found probe {probe}!");
Filters are implemented internally via the SearchFilter
class. One or more SearchFilter
objects can be specified to filter on multiple properties.
//Get all probes with more than 10 sensors under probes whose name contains "office"
var filters = new[]
{
new SearchFilter(Property.TotalSensors, FilterOperator.GreaterThan, 10),
new SearchFilter(Property.Name, FilterOperator.Contains, "office")
};
var probes = client.GetProbes(filters);
GetProbes
can be used in conjunction with other methods in order to chain results together.
//Get all sensors for all probes whose name contains "office"
var sensors = client.GetProbes(Property.Name, FilterOperator.Contains, "office").SelectMany(
probe => client.GetSensors(Property.Probe, probe.Name)
);
Depending on your goal however, it may be faster to skip retrieving parent objects and target the child objects immediately.
//Get all sensors for all probes whose name contains "office"
var sensors = client.GetSensors(Property.Probe, FilterOperator.Contains, "office");
Probes can be retrieved with PowerShell via the Get-Probe
cmdlet. (Note: for complete instructions on using Get-Probe
, please see Get-Help Get-Probe
)
C:\> Get-Probe
Name Id ProbeStatus Devices Groups Up Down Down Warning Paused
Sensors (Ack)
---- -- ----------- ------- ------ ------- ---- ----- ------- ------
Local Probe 1 Connected 30 3 11 20 10 2 100
Contoso (New York) 2001 Connected 20 2 30 2 3 1 0
PrtgAPI automatically formats Probe
objects in a table, displaying the most relevant properties. To view all properties of probes, pipe your probesto Format-List
Get all probesnamed "Local Probe" (case insensitive)
C:\> Get-Probe "local probe"
Name Id ProbeStatus Devices Groups Up Down Down Warning Paused
Sensors (Ack)
---- -- ----------- ------- ------ ------- ---- ----- ------- ------
Local Probe 1 Connected 30 3 11 20 10 2 100
Wildcards can also be used
Get-Probe *local*,*conto*
Get-Probe
can filter on a number of properties, including Id
, Tags
and ProbeStatus
C:\> Get-Probe -Id 0,2001 -ProbeStatus Connected
Name Id ProbeStatus Devices Groups Up Down Down Warning Paused
Sensors (Ack)
---- -- ----------- ------- ------ ------- ---- ----- ------- ------
Local Probe 1 Connected 30 3 11 20 10 2 100
Contoso (New York) 2001 Connected 20 2 30 2 3 1 0
# Get all probes containing the Remote_Branch tag
Get-Probe -Tags Remote_Branch
When filtering by tags, PrtgAPI provides two parameters that can be used
-
-Tags
: Filter for objects that contain all specified tags -
-Tag
: Filter for objects that contain any specified tags
# Get all probes in Manhattan, New York
Get-Probe -Tags ny,manhattan
# Get all Manhattan and Queens probes
Get-Probe -Tag manhattan,queens
Get-Probe
can be used as the input to Get-Sensor
, Get-Device
and Get-Group
cmdlets, allowing you to easily filter based on a set of specified criteria
# Get all sensors under all probes containing "contoso"
Get-Probe *contoso* | Get-Sensor
For probe properties that are not explicitly defined as parameters on Get-Probe
, these properties can still can be specified as dynamic parameters
# Get all devices that are the first or second object under their parent
Get-Probe -Position 1,2
To filter by custom fields the New-SearchFilter
cmdlet can be used (alias: flt
)
flt totalsensors greaterthan 10 | Get-Probe
For more information on New-SearchFilter
see Filters