New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


PRTG Powershell Custom Sensor Output Format

Votes:

0

Your Vote:

Up

Down

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 by  Evan Lane (110) 2 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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 by  Evan Lane (110) 2 1



5 Replies

Votes:

1

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Evan Lane (110) 2 1



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Evan Lane (110) 2 1



Votes:

0

Your Vote:

Up

Down

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

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



Please log in or register to enter your reply.


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.