Blog
By Pete Zerger on 2/15/2010 3:54:21 AM • Rank (1952) • Views 2049
0

0

Recently in a forum thread, we had another discussion on the now age old problem: Creating an OpsMgr Top Alerts Reports based on repeat count tell you which rules are noisy is easy, but what about the top monitor-generated alerts?

In the past, we would use T-SQL to get this, as shown here

SELECT  [AlertName], [Severity] ,[RaisedDateTime] ,[SiteName] ,[RepeatCount] ,[DBCreatedDateTime] 
FROM [OperationsManagerDW].[Alert].[vAlert]
WHERE ( RaisedDateTime BETWEEN DATEADD(HH, DATEDIFF(HH, GETDATE(), getutcdate()), @startdate) AND DATEADD(HH, DATEDIFF(HH, GETDATE(), getutcdate()), @en

I was pleased to see that Tenchuu (Andreas Z) has yet again brought a new answer to an old problem with his Top Alerts Reports, Powershell Edition. Great work Tenchuu!


Top Alerts Report, Powershell Edition

Instructions for Use: Save in notepad with a .ps1 extension and run from OpsMgr Command Shell Prompt

#Create Datatable

$AlertTable = New-Object System.Data.DataTable "AlertTable"

$AlertTable.Columns.Add((New-Object System.Data.DataColumn ID,([string])))

$AlertTable.Columns.Add((New-Object System.Data.DataColumn Name,([string])))

$AlertTable.Columns.Add((New-Object System.Data.DataColumn AlertCount,([int])))

$AlertTable.Columns.Add((New-Object System.Data.DataColumn IsMonitorAlert,([string])))

foreach ($Alert in (Get-Alert))

{    

    #Check if Alert exists already.

    $AlertExists = $false  

    foreach ($Row in $AlertTable.Rows)

    {

        if ($Row.ID -eq $Alert.MonitoringRuleId.ToString())

        {    

            $AlertExists = $true

            #In case it does, we just merge the Repeatcount

            $Row.AlertCount = $Row.AlertCount + ($Alert.RepeatCount + 1)    

        }

    } 

    if ($AlertExists)

    {

    }

    else

    {

        #If the Alert doesn't exist, we add it to the DataTable.

        $NewRow = $AlertTable.NewRow()

        $NewRow.ID = $Alert.MonitoringRuleId.ToString()

        $NewRow.Name = $Alert.Name

        $NewRow.AlertCount = ($Alert.RepeatCount + 1)

        $NewRow.IsMonitorAlert = $Alert.IsMonitorAlert

        $AlertTable.Rows.Add($NewRow)

    }

}

$AlertTable = ($AlertTable | sort AlertCount -Descending)

$AlertTable | format-table -AutoSize | select-object -first 10

 

RSS | TWITTER

Comments (4) - Comment RSS
Andreas Zuckerhut wrote: on Nov 10, 2009 05:19 AM
Wow, amazing Script... wait, it's mine :D
Pete Zerger wrote: on Nov 10, 2009 05:33 AM
Tenchuu, I can hear your sarcasm. :) Just trying to make sure your work is properly noticed. Cheers for this!
Marco Shaw wrote: on Nov 10, 2009 08:43 AM
Figure 13 here: http://technet.microsoft.com/en-ca/magazine/2008.08.scom.aspx It has some code on how to associate rules and monitors with MPs. That may also be helpful.
Kevin wrote: on Nov 10, 2009 09:09 AM
Nice code. The only problem is that there is no date range specified, so this is going to take your max data contention period on the OpsMgrDB. This may have quite an overhead too. I would recommend first creating a CriteriaClass and passing that into the get-alert CMDlet to filter based on a date range. But congrats, this is very cool :)


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/yb2aasm

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert