# PRTG-CascadeStatus
#
# Loads the Status overview of a remote PRG-instance#
# 20180428 frank@carius.de
# Initial Version
param (
$serveruri = "https://prtg.paessler.com",
$Username = "demo",
$password = "demodemo",
$passhash = $null
)
write-host "PRTG-CascadeStatus:Start"
write-host " Username $($Username)"
if ($passhash) {
Write-host " Using PassHash"
$requesturi1 = "$($serveruri)/api/gettreenodestats.xml?Username=$($Username)&passhash=$($passhash)"
$requesturi2 = "$($serveruri)/api/getstatus.xml?Username=$($Username)&passhash=$($passhash)"
}
else {
write-host " Using Password"
$requesturi1 = "$($serveruri)/api/gettreenodestats.xml?Username=$($Username)&password=$($password)"
$requesturi2 = "$($serveruri)/api/getstatus.xml?Username=$($Username)&password=$($password)"
}
write-host " Requesturi1 = $($Requesturi1)"
write-host " Requesturi2 = $($Requesturi2)"
try {
write-host "Requesting Data from Source"
$result1 = invoke-restmethod $requesturi1
$result2 = invoke-restmethod $requesturi2
}
catch {
write-host " Error loading Data from Source. Error $($_.Exception.Message)"
$prtgresult = '
Error loading Data from Source. Error '+$_.Exception.Message+'
1
'
write-host "PRTG-CascadeStatus:End wiht Error"
write-host "PRTG-CascadeStatus:Send PRTGResult to STDOUT"
$prtgresult
}
write-host "PRTG-CascadeStatus: Build PRTG XML"
$prtgresult = "`r`n`r`n"
foreach ($property in ( "upsens",
"downsens",
"warnsens",
"downacksens",
"partialdownsens",
"unusualsens",
"pausedsens",
"undefinedsens",
"pausedsens",
"totalsens")){
$prtgresult += " `r`n"
$prtgresult += " $($property)`r`n"
$prtgresult += " $($result1.data.($($property)))`r`n"
$prtgresult += " Count`r`n"
$prtgresult += " 0`r`n"
$prtgresult += " `r`n"
}
$prtgresult += " `r`n"
$prtgresult += " PRTGUpdateAvailable`r`n"
if ($result2.status.PRTGUpdateAvailable -eq "no") {
$prtgresult += " 0`r`n"
}
else {
$prtgresult += " 1`r`n"
}
$prtgresult += " Count`r`n"
$prtgresult += " 0`r`n"
$prtgresult += " `r`n"
$prtgresult += " `r`n"
$prtgresult += " Version`r`n"
$prtgresult += " "
$prtgresult += ([int]$result2.status.Version.Split(".")[0]).tostring("00")
$prtgresult += ([int]$result2.status.Version.Split(".")[1]).tostring("000")
$prtgresult += ([int]$result2.status.Version.Split(".")[2]).tostring("000")
$prtgresult += ([int]$result2.status.Version.Split(".")[3]).tostring("0000")
$prtgresult += "`r`n"
$prtgresult += " `r`n"
$prtgresult += " 0`r`n"
$prtgresult += " Count`r`n"
$prtgresult += " 0`r`n"
$prtgresult += " `r`n"
$prtgresult += " OK URL:$($serveruri) Version $($result2.status.version)`r`n"
$prtgresult += " 0`r`n"
$prtgresult += ""
write-host "PRTG-CascadeStatus:End"
write-host "PRTG-CascadeStatus:Send PRTGResult to STDOUT"
$prtgresult