Hi,

We have a file share with many subfolders inside it. Each subfolder has a file called "test.txt" while file name is the same, the file size different. We need to monitor all test.txt files and show an alert in prtg if any of the test.txt files is any of the subfolders grows larger than 10 KB.

This power shell below returns the results we need

 Get-Childitem -path  $path -Recurse -Filter $fileFilter | Sort-Object  Length  -Descending |  Select-Object DirectoryName, name, @{Name="KBytes";Expression={ '{0:N0}' -f ($_.Length / 1KB) }}
 

in the following format

DirectoryName        Name     KBytes 

-------------        ----     ------

E:\Share\Dirt Files  test.txt 5     

E:\Share\Clean Files test.txt 0     

E:\Share\Fake Files  test.txt 0     

If the result in the KBytes column on any of the lines is over 10 we need to show an alert for that line

It's our understanding that results need to be formatted for PRTG to understand but we can't find any good examples showing what to do in our situation.


Article Comments

Hello,

Thanks for contacting us.

In this case you will need to parse the output from the command and then put it in the right structure (most likely JSON/XML as there are multiple channels)

More information: https://www.paessler.com/manuals/prtg/custom_sensors#advanced_sensors

And, in addition to this you can use the following example for guidance: https://helpdesk.paessler.com/en/support/solutions/articles/89954-powershell-script-output

Hope this helps.

Regards,

Miguel Aikens


Jun, 2022 - Permalink

Looks like the script below is recognized by PRTG, I am getting a path for each file, but file name isn't displayed. Additionally, I am not sure how to set up alerting for all of the results returned and not for each folder individually.

Thank you

$path = "E:\Share"
$fileFilter = "test.txt"

$fileSizes =  Get-Childitem -path  $path -Recurse -Filter $fileFilter | Sort-Object  Length  -Descending |  Select-Object DirectoryName, name, @{Name="KBytes";Expression={ '{0:N0}' -f ($_.Length / 1KB) }}

$filesHtml = ""

Foreach ($file in $fileSizes) 
{ 
    $d = $file.DirectoryName
    $n = $file.name
    $v = $file.KBytes
   
    $filesHtml = $filesHtml+"<result><channel>"+$d+"</channel><value>"+$v+"</value><text>"+$n+"</text></result>" 
} 

Write-Host "<prtg>" 
$filesHtml
"</prtg>"

Jun, 2022 - Permalink

Hello again,

I will contact you directly using our ticketing tool to get more details and screenshots. This would be easier for me to see what you are seeing and go from there.

Regards,

Miguel Aikens


Jun, 2022 - Permalink