Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Monday, February 8, 2010

Retrieve a list of monitors in a critical state

One thing the OpsMgr team 'forgot' to do was allow us to view all Monitors in a Critical state. This is obviously something a lot of people would need as it's nice to have an overview of what isn't in a healthy state without trawling through Health Explorer Windows.

Unfortunately there is no elegant way to do this with the SDK and/or Powershell, as this needs to be addressed on a "per monitoringobject" basis, meaning we have to loop through classes and objects and that will take a crazy amount of time.

Once again, SQL to the rescue:

Select [TimeGenerated],a.BaseManagedEntityId, a.DisplayName, a.TopLevelHostEntityId, e.DisplayName as ParentDisplayname, e.FullName as ParentFullName,
f.TypeName,
DateDiff(mi,TimeGenerated,GETUTCDate())[TimeInState],ISNULL(a.path,a.DisplayName)[Path],OperationalStateName,
a.DisplayName[Problem],d.DisplayName[Problem Description],d.Description[Detailed Description]
from BaseManagedEntity a
INNER JOIN ManagedEntityAvailabilityView b on a.BaseManagedEntityId =b.BaseManagedEntityId
INNER JOIN StateView c on b.BaseManagedEntityId =c.BaseManagedEntityId
INNER JOIN MonitorView d on c.MonitorID= d.ID
INNER JOIN BaseManagedEntity e on e.BaseManagedEntityId = a.TopLevelHostEntityId
INNER JOIN ManagedType f on a.BaseManagedTypeId=f.ManagedTypeId
INNER JOIN

(Select BaseManagedEntityID,NewHealthState,max(TimeGenerated)[TimeGenerated]
From StateChangeEventView
Group By BaseManagedEntityID,NewHealthState)SC
On b.BaseManagedEntityID = SC.BaseManagedEntityId

Where HealthState = 3
and AlertPriority = 1
and IsUnitMonitor = 1
and SC.NewHealthState = 3
--and e.DisplayName = 'COMPUTERNAME'
Order By a.[Path]

Stuff to help you with these products, yo

Right, so here's the deal:

There's a few of us working for a rather large, rather international company - we make sure a whole lot of servers are working most of the time.

I'm sure if any of you have ever worked with OpsMgr and/or SCCM, you will know that these products are quite large and the documentation/help isn't all that great.

This blog is two-fold: it's going to help us categorise all the things we've done and also serve to contribute to the System Center community.

Our team is as follows:

DT: SCCM - he's been using this product for years. I know stuff all about it so any post regarding this topic will definitely be from him.

AB - SQL - despite what you may think, there are some things you cannot do with the SDK. If the data is there, Andre will find a way to use it.

RN - MP Authoring - need help understanding relationships? Hosted entities? Abstrat classes? Eh...

CM - Infrastructure - installing Gateways, Management Servers, Certificate Authentication, etc.

KC - SDK, Powershell, Custom OpsMgr applications, MP Authoring, general blog writer.

---

So here's hoping this won't turn into yet another "one post" blog.