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

Custom PS script sensor

Votes:

0

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.

custom-sensor file-size powershell script

Created on May 28, 2022 1:44:57 AM

Last change on May 30, 2022 6:31:53 AM by  Felix Wiesneth [Paessler Support]



3 Replies

Votes:

0

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://kb.paessler.com/en/topic/89954-powershell-script-output

Hope this helps.

Regards,

Miguel Aikens

Created on Jun 1, 2022 9:23:02 PM by  Miguel Aikens [Paessler Technical Support]



Votes:

0

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

Created on Jun 1, 2022 10:43:42 PM

Last change on Jun 2, 2022 5:51:51 AM by  Felix Wiesneth [Paessler Support]



Votes:

0

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

Created on Jun 3, 2022 9:44:43 PM by  Miguel Aikens [Paessler Technical 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.