Skip to content
lordmilko edited this page Mar 10, 2018 · 21 revisions

Contents

C#

Basic Requests

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);

Advanced Filtering

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");

PowerShell

Basic Requests

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    Condition  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 Probes 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    Condition  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

C:\> Get-Probe -Id 0,2001

Name               Id    Condition  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

Advanced Filtering

To filter by custom fields the New-SearchFilter cmdlet must be used (alias: flt)

flt totalsensors greaterthan 10 | Get-Probe

For more information on New-SearchFilter see Filters

See Also

Clone this wiki locally