I have a device that provides data via an html page. I'm trying to setup the HTML Content sensor to grab the value data and report. However it's only provided in a table format, see below, this format cannot be changed. Also this page is refreshed on a 1-2 minute interval.

<tr>
  <td width="200" class="tblL">Downlink RF Power (dBm)</td>
  <td width="400" class="tblR">-37.1</td>
</tr>

Any ideas how I can make this work in PRTG, without too much coding if possible?

Thanks


Article Comments

Hi there,

I'm afraid that the native HTML sensors will not be capable of extracting values from HTML tables, so this will need to be done with a custom script. As a kickoff, I found this article which describes a Powershell script. Please do also have a look at the API documentation Setup > PRTG API > Custom Sensors for the correct syntax.

Best regards, Felix


Oct, 2015 - Permalink

Hi,

I'm still having issue with getting the custom sensor to work. I have a batch file that opens the target page to grab the data from, then writes this data to a file. I assume this data now needs to be converted into the prtg xml format so I can pull the data. Is this correct? If so is there an easier way than writing a custom exe file to accomplish this task? Setting up custom sensors could really be much easier than it is right now.

Thanks,

Stuart


Oct, 2015 - Permalink

Hi,
I'm afraid there is no other way than using a script to parse the HTML. However, there is no need to save a file, you should be able to work with the HTML directly (e.g. in Powershell). Below you will find example code which reads the html and accesses a value:

ry{
    $page = Invoke-WebRequest -Uri ("{0}" -f $url)
}
Catch{
    Write-Host "0:An Error occured"
    Exit(2)
}
$data = $($page.ParsedHtml.getElementsByTagName("td"))
# Uncomment to see all elements
#foreach ($element in $data){
#    Write-Host $element.innerHTML
#}
#Write-Host $data[11].innerText.ToString()
# Some debugging and adjusting has to be done here
Write-Host ("{0}:{1}" -f $data[12].innerText.ToString(), $data[11].innerText.ToString())
Exit(0)

This snippet has an output which already can handled by PRTG's EXE/Script Sensor but you will have to adjust the parsing logic to suit your needs.


Nov, 2015 - Permalink