What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Retrieve all Object Properties via the API

Votes:

0

Is it possible to retrieve all object properties, the same way we can do with: .../api/table.xml?content=sensors&columns=sensor&username=myuser&passhash=hash

The reason for the question, I am working on a project to automatically create sensors via the API when a record in another system is marked as complete and I need to compare what is currently in PRTG vs the 3rd party system (complete daily refresh as people have access to change records in PRTG).

The basic sensor GET above takes a few seconds to come back with all data (unfiltered - just a plain dump), but I have a loop after this that gets the object properties (I need host and httpurl). Calling "...api/getobjectproperty.htm?id=X&name=host&show=text" twice for each sensor object takes about 9 minutes to complete. IIS for the separate API gives up after about 8 minutes, or it gives up on memory used (2GB)

I have various other methods I can try (hangfire, IIS timeouts, stand alone calls etc...), but as PRTG can dump all the device and sensor info out so quickly, can it do the same 'dump' for object properties, even if I have to specify "&name=host" or "&name=httpurl" as 2 separate calls. 2 is a lot less than the 30,000 calls (and counting) my webmethod is currently doing against PRTG API.

Or can I get the sensor data + object properties (objid, parentid, sensorName, tags + host & httpurl) in a different way without a person being involved

Thanks

Wayne

api getobjectproperty prtg sensor

Created on Mar 10, 2018 6:30:38 PM



11 Replies

Votes:

0

You can do this with PrtgAPI via the Get-ObjectProperty cmdlet

C:\> Get-Sensor ping | Get-ObjectProperty

PingPacketSize             : 32
PingMode                   : MultiPing
PingCount                  : 5
PingDelay                  : 5
AutoAcknowledge            : False
InheritInterval            : False
Interval                   : 00:00:30
IntervalErrorMode          : OneWarningThenDown
InheritDependency          : False
Schedule                   : None
MaintenanceEnabled         : False
MaintenanceStart           : 12/03/2018 8:11:42 PM
MaintenanceEnd             : 12/03/2018 8:11:42 PM
DependencyType             : MasterObject
DependentObjectId          :
...

For properties that are not currently supported by PrtgAPI, you can use the -Raw parameter to view all properties present on the object

C:\> Get-Sensor ping | Get-ObjectProperty -Raw

name               : Ping
tags               : pingsensor
timeout            : 2
size               : 32
countmethod        : 1
count              : 5
delay              : 5
autoacknowledge    : 0
stack              : 0
stackunit          : ?raw-s4|%
intervalgroup      : 0
inherittriggers    : 1
scheduledependency : 0
maintenable        : 0
maintstart         : 2018,03,12,20,12,31
maintend           : 2018,03,12,20,12,31
...

The Get-ObjectProperty cmdlet can be used with sensors, devices, groups and probes

To create your new sensors, you can do so via the Add-Sensor or Clone-Object cmdlets

If you are doing this in C#, there are equivalent methods available to achieve the same result. If you are doing this in a language other than C# or PowerShell, you can specify -Verbose on each of these cmdlets to view the HTTP request required to perform the specified action

Regards,

lordmilko

Created on Mar 12, 2018 9:18:46 AM



Votes:

0

Just to add to this, each call to retrieve all sensor properties is one API call, so you should at least be able to reduce the amount of requests you're making by 50%

If you're doing this in IIS though it may be worthwhile abusing the corresponding async methods for improved performance

//Do some kind of filter
var sensors = await client.GetSensorsAsync(Property.Name, "HTTP");

var tasks = sensors.Select(async s => await client.GetSensorPropertiesAsync(s.Id));

var properties = await Task.WhenAll(tasks);

foreach (var prop in properties)
{
    Console.WriteLine($"{prop.Name}'s URL is {prop.Url}");
}

Depending on the number of sensors you're querying it may be worth staging the number of tasks you await at once

Created on Mar 12, 2018 9:56:12 AM



Votes:

0

Thanks LordMilko

Does this work by pulling out all the IDs based on tag, then do a loop of getting all the individual IDs properties.

foreach (var prop in RawProperty) { var val = client.GetObjectPropertyRaw(Object.Id, prop); obj.Properties.Add(new PSNoteProperty(prop.ToLower().Replace("_", ""), val)); }

If so, I'll still have 30,000 calls (2 x 15k in my code), just hidden behind 2 single powershell/C# calls. Its the 30k worth of API calls to PRTG I'm trying to avoid as that's the part that takes the 8-9 minutes

Created on Mar 12, 2018 10:44:18 AM



Votes:

0

Retrieving all sensors based on some combination of filters (IDs, tags, names, types, etc) is a single API call, and then retrieving each sensor's properties requires an individual API call

However, if you're just after the URL of a HTTP sensor and the Host of a sensor's device, this can be achieved in 15,002 API calls, as you can retrieve all of the devices for all of your sensors in a single request (each of which will contain its Host)

//Get some sensors (one request)
var sensors = client.GetSensors();

//Get the properties of each sensor (sensors.Count requests)
var properties = sensors.Select(s => client.GetSensorProperties(s.Id));

//Get all the devices of all the sensors (one request)
var devices = client.GetDevices(Property.ParentId, sensors.Select(s => s.ParentId).ToArray());

You can then identify the Host that belongs to each sensor by cross referencing the Id of a device with the ParentId of a sensor

Note: obviously you should only use C# if you're developing your program in that language; there is no need to mess around with PowerShell stuff in System.Management.Automation

Created on Mar 12, 2018 11:04:23 AM

Last change on Mar 12, 2018 11:04:23 AM



Votes:

0

(Apologies, client.GetDevices should use Property.Id, not Property.ParentId)

Created on Mar 12, 2018 11:40:39 AM



Votes:

0

Thanks.

If its not possible to dump all the custom sensor data out via one or two calls like with the device data, I may have to make the API call after I've inserted the data from the database instead, which can be outside of the API call (so out of my timeout issue).

The company want to at least triple their hosted customer base in the next few years. This doesn't increase the calls by 3, but you can see where I'm going with this. I'm going to hit the same problem timeout again in a few years as the 15k I could run now would increase.

I think Paessler support review the forum; how could I request this as a possible future enhancement

Very nice project BTW Lordmilko

Created on Mar 12, 2018 12:14:57 PM



Votes:

0

Just to confirm, you have 15,000 HTTP sensors on your PRTG Server? And in 3 years you'll be running 45,000 HTTP sensors? Is that the only type of sensor your server runs?

You can of course abuse the async methods to do batches of say 50 requests simultaneously; in combination with using GetDevicesAsync for retrieving the Host for all properties I'd say at present you can probably get this down to 3-4 minutes, but obviously it's never going to be as good as doing a single request that retrieves properties for multiple objects.

Created on Mar 12, 2018 12:41:22 PM



Votes:

0

No, there's other devices & types of sensors & data from the sensors I need to pull. These 2 types are my sticking point at the moment, before I add anything else in. I didn't want to muddy the waters by going into all the detail on what I'm trying to do

Thanks for your help and guidance with this

Created on Mar 12, 2018 1:12:19 PM



Votes:

0

Since the initial stated goal is simply "to see what people might have changed changed", instead of requesting the properties of each individual sensor, I think a better idea may be to inspect the Logs of all sensors to see which objects have actually changed, and then based on that retrieve those properties to inspect the new values

//Get all events indicating an object was modified
//A null object ID is equivalent to the Root group with ID 0
var logs = client.GetLogs(null, null, DateTime.Now.AddDays(-1), 50000, LogStatus.Edited);

//Identify all objects that were modified
var modifiedIds = logs.Select(i => i.Id).Distinct();

//Filter our sensors to those that were modified
var modifiedSensors = sensors.Where(s => modifiedIds.Contains(s)).ToList()

//Retrieve the properties of only the ones that were modified
var modifiedProperties = modifiedSensors.Select(s => s.GetSensorProperties());

If only one sensor was modified, you only need to call GetSensorProperties once. This should dramatically reduce the number of requests that need to be made

Created on Mar 12, 2018 1:49:17 PM



Votes:

0

@loadmilko what's the api call (url) to get all the get all the objects properties, that your code calls?

Created on Aug 7, 2018 3:27:48 PM



Votes:

1

Hi @netops-MM,

PrtgAPI executes the request

https://<server>/controls/objectdata.htm?id=<id>&objecttype=sensor&username=<username>&passhash=<passhash>

And then uses regular expressions to construct an object model that eventually allows us to create a set of key/value pairs representing each setting and its associated value

Regards,

lordmilko

Created on Aug 7, 2018 9:32:10 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.