-
-
Notifications
You must be signed in to change notification settings - Fork 38
Other Objects
PrtgAPI is capable of manipulating any object stored by PRTG. This extends far beyond typical objects such as Sensors, Devices and Groups, covering items 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!
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 :(");
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
...
By piping multiple instances of Get-Object
together you can explore the PRTG Object Tree
Get-Object | Get-Object | Get-Object | Get-Object
Using this technique it is also possible to explore the relationship between System objects and their children
# Retrieve all children of the Notifications object
C:\> Get-Object -Id -3 | Get-Object
Name Id Type
---- -- ----
Email and push notification to admin 300 Notification
Email to all members of group PRTG Users Group 301 Notification
Ticket Notification 302 Notification
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
When searching by -Type
, please note that not all object types may support filtering server side
# No problem
C:\> Get-Object -Type System,Device
# Does not work; use Where-Object to filter client side instead
C:\> Get-Object -Type ActiveDirectoryUserOrGroup
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...}