Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Using POST For Big Queries #80

Open
JustinGrote opened this issue May 16, 2019 · 1 comment
Open

Allow Using POST For Big Queries #80

JustinGrote opened this issue May 16, 2019 · 1 comment
Labels
enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release

Comments

@JustinGrote
Copy link

 $r = get-sensor -id $id[1..890]
'Get-Sensor' timed out: The underlying connection was closed: The connection was closed unexpectedly. Retries remaining: 1
The underlying connection was closed: The connection was closed unexpectedly.
At line:1 char:6
+ $r = get-sensor -id $id[1..890]
+      ~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-Sensor], WebException
    + FullyQualifiedErrorId : System.Net.WebException,PrtgAPI.PowerShell.Cmdlets.GetSensor

I suspect this is due to the query being a GET, and the GET URL is hitting the limit. Doing it as a URLBody POST might resolve. Alternatively, have a -BatchSize parameter or something to break into multiple queries on that size.

@lordmilko lordmilko added the enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release label May 17, 2019
@lordmilko
Copy link
Owner

Hi @JustinGrote,

You are exactly right, this is the issue. I am already aware of the limitations of executing large requests, and have already taken steps to work around them when executing certain known requests (such as specifying a large number of objects to Pause-Object or specifying a large number of values for a particular parameter (such as the services of a new WMI Service object)), however the correct response is in fact to utilize POST instead of GET.

However, upon attempting to implement this recently as part of #59 I discovered that in fact most API requests do not work properly when using POST. If I recall correctly this is due to the fact we are attempting to authenticate via our manually specified username and passhash, rather than using a stored cookie. Hacks to split the request so that the username and passhash are specified in the URL and the rest is specified int he body did not go over well. I don't believe we want to be using a cookie everywhere, as then we have to deal with issues like what to do when it expires and how to renew it, etc.

What really needs to be done in lieu of proper support for extremely large queries is catch the fact the maximum allowed length has been exceeded, and display a more descriptive error message stating that was the fact. This is not something you are going to get a nice parameter for to workaround, as you can max out the URL length using a wide variety of values in all sorts of scenarios that can't necessarily be coherently split into multiple requests.

@lordmilko lordmilko changed the title Get-Sensor Fails if more than 890 items passed to -id Allow Using POST For Big Queries Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Items that are on the todo list for incorporating into PrtgAPI in a future release
Projects
None yet
Development

No branches or pull requests

2 participants