Hey there!

I have created a custom xml sensor which should have different "LimitMaxError" values depending on a condition. The sample below should illustrate what I am trying.

$hour = (get-date).Hour

if($hour -lt 9){
    $limit = 5
} else{
    $limit = 15
}

$xml += "<?xml version=""1.0"" encoding=""Windows-1252"" ?>"
$xml += "<prtg>"
$xml += "<result>"
$xml += "<Channel>Hour</Channel>"
$xml += "<Value>$hour</Value>"
$xml += "<Unit>Custom</Unit>"
$xml += "<CustomUnit>#</CustomUnit>"
$xml += "<LimitMaxError>$limit</LimitMaxError>"
$xml += "<LimitMode>1</LimitMode>"
$xml += "</result>"
$xml += "</prtg>"
$xml

If $hour < 9, $limit = 5 and if $hour > 9, $limit = 15. When I run this script in PowerShell ISE the value of $limit is correctly changing dependig on the condition but when the sensor is created the value of <LimitMaxError> does not change. The Value $hour is updated correctly.

Is there any way to realize this or can't limits of a channel be updated during script runtime?

Thanks in advance Kind Regards


Article Comments

Hello,
we appreciate your inquiry.

As per the documentation available within PRTG (Setup > PRTG API > Custom Sensors):

<LimitMaxError>
Define an upper error limit for the channel. If enabled, the sensor will be set to a "Down" status if this value is overrun and the LimitMode is activated. Note: Please provide the limit value in the unit of the base data type, just as used in the <Value> element of this section. While a sensor shows a "Down" status triggered by a limit, it will still receive data in its channels. The values defined with this element will be considered only on the first sensor scan, when the channel is newly created; they are ignored on all further sensor scans (and may be omitted). You can change this initial setting later in the Channel settings of the sensor.
This also applies to the following elements:
  • <ShowChart>
  • <ShowTable>
  • <LimitMaxError>
  • <LimitMaxWarning>
  • <LimitMinWarning>
  • <LimitMinError>
  • <LimitErrorMsg>
  • <LimitWarningMsg>


Within Custom Sensors, you can "workaround" this by using the following tags to set the sensor to error or warning based on specific conditions within the script:

  • <Warning>
  • <Error>
As example:
write-host "<prtg>"
write-host "<error>1</error>"
write-host "<text>Value ($value) is above limit</text>"
write-host "</prtg>"



Best Regards,


Oct, 2015 - Permalink

Hello,

thank you for the fast reply. I must have skipped this.

Thanks for the example.

Kind Regards


Oct, 2015 - Permalink