Anzahl aktiver Verwaltungsgruppenwarnungen erfassen

ManagementGroupCollectionAlertsCountRule (Rule)

Anzahl der aktiven Warnungen in der Verwaltungsgruppe erfassen

Element properties:

TargetMicrosoft.SystemCenter.AllManagementServersPool
CategoryPerformanceCollection
EnabledTrue
Alert GenerateFalse
RemotableTrue

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedPowerShell.PerformanceProvider System.PrivilegedMonitoringAccount
WriteToDB WriteAction Microsoft.SystemCenter.CollectPerformanceData Default
WriteToDW WriteAction Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData Default

Source Code:

<Rule ID="ManagementGroupCollectionAlertsCountRule" Enabled="true" Target="SC!Microsoft.SystemCenter.AllManagementServersPool" ConfirmDelivery="false" Remotable="true" Priority="Normal" DiscardLevel="100">
<Category>PerformanceCollection</Category>
<DataSources>
<DataSource ID="DS" TypeID="Microsoft.Windows.TimedPowerShell.PerformanceProvider" RunAs="System!System.PrivilegedMonitoringAccount">
<IntervalSeconds>900</IntervalSeconds>
<SyncTime/>
<ScriptName>GetMGAlertsCount.ps1</ScriptName>
<ScriptBody><Script>$errorActionPreference = 'Stop'
Set-StrictMode -Version 2

$SCOMPowerShellKey = "HKLM:\SOFTWARE\Microsoft\System Center Operations Manager\12\Setup\Powershell\V2"
$SCOMModulePath = Join-Path (Get-ItemProperty $SCOMPowerShellKey).InstallDirectory &#x201C;OperationsManager&#x201D;
Import-module $SCOMModulePath

$alertsCount = 0
$alertsByObjectHash = @{}
$alertsByObject = Get-SCOMAlert -ResolutionState 0 | group MonitoringObjectId
if (!$alertsByObject)
{
# do nothing, alerts count is zero as default
}
else
{
function PopulateClassHash($class)
{
if (!$allMGRelatedClassHash.ContainsKey($class.Id))
{
$allMGRelatedClassHash.Add($class.Id, $class.Name)

# recursively get target classes in relationships with source is current class and add into the hashtable
$relationships = @(Get-SCOMRelationship -Source $class) | Where {$_.Base.GetElement().Name -ne "System.Reference"}
if ($relationships)
{
foreach ($relationship in $relationships)
{
PopulateClassHash $relationship.Target.Type.GetElement()
}
}
}
}

$mgClass = Get-SCOMClass -Name "Microsoft.SystemCenter.AllOperationsManagerObjectsGroup"
$mgGroup = Get-SCOMGroup -Id $mgClass.Id
$mgMembers = $mgGroup.GetChildMonitoringObjectGroups()
$firstLvlMemberClassHash = @{}

foreach ($member in $mgMembers)
{
$cls = $member.GetClasses()
foreach ($c in $cls)
{
if (!$firstLvlMemberClassHash.ContainsKey($c.Id))
{
$firstLvlMemberClassHash.Add($c.Id, $c.name)
}
}
}

$allMGRelatedClassHash = @{}

# populate the all MG related class hashtable
foreach ($firstLvlMember in $firstLvlMemberClassHash.GetEnumerator())
{
$firstLvlClass = Get-SCOMClass -Id $firstLvlMember.Name
PopulateClassHash $firstLvlClass
}

$alertsByObject | % {$alertsByObjectHash.Add($_.Name, $_.Count)}

foreach ($obj in $alertsByObjectHash.GetEnumerator())
{
$objInstance = Get-SCOMClassInstance -Id $obj.Name
IF (!($objInstance)) { continue }
$objClasses = $objInstance.GetClasses()
foreach ($objCls in $objClasses)
{
if ($allMGRelatedClassHash.ContainsKey($objCls.Id))
{
$alertsCount += $obj.Value
break
}
}
}
}

$api = New-Object -comObject 'MOM.ScriptAPI'
$bag = $api.CreateTypedPropertyBag(2)
$bag.AddValue('AlertsCount', [System.Int32]$alertsCount)
$api.AddItem($bag)
$bag</Script></ScriptBody>
<Parameters/>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>false</StrictErrorHandling>
<ObjectName>ManagementGroupAlerts</ObjectName>
<CounterName>AlertsCount</CounterName>
<InstanceName>Total</InstanceName>
<Value>$Data/Property[@Name='AlertsCount']$</Value>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData"/>
<WriteAction ID="WriteToDW" TypeID="SCDW!Microsoft.SystemCenter.DataWarehouse.PublishPerformanceData"/>
</WriteActions>
</Rule>