Closed abatie closed 5 years ago
Hi @abatie,
If you have access to PowerShell on any other machine, the best strategy to figure out how to any particular API call works is to invoke the PrtgAPI cmdlet that performs the desired operation with the -Verbose
parameter. Otherwise, you can try and perform the operation you're after in the PRTG UI while running Fiddler, then inspect the actual API call that was made so you can execute it yourself.
PrtgAPI modifies the aggregation channel using the following API call
http://prtg.example.com/editsettings?id=2079&aggregationchannel_=%231%3AChannel1%0D%0Achannel(2059%2C1)&username=prtgadmin&passhash=12345678
editsettings
is the API endpoint PRTG uses internally; PrtgAPI tends to use this over the publically documented /api/setobjectproperty.htm
endpoint as editsettings
properly supports all object properties, and provides the flexibility to modify multiple properties at once (important when a property depends on another property being set alongside it).
Also note the trailing underscore on the property name; all properties (excluding "inheritance enabled/disabled" type properties) specified to editsettings
should generally end in an underscore.
Are you able to advise whether this worked successfully?
Regards, lordmilko
Hi @abatie,
As I've answered your question and haven't heard a response back from you I am closing this issue.
Please let me know if you have any further issues
Regards, lordmilko
Sorry, I saw you'd labeled it a question, but the answer didn't show for some reason.
When I do this, I get a redirect and it doesn't update the aggregation channel:
Redirect: 'location' => '/device.htm?id=10036'
After decoding your URL I got the channel definition
#1:Iostat
Channel(29089,0)
#2:Active Connections
Channel(41743,0)
As your channel definition contains sensors not present on my PRTG server, I replaced these sensor IDs with sensors that do exist in my server, and was successfully able to execute the following request with PrtgAPI
http://prtg.example.com/editsettings?id=2079&aggregationchannel_=%231%3AIostat%0AChannel(2056%2C0)%0A%232%3AActive+Connections%0AChannel(2056%2C0)&username=prtgadmin&passhash=12345678
Substituting my sensor IDs for yours and comparing them, we can see your URL is not the same as mine
%231%3AIostat%0AChannel(29089%2C0)%0A%232%3AActive%20Connections%0AChannel(41743%2C0)%0A
%231%3AIostat%0AChannel(29089%2C0)%0A%232%3AActive+Connections%0AChannel(41743%2C0)
There are two differences between these URLs
+
Can you try resolving these two issues and seeing whether your API call works? If it still doesn't work, you may want to check whether you can add this channel definition using the PRTG UI.
Well, I'm stupid - I had a bug and it was using the wrong sensor ID. It's working (with the %20 even), sorry about that and thanks a lot for your help!
I was pointed at this project by Paessler as apparently they don't actually support some of the features of the API, namely Sensor Factory sensor settings. I'm using Perl on Linux to access the API, so can't use your code directly, but was able to tease out the property name "aggregationchannel" that I want to edit, but while I can read the value, setting the value seems to be ignored. As near as I can tell from the code (I'm afraid object oriented code is a very effective obfuscation technique for me in trying to figure out what's really happening ;-) ), setting the value should work, so I'm wondering if you had to do anything other than just call setobjectproperty to get updates to this property to work?
http://prtghost/api/setobjectproperty.htm?username=xxx&password=yyy&id=10036&name=aggregationchannel&value=#1:Iostat%0AChannel(29089,0)%0A#2:Active%20Connections%0AChannel(41743,0)