Here is the script to get data from ookla. Script is running speedtest cli version and generates xml output with four channels as one sensor. You will get Download, Upload, ping and distance to server.
All you need is to get speedtest installed from: https://www.speedtest.net/pl/apps/cli
function Get-Data { $result = speedtest --csv --bytes return $result } function Parse-Data { param( [string]$DataString ) $csvheader = @('Server ID','Sponsor','Server Name','Timestamp','Distance','Ping','Download','Upload','Share','IP Address') $csvunits = @('','','','','km','ms','Mbit/s','Mbit/s','','') # $DataString = $result $ValueArray = $DataString.split(',') $ValueArray[4] = ([math]::Round(([double]($ValueArray[4]) / 1))).tostring() $ValueArray[5] = ([math]::Round(([double]($ValueArray[5]) / 1))).tostring() $ValueArray[6] = ([math]::Round(([double]($ValueArray[6]) / 1000000))).tostring() $ValueArray[7] = ([math]::Round(([double]($ValueArray[7]) / 1000000))).tostring() if (($csvheader.count) -eq ($ValueArray.count)) {$max = $csvheader.count} $result = for ($i = 0; $i -lt $max; $i++) { if ($csvunits[$i]) { [PSCustomObject]@{ channel = $csvheader[$i] value = $ValueArray[$i] unit = $csvunits[$i] } } } Return $result } function Get-XML { param( $Table ) $prtg = '<?xml version="1.0" encoding="Windows-1252" ?> <prtg>' #$prtg = '<prtg>' foreach ($row in $Table) { $channel = $row.channel $value = $row.value $unit = $row.unit if ($value.Contains('.')) {$float = 1} else {$float = 0} if ($channel) { $prtg +=" <result> <channel>$channel</channel> <value>$value</value> <unit>Custom</unit> <customUnit>$unit</customUnit> <float>$float</float> </result>" } } $prtg +="</prtg>" return $prtg } $Speedtest_csv = Get-Data $Table = Parse-Data $Speedtest_csv [xml]$xml = Get-XML $Table write-host ($xml.innerxml)
Add comment