#Import-Module OperationsManager
#=================================================================================
# Just for monitors no read and write files.
function AlertsRuleMonitor {
# Import the SCOM PowerShell module
$ScriptName = "AlertsRuleMonitor.ps1"
$disableLoggingToArray = -not $LogToArray
LoadOperationsManagerModule $ScriptName
# Gather script start time
$StartTime = Get-Date
# Gather who the script is running as
$WhoAmI = whoami
# Connect to FlashArray
try {
$IgnoreCertErrors = GetIgnoreCertErrors $true
$FlashArray = New-PfaArray -EndPoint $Endpoint -UserName $Username -Password $Password -ClientName $GLOBAL:clientName -ClientVersion $GLOBAL:mpVersion -IgnoreCertificateError:$IgnoreCertErrors -HttpTimeOutInMilliSeconds 60000 -DisableLoggingToArray:$disableLoggingToArray
} catch {
Log $ScriptName $GLOBAL:ERROR_LEVEL "Connection to array failed on these credentials. $Username. Check that the PurePowershell cmdlet is installed, your credentials are correct and that you have access to the Pure Arrays listed in your credentials file. Error: $_"
exit
}
$Warning = "No"
# Import the SCOM PowerShell module
Import-module OperationsManager
# Connect to localhost when running on the management server
$connect = New-SCOMManagementGroupConnection –ComputerName localhost
# Get group of PureArray
$Group = Get-SCOMGroup -DisplayName "*Pure Array*"
# Get the instances of this paticular array
$ArrayInstance = $Group.GetRelatedMonitoringObjects() | where {$_.DisplayName -eq $Endpoint}
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Array Instance found: $ArrayInstance"
# Get new critical alerts whose names contain REST API
$CriticalAlerts = Get-SCOMAlert -Instance $ArrayInstance -ResolutionState 0 -Severity 2 | where {$_.name -like "*REST API*"}
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Critical REST API alerts found: $CriticalAlerts"
# Get new warning alerts whose names contain REST API
$WarningAlerts = Get-SCOMAlert -Instance $ArrayInstance -ResolutionState 0 -Severity 1 | where {$_.name -like "*REST API*"}
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "Warning REST API alerts found: $WarningAlerts"
$Severity = ""
if ($CriticalAlerts -eq $null -and $WarningAlerts -eq $null) {
Log $ScriptName $GLOBAL:VERBOSE_LEVEL "No alerts from REST API"
$Warning = "No"
} else {
$Warning = "Yes"
if ($CriticalAlerts -ne $null) {
$Severity = "critical"
} else {
$Severity = "warning"
}
}
$bag = $momapi.CreatePropertyBag()
# Add the necessary properties to the object and add the object to the return bag
$bag.AddValue('Warning',$Warning)
$bag.AddValue('Severity',$Severity)
$bag
$EndTime = Get-Date
$ScriptTime = ($EndTime - $StartTime).TotalSeconds
Log $ScriptName $GLOBAL:INFO_LEVEL "Script has completed at $Endpoint, Alert state $Severity. Runtime was ($ScriptTime) seconds."