# PRTG-Cascade
#
# Load last values of an existing Sensor from another PRTG instance and sends them to the local sensor
#
# 20180428 frank@carius.de
# Initial Version
param (
$serveruri = "https://prtg.paessler.com",
$Username = "demo",
$password = "demodemo",
$sensorid = "2598",
$passhash = $null
)
write-host "PRTG-Cascade:Start"
write-host " Serveruri: $($serveruri)"
write-host " Username $($Username)"
if ($passhash) {
Write-host " Using PassHash"
$requesturi = "$($serveruri)/api/table.xml?content=channels&Username=$($Username)&passhash=$($passhash)&columns=name,lastvalue_&id=$($sensorid)"
}
else {
write-host " Using Password"
$requesturi = "$($serveruri)/api/table.xml?content=channels&Username=$($Username)&password=$($password)&columns=name,lastvalue_&id=$($sensorid)"
}
write-host " Requesturi = $($Requesturi)"
try {
write-host "Requesting Data from Source"
$result = invoke-restmethod $requesturi
write-host "PRTG-Cascade: Build PRTG XML"
$prtgresult = "`r`n`r`n"
foreach ($item in $result.channels.item) {
if ($item.lastvalue -ne $null) {
#$item.name + " xx " + $item.lastvalue.split(" ")[0] + " xx " + $item.lastvalue.split(" ")[1]
$prtgresult += " `r`n"
$prtgresult += " $($item.name)`r`n"
if ($item.lastvalue.contains(" ")){
$prtgresult += " $($item.lastvalue.split(" ")[0])`r`n"
$prtgresult += " Custom`r`n"
$prtgresult += " $($item.lastvalue.split(" ")[1])`r`n"
if ($item.lastvalue.contains(",")) {
$prtgresult += " 1`r`n"
}
else {
$prtgresult += " 0`r`n"
}
}
$prtgresult += " Count`r`n"
$prtgresult += " `r`n"
}
}
$prtgresult += " OK URL:$($serveruri) SensorID:$($sensorid)`r`n"
$prtgresult += " 0`r`n"
$prtgresult += ""
}
catch {
write-host " Error loading Data from Source. Error $($_.Exception.Message)"
$prtgresult = '
Error loading Data from Source. Error '+$_.Exception.Message+'
1
'
}
write-host "PRTG-Cascade:End"
write-host "PRTG-Cascade:Send PRTGResult to STDOUT"
$prtgresult