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

Monitor URL that doesn't have html or xml tags

Votes:

0

Hi all!

So I'm looking for a way to monitor a URL that returns value(s) but not in any well formed xml or html tags. Some example returns are like just the number 5 or strings like

Load=5262 Conns=6641 Mbps=36.9

for Forcepoint health monitoring. I know I can parse these URLs with PowerShell by InvokeWebRequest but I'm not great with scripting or programming so any help would be appreciated.

I'd like to parse the values and define thresholds that throw an alarm if they go over a certain value or below.

Hope I could explain understandably as English is not my first language.

Best regards M

http parse url

Created on Apr 12, 2018 7:03:58 AM



Best Answer

Accepted Answer

Votes:

3

Here an example if you would like to get the bold part from your example

Load=5262 Conns=6641 Mbps=36.9

# initialize the webclient
$webclient = New-Object Net.WebClient
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

# download the page
$urlDownload = $webclient.DownloadString('http://thisisanexample/lalelu.html')

$cutAfter = ($urlDownload -split 'Conns=')[1]

$cutBefore = ($filterTwice -split ' Mbps=')[0]

Write-Host "<?xml version="1.0" encoding="UTF-8" ?>"
Write-Host "<prtg>"
Write-Host "<result>"
Write-Host "<channel>Conns</channel>"
Write-Host "<value>$filterTwice</value>"
Write-Host "<Unit>Custom</Unit>"
Write-Host "<CustomUnit>Conns</CustomUnit>"
Write-Host "</result>" 
Write-Host "</prtg>"

For more information check here: https://prtg.paessler.com/api.htm?tabid=7 Login Name: demo Password: demodemo

In my example I first split the website output at Conns= taking the second part and then split the result again at 'space'Mbps= taking the first part of the result leaving me behind with the value 6641. (at least in theory...) You could also do something like "get the next 4 characters after expression Conns=". I would have to google that myself tho...

Hope this helps..

Created on Apr 13, 2018 10:51:55 AM



4 Replies

Votes:

0

Hi there,

I'm afraid that if the sensors does not offer an XML/REST API, there is no way around a script to parse these values into proper XML which is readable for PRTG. As our support does not cover custom scripting, maybe another customer can assist you here. The XML needs to look like this for PRTG:

            <prtg>
            <result>
            <channel>First channel</channel>
            <value>10</value>
            </result>
            <result>
            <channel>Second channel</channel>
            <value>20</value>
            </result>
            </prtg>

Best regards, Felix

Created on Apr 13, 2018 10:33:26 AM by  Felix Saure [Paessler Support]



Accepted Answer

Votes:

3

Here an example if you would like to get the bold part from your example

Load=5262 Conns=6641 Mbps=36.9

# initialize the webclient
$webclient = New-Object Net.WebClient
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

# download the page
$urlDownload = $webclient.DownloadString('http://thisisanexample/lalelu.html')

$cutAfter = ($urlDownload -split 'Conns=')[1]

$cutBefore = ($filterTwice -split ' Mbps=')[0]

Write-Host "<?xml version="1.0" encoding="UTF-8" ?>"
Write-Host "<prtg>"
Write-Host "<result>"
Write-Host "<channel>Conns</channel>"
Write-Host "<value>$filterTwice</value>"
Write-Host "<Unit>Custom</Unit>"
Write-Host "<CustomUnit>Conns</CustomUnit>"
Write-Host "</result>" 
Write-Host "</prtg>"

For more information check here: https://prtg.paessler.com/api.htm?tabid=7 Login Name: demo Password: demodemo

In my example I first split the website output at Conns= taking the second part and then split the result again at 'space'Mbps= taking the first part of the result leaving me behind with the value 6641. (at least in theory...) You could also do something like "get the next 4 characters after expression Conns=". I would have to google that myself tho...

Hope this helps..

Created on Apr 13, 2018 10:51:55 AM



Votes:

0

Thanks for sharing this Lukas!

Best regards, Felix

Created on Apr 13, 2018 11:06:17 AM by  Felix Saure [Paessler Support]



Votes:

0

We were able to solve this by using Lukas' suggestion! Thank you very much!!

Created on Apr 19, 2018 6:26:10 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.