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

Downloading an HTTP table to an array and insert into PRTG sensor

Votes:

0

Downloading an HTTP table to an array https://community.spiceworks.com/topic/543224-downloading-an-http-table-to-an-array

HI all, I would be very grateful for your help with a script.

I have managed to get some parts of it it to work, extracting information from innerHTML, innerText, outerHTML and outerText (below) but I have trouble with presenting results and feeding this into a variable so result can be uploaded to the PRTG monitoring server.

Much appreciating your help,

Thanks!

$ie = New-Object -ComObject "InternetExplorer.Application"
#$ie.visible = $true
$ie.silent = $true
$ie.Navigate("http://download.webpage.com/webpage/test.html")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
#while ($ie.Busy) {Start-Sleep -Milliseconds 50}



Write-Warning "Retrieving information from web"
$body = $ie.Document.getElementsByTagName("table")

Write-Warning "Tables : "
$tables = $body
$tables



$tables2 = $tables | select innerText 
Write-Warning "Tables 2: "
$tables2

$RawTables = $body


Write-Verbose "Found $($RawTables.Count) tables in HTML"
$TableNum = 1

ForEach ($RawTable in $RawTables)
{   Write-Verbose "Parsing headers for Table #$TableNum"

 
 $InnerHTML = ($RawTable | select innerText).innerText -split "`n"

Write-Warning "InnerHTML: "
$InnerHTML




$Search = $InnerHTML
Write-Warning "Search: "


$Search

    $Fields = [ordered]@{}
    ForEach ($Line in $Search)
    {   ForEach ($Field in $Line.Matches)
        {   $Fields.Add($Field.Groups[1].Value,$null)
        }
    }




    Write-Warning "Parsing table data for Table #$TableNum"
    If ($Fields.Count -gt 0)
 
    {   $Search = $InnerHTML | Select-String -Pattern "<t[hd] ?.*?>(.*?)</t[hd]>" -AllMatches

Write-Warning "Search2: "
$Search
        $Row = [PSCustomObject]$Fields
        $Index = 0
        $Table = ForEach ($Match in $Search.Matches)
        {   $Field = $Fields.GetEnumerator().Name[$Index]
            $Row.$Field = ($Match.Groups[1].Value -replace "<.*?>","").Trim()
            If ($Index -eq ($Fields.Count - 1))
            {   $Index = 0
                Write-Output $Row
                $Row = [PSCustomObject]$Fields
            }
            Else
            {   $Index ++
            }
        }
        [PSCustomObject]@{
            Raw = $InnerHTML
            Data = $Table
            Fields = $Fields
        }
    }
    Else
    {   Write-Warning "Unable to determine headers for Table #$TableNum, skipping it"
    }
    $TableNum ++
}


# This code will need to be inserted as well (not finished)
# Sends results to PRTG for monitoring:

#"<prtg>"
#
#       "<result>"
#       "<channel>Javascript enabled</channel>"
#       "<value>$yesno</value>"
#       "</result>"

#       "<result>"
#       "<channel>Client IP address</channel>"
#       "<value>$clientip</value>"
#       "</result>"
#       "<text>$returndescription</text>"

#       "<result>"
#       "<channel>Real connecting IP address</channel>"
#       "<value>$realip</value>"
#       "</result>"

#       "<result>"
#       "<channel>Server IP address</channel>"
#       "<value>$serverip</value>"
#       "</result>"

#       "<text>$returndescription</text>"

#       "<result>"
#       "<channel>M_IP1</channel>"
#       "<value>$m_ip1</value>"
#       "</result>"

#       "<result>"
#       "<channel>M_IP2</channel>"
#       "<value>$m_ip2</value>"
#       "</result>"

#       "<text>$returndescription</text>"

#       "<result>"
#       "<channel>M_IP1</channel>"
#       "<value>$m_ip1</value>"
#       "</result>"

#       "<result>"
#       "<channel>IP mapp DNS mapp</channel>"
#       "<value>$imdm</value>"
#       "</result>"

#       "<text>$returndescription</text>"

#       "<result>"
#       "<channel>Serial</channel>"
#       "<value>$serial</value>"
#       "</result>"

#       "<result>"
#       "<channel>RTT Small hreq</channel>"
#       "<value>$rttsmall</value>"
#       "</result>"

#       "<result>"
#       "<channel>BW DL Small</channel>"
#       "<value>$bwdlsmalldl</value>"
#       "</result>"      

#       "<result>"
#       "<channel>BW UL Med</channel>"
#       "<value>$bwmedul</value>"
#       "</result>"

#       "<result>"
#       "<channel>BW DL Large</channel>"
#       "<value>$bwlargedl</value>"
#       "</result>"    

#       "<result>"
#       "<channel>BW UL Large</channel>"
#       "<value>$bwdllargeul</value>"
#       "</result>"  

#"</prtg>" 



[System.Runtime.Interopservices.Marshal]::ReleaseComObject($ie)
Remove-Variable ie

# End of Script

This is the innerHTML, innerText, outerHTML and outerText I retrieve the information out from.

innerHTML                    :
                                       <tbody><tr>
                                           <th>JavaScript enabled</th>
                                           <td>
                                               <script type="text/javascript">
                                               document.write('Yes');
                                               </script>Yes
                                               <noscript>No</noscript>
                                           </td>
                                           <tr>
                                               <th>Client IP address </th>
                                               <td id="clientip">11.11.11.111</td>
                                               <tr>
                                                   <th>Real connecting IP address </th>
                                                   <td id="anotherip">11.11.11.111</td>
                                                   <tr>
                                                       <th>Server IP address </th>
                                                       <td id="serverip">33.333.333.33 (machine ip = 44.444.444.44)</td>
                                                       <tr>
                                                           <th>M_IP1: </th>
                                                           <td id="mapip1">66.666.666.66</td>
                                                           <tr>
                                                               <th>M_IP2: </th>
                                                               <td id="mapip2">55.555.555.55</td>
                                                               <tr>
                                                                   <th>IP mapping matches DNS mapping: </th>
                                                                   <td id="mapping">No</td>
                                                                   <tr>
                                                                     <th>Network name: </th>
                                                                     <td id="network">Network Name</td>
                                                                     <tr>
                                                                     <th>Serial: </th>
                                                                     <td id="serial">1234</td>
                                                                     <tr>
                                                                       <th>RTT for small http request </th>
                                                                       <td id="httplatency">17 ms</td>
                                                                       <tr>
                                                                           <th>BW for DL small kbyte to browser </th>
                                                                           <td id="dlbandwidthsmall">55183.6 kbps    (HIT)</td>
                                                                           <tr>
                                                                               <th>BW for UL medium kbyte from browser </th>
                                                                               <td id="uploadbandwidthsmall">29681.1 kbps</td>
                                                                               <tr>
                                                                                   <th>BW for DL large Mbyte to browser </th>
                                                                                   <td id="dlbandwidthlarge">Calculating...</td>
                                                                                   <tr>
                                                                                       <th>BW for UL Large kbyte from browser </th>
                                                                                       <td id="ulbwxlarge">Calculating...</td>

                                   </tr></tbody>
innerText                    :
                               JavaScript enabled
                               document.write('Yes'); Yes No

                               Client IP address
                               11.11.11.111

                               Real connecting IP address
                               11.11.11.111

                               Server IP address
                               33.333.333.33 (machine ip = 44.444.444.44)

                               M_IP1:
                               66.666.666.66

                               M_IP2:
                               55.555.555.55

                              IP mapping matches DNS mapping:
                               No

                               Network name:
                               Network Name

                               Serial:
                               1234

                               RTT for small http request
                               17 ms

                               BW for download small kbyte to browser
                               1001.1 kbps (HIT)

                               BW for UL medium kbyte from browser
                               1001.1 kbps

                               BW for DL large Mbyte to browser
                               Calculating...

                               BW for UL Large kbyte from browser
                               Calculating...
outerHTML                    : <table>
                                       <tbody><tr>
                                           <th>JavaScript enabled</th>
                                           <td>
                                               <script type="text/javascript">
                                               document.write('Yes');
                                               </script>Yes
                                               <noscript>No</noscript>
                                           </td>
                                           <tr>
                                               <th>Client IP address </th>
                                               <td id="clientip">11.11.11.111</td>
                                               <tr>
                                                   <th>Real connecting IP address </th>
                                                   <td id="realip">11.11.11.111</td>
                                                   <tr>
                                                       <th>Server IP address </th>
                                                       <td id="Serverip">33.333.333.33 (machine ip = 44.444.444.44)</td>
                                                       <tr>
                                                           <th>M_IP1: </th>
                                                           <td id="mapip1">66.666.666.66</td>
                                                           <tr>
                                                               <th>M_IP2: </th>
                                                               <td id="mapip2">55.555.555.55</td>
                                                               <tr>
                                                                   <th>IP mapping matches DNS mapping: </th>
                                                                   <td id="mapping">No</td>
                                                                   <tr>
                                                                     <th>Network name: </th>
                                                                     <td id="network">Network Name</td>
                                                                     <tr>
                                                                     <th>Serial: </th>
                                                                     <td id="serial">1234</td>
                                                                     <tr>
                                                                       <th>RTT for small http request </th>
                                                                       <td id="httplatency">17 ms</td>
                                                                       <tr>
                                                                           <th>BW for DL small kbyte to browser </th>
                                                                           <td id="dlbandwidthsmall">1001.1 kbps    (HIT)</td>
                                                                           <tr>
                                                                               <th>BW for UL medium kbyte from browser </th>
                                                                               <td id="uploadbandwidthsmall">1001.1 kbps</td>
                                                                               <tr>
                                                                                   <th>BW for DL large Mbyte to browser </th>
                                                                                   <td id="dlbandwidthlarge">Calculating...</td>
                                                                                   <tr>
                                                                                       <th>BW for UL Large kbyte from browser </th>
                                                                                       <td id="ulbwxlarge">Calculating...</td>

                                   </tr></tbody></table>
outerText                    :
                               JavaScript enabled
                               document.write('Yes'); Yes No

                               Client IP address
                               11.11.11.111

                               Real connecting IP address
                               11.11.11.111

                               Server IP address
                               33.333.333.33 (machine ip = 44.444.444.44)

                               M_IP1:
                               66.666.666.66

                               M_IP2:
                               55.555.555.55

                              IP mapping matches DNS mapping:
                               No

                               Network name:
                               Network Name

                               Serial:
                               1234

                               RTT for small http request
                               17 ms

                               BW for DL small kbyte to browser
                               1001.1 kbps (HIT)

                               BW for UL medium kbyte from browser
                               1001.1 kbps

                               BW for DL large Mbyte to browser
                               Calculating...

                               BW for UL Large kbyte from browser
                               Calculating...

html powershell prtg table

Created on Nov 5, 2018 12:29:34 PM

Last change on Nov 5, 2018 7:08:24 PM by  Stephan Linke [Paessler Support]



2 Replies

Votes:

1

Hello,

Please bear in mind, as with all things customising, which includes script sensors, customizing on pages in PRTG (reports, map objects, etc.), users are on their own. This has to be done by the user. While we do have a few explanations and rough guides in our KB for that, as well as the API-Documentation, be aware, that it's only supposed to work as a base, and using it is at your own risk.

Hopefully other users can help you!

Let us know if you need anything else.

best regards.

Created on Nov 8, 2018 9:37:06 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Yes, I have had great help from you earlier, thank you and keep up the good work! J

Created on Nov 8, 2018 7:53:27 PM




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.