I was able to put this script together thanks to several great examples from others. It will check the CSV status and if it falls below a certain threshold it will send an email to the address specified. You will need to modify a few of the lines below for email server, to address, etc.
#Load the FailoverClusters module
Import-Module FailoverClusters
$warninglevel = 15 # The percent to send warning at
$objs = @()
$nl = [Environment]::NewLine
$csv_status = Get-ClusterSharedVolume
foreach ( $csv in $csv_status )
{
$expanded_csv_info = $csv | select -Property Name -ExpandProperty SharedVolumeInfo
foreach ( $csvinfo in $expanded_csv_info )
{
$obj = New-Object PSObject -Property @{
Name = $csvinfo.Name
Path = $csvinfo.FriendlyVolumeName
Size = $csvinfo.Partition.Size
FreeSpace = $csvinfo.Partition.FreeSpace
UsedSpace = $csvinfo.Partition.UsedSpace
PercentFree = $csvinfo.Partition.PercentFree
}
if ($csvinfo.Partition.PercentFree -lt $warninglevel) { $objs += $obj }
}
}
if ($objs.count -gt 0) {
$smtpServer = "mailserver"
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "from address"
$msg.To.Add("to address")
$msg.Priority = "high"
$msg.Subject = "Warning Cluster Volume low on space"
#Preamble text
$msg.body = "Enter any explanatory message here or delete this line"
#Next line is what puts in the volume information
$msg.body += $objs | ft -auto Name,Path,@{ Label = "Size(GB)" ; Expression = { "{0:N2}" -f ($_.Size/1024/1024/1024) } },@{ Label = "Free(GB)" ; Expression = { "{0:N2}" -f ($_.FreeSpace/1024/1024/1024) } },@{ Label = "Used(GB)" ; Expression = { "{0:N2}" -f ($_.UsedSpace/1024/1024/1024) } },@{ Label = "PercentFree" ; Expression = { "{0:N2}" -f ($_.PercentFree) } } | Out-String
$smtp.Send($msg)
}
To make this work create the script in a ps1 file. Modify the settings that need to be modified and adjust your warning threshold to a percent you like. Create a scheduled job to run it at whatever interval you wish. I run mine every 15 minutes. When creating the job make sure the program you run is powershell.exe then give it a command line option of your script name.
Thanks--I was able to implement this into my monitoring system to alert when Cluster Shared Volumes are low on space!
ReplyDelete