Skip to content
lordmilko edited this page Oct 14, 2017 · 18 revisions

C#

Groups can be retrieved from a PRTG Server via the GetGroups method

var groups = client.GetGroups();

If you wish to filter for groups that meet certain search criteria you can specify a Property to filter on using one of several overloads

//Get groups whose name match "Servers"
var groups = client.GetGroups(Property.Name, "Servers");
//Get groups under probes whose name contains "office"
var groups = client.GetGroups(Property.Probe, FilterOperator.Contains, "office");

Filters are implemented internally via the SearchFilter class. One or more SearchFilter objects can be specified to filter on multiple properties.

//Get all groups with more than 10 sensors under probes whose name contains "office"
var filters = new[]
{
    new SearchFilter(Property.TotalSensors, FilterOperator.GreaterThan, 10),
    new SearchFilter(Property.Probe, FilterOperator.Contains, "office")
};

var groups = client.GetGroups(filters);

GetGroups can be used in conjunction with other methods in order to chain results together.

//Get all sensors for all groups whose name contains "infrastructure"
var sensors = client.GetGroups(Property.Name, FilterOperator.Contains, "infrastructure").SelectMany(
    group => client.GetSensors(Property.ParentId, group.Id)
);

When chaining results, consider whether your results could be acquired quicker by constructing an array of filters containing the criteria you are after; i.e. you do not need to ask for probes before groups if you know the name of the probe you'd like to find groups under.

PowerShell

Groups can be retrieved with PowerShell via the Get-Group cmdlet. (Note: for complete instructions on using Get-Group, please see Get-Help Get-Group)

C:\> Get-Group

Name                Id      Status      Probe          Devices    Up        Down  Down   Warning  Paused
                                                                  Sensors         (Ack)
----                --      ------      -----          -------    --------  ----  -----  -------  ------
Root                0       Up                         11         20        10    2      3        100
Servers             2070    Up          Local Probe    8          14        8     0      1        80

PrtgAPI automatically formats Groups objects in a table, displaying the most relevant properties. To view all properties of groups, pipe your groups to Format-List

Get all groups named "Servers" (case insensitive)

C:\> Get-Group servers

Name                Id      Status      Probe          Devices    Up        Down  Down   Warning  Paused
                                                                  Sensors         (Ack)
----                --      ------      -----          -------    --------  ----  -----  -------  ------
Servers             2070    Up          Local Probe    8          14        8     0      1        80

Wildcards can also be used

Get-Device *serv*,*roo*

Get-Group can filter on a number of properties, including Id, Tags

C:\> Get-Device -Id 0,2197

Name                Id      Status        Probe          Devices    Up        Down  Down   Warning  Paused
                                                                    Sensors         (Ack)
----                --      ------        -----          -------    --------  ----  -----  -------  ------
Root                0       Up                           11         20        10    2      3        100
Servers             2070    PausedByUser  Local Probe    8          14        8     0      1        80
# Get all groups containing the C_OS_VMware tag
Get-Device -Tags C_OS_VMware

Get-Group accepts both Group and Probe objects via the pipeline. When an object is piped to Get-Group, the object is used as a filter in conjunction with any other filters that may be specified

Get-Probe micro* | Get-Group
Get-Group | Select -First 1 | Get-Group *serv*

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

flt totalsensors greaterthan 10 | Get-Group

For more information on New-SearchFilter see Filters

Group objects can also be used as the input to cmdlets (including cmdlets retrieving sensors and manipulating state). For more information see the See Also section below.

See Also

Clone this wiki locally