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

Execute Powershell on drive sensor alert. How to pass Device and Drive parameters

Votes:

0

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

parameters powershell prig

Created on Nov 3, 2021 1:15:43 PM

Last change on Nov 5, 2021 7:05:21 AM by  Felix Wiesneth [Paessler Support]



3 Replies

Votes:

0

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

Created on Nov 5, 2021 9:27:22 PM by  Miguel Aikens [Paessler Technical Support]



Votes:

0

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.

Created on Nov 6, 2021 12:57:54 PM



Votes:

0

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

Created on Nov 8, 2021 11:05:14 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.