On lines 19 & 20 I am trying to get the Device and drive that is alerting and kicking off the PowerShell script to tell us the top 10 largest files.
2 questions how do I get the parameters from the alert and how do I get PRTG to execute the script on drive sensors that are "Down" and not in a warning?
Any help would be appreciated.
$scriptBlock = { param ([string]$Path) #$ErrorActionPreference = "silentlyContinue" $list = New-Object 'Collections.ArrayList' $files =(robocopy /bytes /njh /njs /np /nc /fp /ndl /l /s "$Path" 'NoDestination') foreach($file in $files) { $data = $file.split("`t") $null = $list.add([tuple]::create([uint64]$data[3], $data[4])) } $list.sort() # sort by size ascending $result = $list.GetRange($list.count-10,10) $result #| select item2, item1 | sort item1 -Descending } $device = %Device $DriveAlerting = %sensor # needs to b einthe format "D:\" $result= Invoke-Command -ComputerName $device -ScriptBlock $scriptBlock -ArgumentList $DriveAlerting $mailOutput =$result | select -property @{N='Device';E={$_.PSComputerName}}, @{N='Path';E={$_.Item2}}, @{N='Size in GB';E={($_.Item1/1GB)}} | sort 'Size in GB' -Descending #### Create the email $msg = New-Object Net.Mail.MailMessage $style = "<style>BODY{font-family: Arial; font-size: 10pt;}" $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}" $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }" $style = $style + "TD{border: 1px solid black; padding: 5px; }" $style = $style + "</style>" $Msg = @{ To = xxxxxxxx From = XXXXXXXX Body = $mailOutput | ConvertTo-Html -Head $Style -Body "<H2>Top 10 largest files</H2>" | Out-String # subject = "$device - $((Get-Date).ToShortDateString())" SmtpServer = xxxxxxx BodyAsHtml = $True } Send-MailMessage @Msg
Article Comments
Still getting familiar with PRTG so not sure what the best way is.
What I want to do is when any "down" SNMP sensor for any hard drive is below the alert threshold. I want this script to kick off and determine the top 10 largest files on that drive. Therefore our NOC does not have to determine this manually.
I currently have the script to email our NOC. If you have suggestions to make that better I am open ideas.
Nov, 2021 - Permalink
Hi,
Thanks for your reply.
For the parameters you can use for the script you can find them here: https://www.paessler.com/manuals/prtg/custom_sensors
Here's one for command-line: https://www.paessler.com/manuals/prtg/custom_sensors#command_line
Turns out we don't provide support on scripting but we can provide data for you to build your scripts. There's another useful website with some scripts you might want to use as a reference: https://www.paessler.com/sensor-hub/all/all/all
Hope this provides some guidance.
At your service,
Miguel Aikens
Nov, 2021 - Permalink
Hello,
Thanks for contacting us.
Do you want to use this script for a notification template is it? Just want to be clear before providing more information.
Regards,
Miguel Aikens
Nov, 2021 - Permalink