I have a distributed Application. If the application change healthState I have to send an alert with the child-monitor that is unhealthy.
Is their a way to find out wich of the child monitor does not have the state success?
I have tried:
$serviceObjectsRecursive = $DA.GetRelatedMonitoringObjects(‘Recursive’)
foreach ($instance in $serviceObjectsRecursive )
{
$monitors = Get-SCOMMonitor -Instance $instance -Recurse
foreach ( $monitor in $monitors)
{
<#Here I have the problem to get the MonitorState#>
}
}
$serviceObjectsRecursive = $DA.GetRelatedMonitoringObjects(‘Recursive’) | ? HealthState -EQ Error
foreach ($Instance in $serviceObjectsRecursive ) {
$MonitorCollection = New-Object -TypeName 'System.Collections.Generic.List[Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitor]'
#Only get unhealthy Unit monitors
$Instance | Get-SCOMMonitor -Recurse | ? XMLTag -Match Unit | %{ $MonitorCollection.Add($_) }
if ($MonitorCollection.Count -gt 0) {
$Instance.GetMonitoringStates($MonitorCollection) | ? HealthState -EQ Error
}
}
I like to filter as we go, of course you can skip or update it (if you want the Warnings as well for example). I have also started with the same $DA as yours (Assume you get the ID from the Alert and go from there, but that should be the easy part)