lordmilko / PrtgAPI

C#/PowerShell interface for PRTG Network Monitor
MIT License
301 stars 37 forks source link

How to pull Service URL from devices #302

Closed kadayvis closed 2 years ago

kadayvis commented 2 years ago

What's going on?

Hello, We love your project, everything works great and it's extremely impressive, but we are trying to figure out how to extract the Service URL for a device making direct API requests. We know your API can do it, and we've tested it successfully, but when we try to extract it as a field in a direct API call it comes back blank. How exactly are you achieving this?

Thank you!

Due Dilligance

lordmilko commented 2 years ago

Hi @kadayvis,

I am assuming you are referring to the Service URL as displayed in the settings of the object?

image

The way PrtgAPI retrieves this depends on the API call you are making

When you do Get-ObjectProperty with no parameters PrtgAPI scrapes the /controls/objectdata.htm page (which is a page whose contents is embedded in the output seen when clicking the Settings tab) and then parses the HTML to extract all input fields/dropdown lists, etc to present in a nice neat format to the user.

By default, Get-ObjectProperty will wrap its output up in a nice type safe object that declares a number of commonly used properties, however by doing Get-ObjectProperty -Raw it is possible to see all properties on the Settings page - including the raw names of each setting

By doing this we can see that the name of the Service URL field is simply serviceurl, and as such we can retrieve this property directly by doing /api/getobjectproperty.htm?id=2055&name=serviceurl

C:\> get-device ci*|Get-ObjectProperty -RawProperty serviceurl -verbose
VERBOSE: Get-ObjectProperty: Synchronously executing request
http://ci-prtg-1/api/getobjectproperty.htm?id=2055&name=serviceurl&username=prtgadmin&passhash=123456789

http://ci-prtg-1

You can view all API calls any PrtgAPI cmdlet makes by specifying the -Verbose parameter

kadayvis commented 2 years ago

Thank you for such a thorough answer, this is exactly what I needed! Also thank you for picking up (a lot) of Paessler's slack on the usefulness of their API and PRTG as a whole, their new update can't come soon enough!

Have a great weekend!