Netflex Blog

powershell

Monitor File Cluster Resources

When a (file) cluster resource failover occurred it is not always desirable to do an automatic failback (you probably would investigate the reason for the failover before performing a failback of the resources). Because of this I have created a Powershell script for use with file clusters to monitor file cluster resources, it works pretty much like the Powershell script I made for monitoring Exchange Database failovers (https://netflex.nl/exchange-database-activation-preference ).

The Powershell script monitors the preferred owner of a resource. In the event the Powershell script detects a resource is not running on the preferred owner, the Powershell script will send an email alert to a predefined recipient.

<#
Author: Michiel Elderson (Netflex)
Date: 14-01-2016
Purpose: Monitor cluster resource owner,
if the owner is not the preferred owner an email alert will be send.

Usage: Run this file in Powershell (can be scheduled once an hour or so)

History
Version |Date |Name |Comments
1.0 |14-01-2016 |Michiel Elderson |Initial Version
#>

Import-Module FailoverClusters
#Michiel Elderson: Change to reflect your (cluster) settings
$ClusterName = "MyCluster"
$From = "FailoverClusterAlert@domain.com"
$Recipients = @("User1@domain.com", "User2@domain.com")
$SmtpServer = "MySMTPServer@domain.com"

#Michiel Elerson: get cluster resources
$Resources = @(Get-ClusterGroup -cluster $ClusterName)

#Michiel Elderson:Create empty email body array
$body = @() | Out-string

#Michiel Elderson: Check each resources preferred / current node
foreach ($Resource in $Resources){

#Michiel Elderson: Get Preferred and Curent resource owner
$ResourceName = $resource.name
$PreferredOwner = (Get-ClusterGroup -cluster $ClusterName $ResourceName | Get-ClusterOwnerNode | % OwnerNodes).name
$CurrentOwner = (Get-ClusterGroup -cluster $ClusterName $ResourceName | % OwnerNode).name

#Michiel Elderson:
#If the Current owner differs from the preferred owner a mail alert will be send.
#(Exclude resource "Available Storage" and "Cluster Group")
if ($PreferredOwner -ne $CurrentOwner -and $ResourceName -ne "Available Storage" -and $ResourceName -ne "Cluster Group"){
Write-host "FileClusterResource $Resource is NOT active on the preferred server" -BackgroundColor Red
$body +="<p>FileClusterResource $Resource is NOT active on the preferred server</p>"
}

}
#Set email settings
$smtpsettings = @{
To = $Recipients
From = $From
Subject = "Resource failover occurred"
Body = $Body
SmtpServer = $SmtpServer
}

#Send the actual mail
Send-mailmessage @smtpsettings -BodyAsHtml

 

When you receive an email alert it is up to you when to do a failback of the resources

 

Usage:

Save the script to Monitor-ResourceOwner.ps1 and change the SMTP/Cluster settings. Run the script on a server where the “Failover Clustering Tools” are installed. You could schedule the script to run every hour.

 

Scroll to Top