Hi Stephan,
I managed to get it working - after adding the Custom Sensor, I had to make sure that the Channel was using actual values as the Script accounts for 3 decimal places.
Also had to change up the code for the output a little for it to come out exactly as wanted. Here is the entire script:
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
###Grab all Sensor IDs from List###
$apiurl="http://prtg.domainname.com:8080/api/table.xml?id=0&content=sensors&columns=objid&username=Admin&passhash=##########"
[xml]$ini = (new-object System.Net.WebClient).downloadstring($apiurl)
###Declare Array to put all uptimes into at end of Foreach###
$target = @()
$ini.sensors.item | foreach {
$sensorapiurl="http://prtg.domainname.com:8080/api/getsensordetails.xml?id="+$_.objid+"&username=Admin&passhash=##########"
[xml]$result = (new-object System.Net.WebClient).downloadstring($sensorapiurl)
$node="uptime"
###Remove String Chars from Uptime###
[string]$strNum = $result.sensordata.$node.innertext.replace("%","").replace(".","")
###Check For If Statement###
If ($strNum -eq "N/A") {
return
}
Else{
###Convert Uptime to Integer then divide to Percentage Value###
[int]$intNum = [convert]::ToInt32($strNum, 10)
$target += $intNum/10000
}
}
$avg = ($target | Measure-Object -Average)
$final = [math]::Round($avg.Average, 3)
###Export Array of Uptime to CSV###
###write-host $final":"Current SLA is $final%
write-host "<prtg>"
"<result>"
"<channel>SLA</channel>"
"<value>$final</value>"
"<Unit>Custom</Unit>"
"<CustomUnit>%</CustomUnit>"
"<VolumeSize></VolumeSize>"
"<float>1</float>"
"</result>"
"<text>The Current SLA is $final</text>"
"</prtg>"
Add comment