Hi All,
I am having issues with the Sensor Output:
Reponse not wellformed: "(99.052:Current SLA is 99.052% <prtg> <result> <channel>SLA</channel> <value>99.052</value> <Unit>Custom</Unit> <CustomUnit>%</CustomUnit> <VolumeSize></VolumeSize> <float>1</float> </result> </prtg> )" (code: PE132)
I know there is the two formats there:
Status Message Format:
"value:message"
And the Channel Format:
<prtg>
<result>
<channel>SLA</channel>
<value>99.052</value>
<Unit>Custom</Unit>
<CustomUnit>%</CustomUnit>
<VolumeSize></VolumeSize>
<float>1</float>
</result>
</prtg>
Am I able to have both of those formats in the same sensor? If yes, where have I made the mistake? - I can provide the full script if needed.
Article Comments
Hi Stephan,
After looking into this a little more I found that there is the following code:
<prtg>
<result>
<channel>SLA</channel>
<value>$var</value>
<Unit>Custom</Unit>
<CustomUnit>%</CustomUnit>
<float>1</float>
</result>
<text>Status Message</text>
</prtg>
Focusing on <text>Status Message</text>, I have tried adding it to my script, but now the Channel SLA doesn't seem to work, simply displays 0% now instead of the actual value.
Should this be the case?
Jan, 2017 - Permalink
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>"
Jan, 2017 - Permalink
You can't use both formats within one sensor. The EXE/Script sensor needs one-line-output, the advanced version XML or JSON.
Jan, 2017 - Permalink