Skip to content

Other Objects

lordmilko edited this page Aug 25, 2018 · 10 revisions

Contents

Note: This article describes a feature that is currently in development

PrtgAPI is capable of manipulating any object stored by PRTG. This extends far beyond typical objects such as Sensors, Devices and Groups, covering nodes such as web server options, libraries and system nodes.

Using PrtgAPI's interfaces for retrieving and modifying raw properties, it is possible to write applications capable of remotely toggling insane options like whether the PRTG web server should use SSL then forcing a restart of your PRTG Core Service!

C#

Uniquely identifiable objects present on a PRTG Server can be retrieved via the GetObjects method

var objects = client.GetObjects();

Objects returned from the GetObjects method are always of type PrtgObject. The PRTG object type of a given PrtgObject can be identified via the Type property.

var sensors = client.GetObjects().Where(o => o.Type == ObjectType.Sensor);

The Type property acts as a hybrid string/enum. Object types known to PrtgAPI are modeled by the ObjectType enum. If an object is returned of an object type not currently known to PrtgAPI, it is possible to treat the Type object as being a string.

objs = client.GetObjects().Where(o => o.Type == "customobj");

A single object with a specified ID can be retrieved via the GetObject method

var obj = client.GetObject(1001);

If an object with the specified ID does not exist, an InvalidOperationException will be thrown.

When retrieving single objects, a resolve parameter can optionally specified. When true, GetObject will automatically resolve the returned object to its most derived type (Sensor, Device, Schedule, etc) if possible.

var sensor = client.GetObject(1001, true);

if (sensor is Sensor)
    Console.WriteLine($"It's the {sensor.Name} sensor!");
else
    Console.WriteLine($"Turns out it was a {sensor.Type}, not a sensor :(");

PowerShell

Uniquely identifiable objects present on a PRTG Server can be retrieved via the Get-Object cmdlet

C:\> Get-Object

Name                      Id   Type
----                      --   ----
Notifications             -3   System
User Groups               -2   System
Users                     -1   System
Root                      0    Group
Local Probe               1    Probe
...

Objects returned from the Get-Object method are always of type PrtgObject. The type of a given PrtgObject can be identified via the Type property. Type stores both the ObjectType enum value and raw type that was returned from the server. Some types, such as sensors, may include a raw type that is more descriptive than their pure type

C:\> (Get-Object -Id 2256).Type

Value  StringValue
-----  -----------
Sensor ping

Objects can be automatically resolved to their most derived PrtgObject type by specifying the -Resolve parameter

C:\> Get-Object -Id 2254

Name Id   Type
---- --   ----
Ping 2254 Sensor

C:\> Get-Object -Id 2254 -Resolve

Name            Id      Device     Group          Probe               Status
----            --      ------     -----          -----               ------
Ping            2056    dc-1       Servers        Local Probe         Up

Objects that cannot be resolved will simply be returned as their original PrtgObject type

C:\> Get-Object -Resolve | group type | foreach { $_ | Add-Member Type $_.group[0].GetType().Name -passthru } | select name,type,group | sort type

Name             Type               Group
----             ----               -----
Device           Device             {Probe Device, dc-1, exch-1}
Group            Group              {Root, Clients, Servers}
Notification     NotificationAction {Email and push notification to admin, Email to all...
Probe            Probe              {Local Probe}
WebServerOptions PrtgObject         {}
Report           PrtgObject         {Summary report for all sensors, Top 100 Uptime/Dow...
Map              PrtgObject         {Magic Map}
PrtgUserOrGroup  PrtgObject         {PRTG System Administrator, PRTG Administrators, PRTG...}
System           PrtgObject         {Users, User Groups, Notifications, Reports...}
Library          PrtgObject         {Alarms, Up and running, Paused or unknown, SNMP...}
Schedule         Schedule           {Weekdays [GMT+0800], Weekends [GMT+0800], Sundays [GMT...
Sensor           Sensor             {System Health, Core Health, Probe Health, Disk Free...}

See Also

Clone this wiki locally