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
Article Comments
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..
Apr, 2018 - Permalink
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
Apr, 2018 - Permalink