Hi Guys,

I am trying to check if a folder is written to in the last 24hr using EXE (i know the folder sensor exists but it will not work in this situation) however i am having issues with the returning value being read correctly by PRTG.

here is the sensor script

$Today = Get-Date
$FileList = Get-ChildItem -LiteralPath 'UNCPATH' -File 

$AgeLimitHours = 24

foreach ($FL_Item in $FileList)
    {
    $HoursOld = [math]::Round(($Today - $FL_Item.LastWriteTime).TotalHours, 0)

    if ($HoursOld -le $AgeLimitHours)
        {
        'value:2' -f $AgeLimitHours
        }
        else
        {
        'value:1'
        }
    }

This returns: {{{ value:1 value:1 value:1 value:1 value:1 value:2 }} for 6 files over 24hr old and 1 file under 24hrs old. However PRTG only reads 0 as a value. It does however display 1 or 2 directly under the name, as a message?

How can i ensure that the value output is read properly?


Article Comments

Hello Samuel,
thank you for your KB-Post.

If you want to have a sensor capable of displaying multiple results, you need to work with the "Advanced" custom sensor variants, that expect JSON or XML. This way you can have up to 50 channels. Please have a look at this KB-Post to understand how the data should look like:

When working with the non-advanced sensors, you can only have one value, but you can have a message. The output should look like this:

value:message

Example for a value of 5 with text "Everything OK" in Powershell:

Write-Host "5:Everything OK"
exit 0

Best Regards,
Luciano Lingnau [Paessler Support]


Mar, 2018 - Permalink