How can I get the Top 100 Uptime report to come out as a csv file instead of a pdf?


Article Comments

Attention: This article is a record of a conversation with the Paessler support team. The information in this conversation is not updated to preserve the historical record. As a result, some of the information or recommendations in this conversation might be out of date.

Unfortunately, it's not possible to create CSV reports for those, as they lack the necessary data files.


Kind regards,
Stephan Linke, Tech Support Team


May, 2018 - Permalink

I guess I must to do something like this:

$date = Get-Date
$day = $date.DayOfWeek

switch($day)
{
    "Monday" { $dateModifier = -1 }
    "Tuesday" { $dateModifier = -2 }
    "Wednesday" { $dateModifier = -3 }
    "Thursday" { $dateModifier = -4 }
    "Friday" { $dateModifier = -5 }
    "Saturday" { $dateModifier = -6 }
    "Sunday" { $dateModifier = -7 }
}

[datetime]$previousSunday = (Get-Date).AddDays($dateModifier)

$endstring = "$($previousSunday.Year)-$($previousSunday.Month)-$($previousSunday.Day)-23-59-00"

$startstring = "$($previousSunday.AddDays(-7).Year)-$($previousSunday.AddDays(-7).Month)-$($previousSunday.AddDays(-7).Day)-00-00-00"

$url = "https://myprtg/api/genreport.htm?id=93216&repstart=$startstring&repend=$endstring&$auth"
Write-Host -ForegroundColor Cyan "VERBOSE: $url"
$request = Invoke-WebRequest -Uri $url -MaximumRedirection 0 -ErrorAction Ignore
$elements = $request.ParsedHtml.getElementsByTagName("td")

$items = @()
$i = 0
foreach($e in $elements)
{
    $items += ($elements[$i].innerText).TrimEnd()
    $i++
}

$i = 1
$report = @()
do
{
    $report += [PSCustomObject]@{
        Sensor = $items[(($i * 12) - 10)]
        Device = $items[(($i * 12) - 9)]
        Group = $items[(($i * 12) - 8)]
        "Uptime %" = $items[(($i * 12) - 7)]
        "Uptime T" = $items[(($i * 12) - 6)]
        "Downtime %" = $items[(($i * 12) - 4)]
        "Downtime T" = $items[(($i * 12) - 3)]
    }
    $i++
}until($i -eq ((($items.Count)-2)/12))

$report | Export-Csv

Jun, 2018 - Permalink

If it returns what you need? :)


Kind regards,
Stephan Linke, Tech Support Team


Jun, 2018 - Permalink