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

API: Parse html result after sensor creation and Invoke-WebRequest not working

Votes:

0

Hi Actually this question is related to every web query giving back an html page A silly question from a dumb powersheller ;) I'm using Powershell 4.0 Here is my query:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$url = "https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998 FIX: Uptime&targetid=63040&username=me&password=pass"

When I do:

$result = Invoke-WebRequest  $url

I have an error (since the beginning for all my functions):

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:11
+ $result = Invoke-WebRequest  $url
+           ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

I used to make it like this instead:

$wc = New-Object System.Net.WebClient
$url = "https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998 FIX: Uptime&targetid=63040&username=me&password=pass"
$result = $wc.DownloadString($url)
$html = New-Object -ComObject "HTMLFile"
$html.IHTMLDocument2_write($result)
$html.forms | % innerhtml

This last line gives back the whole form but I can't figure out how to get the new sensor id only Do you have any suggestion? Thank you upfront

api html parse parsing-data

Created on Apr 26, 2018 12:59:42 PM

Last change on Apr 26, 2018 8:32:19 PM by  Felix Saure [Paessler Support]



3 Replies

Votes:

0

Finally I found out a mean to make it without a com object from the result string I do:

$ResultId = ($Result | where {$_ -like "*sensor*"} | Select-Object -first 1) -replace ".*sensor.htm.id=(\d+)`".*",'$1'

$ResultId contains the sensor's ID

Still I am wondering why Invoke-Webrequest doesn't work

Created on Apr 27, 2018 8:48:10 AM

Last change on Apr 27, 2018 9:11:04 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hi there,

Please note that the URL might not be valid at all due to the space in between:

https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998 FIX: Uptime&targetid=63040&username=me&password=pass

Please try the following URL instead:

https://myprtg.domain.tld/api/duplicateobject.htm?id=61222&name=9998%20FIX:%20Uptime&targetid=63040&username=me&password=pass


Does that work properly?

Best regards.

Created on Apr 27, 2018 10:29:42 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Actually with my method it does work as is I already have though (and tested) removing spaces with invoke-webrequest but it does not work either Actually I have something working and I keep it

Created on Apr 27, 2018 10:39:17 AM




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.