What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

PRTG Powershell Custom Sensor Output Format

Votes:

0

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.

channels custom-sensor powershell prtg sensor-channels

Created on Jan 17, 2017 1:25:17 PM



Best Answer

Accepted Answer

Votes:

0

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>"

Created on Jan 24, 2017 1:20:06 PM



5 Replies

Votes:

1

You can't use both formats within one sensor. The EXE/Script sensor needs one-line-output, the advanced version XML or JSON.

Created on Jan 17, 2017 1:42:11 PM by  Stephan Linke [Paessler Support]



Votes:

0

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?

Created on Jan 23, 2017 3:37:13 PM



Votes:

0

Could you please post your entire script? :)

Created on Jan 24, 2017 1:15:38 PM by  Stephan Linke [Paessler Support]



Accepted Answer

Votes:

0

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>"

Created on Jan 24, 2017 1:20:06 PM



Votes:

0

Nice that you got it already :) Thanks for sharing!

Created on Jan 24, 2017 1:31:07 PM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.