Quantcast
Channel: THWACK: All Content - Server & Application Monitor
Viewing all articles
Browse latest Browse all 12281

Use Powershell script monitor message and statistic in an alert

$
0
0

So, I've created a little PowerShell script that looks at all the subfolders of a given folder and then returns a message with the name of the last folder it finds that is larger than 10GB and a statistic with the size of the folder in GB, (I'd like to eventually figure out how to return all subfolders larger than 10GB, but I haven't gotten that deep into Solarwinds yet...).

 

What I'd like to do is to include the message and statistic values in an alert for the monitor, but I can't figure out how. In this thread, aLTeReGo claims that it can be done by using ${StatisticData} and ${ComponentMessage}, but that doesn't work for me. When the email is sent by the alert, I see the variable name instead of the value I expected. Where am I going wrong?

 

Email message "code":

${N=Alerting;M=AlertDescription}

${N=SwisEntity;M=Node.DNS}

 

${StatisticData}

${ComponentMessage}

 

View full object details here: ${N=SwisEntity;M=DetailsUrl}.

View full alert details here: ${N=Alerting;M=AlertDetailsUrl}

 

PowerShell script:

Invoke-Command -ComputerName ${Node.DNS} -ArgumentList $args[0] -Credential ${CREDENTIAL} -ScriptBlock {

    $FolderPath = $args[0]

    $flag = $false

    $folderName = ""

    Get-ChildItem -Directory $FolderPath | ForEach-Object {

        $spaceUsed = ($((Get-ChildItem -path $_.FullName -recurse | Measure-Object -property length -sum ).sum))/1GB

        if ($spaceUsed -gt 10)

        {

            $flag = $true

            $folderName = $_.Name

        }

    }

    if ($flag)

    {

        Write-Host "Statistic: 1"

        Write-Host "Message: $folderName is larger than 10GB"

    }

    else

    {

        Write-Host "Statistic: 0"

        Write-Host "Message: No subdirectories are larger than 10GB"

    }

}


Viewing all articles
Browse latest Browse all 12281

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>