Welcome to MSDN Blogs Sign in | Join | Help

Notes on System Center Operations Manager

Notes, troubleshooting, development and comments related to System Center Operations Manager

Syndication

News











All of my postings are provided "AS IS" with no warranties, and confer no rights. Use of included samples are subject to the terms specified at Microsoft.



Locations of visitors to this page

Locations of visitors to this page


Last contacted, better SQL query

My post about how to receive approximate last contacted time spawn good feedback and thanks to Robin Drake for rewriting my SQL script without use of cursors while producing single grid. Following is his version:

use OperationsManager

Go

declare @substract float

declare @numberOfMissing float

declare @interval float

-- Get the number of missing heartbeats

select @numberOfMissing = SettingValue from GlobalSettings GS

join ManagedTypeProperty MTP with(nolock) on GS.ManagedTypePropertyId = MTP.ManagedTypePropertyId

where MTP.ManagedTypePropertyName = 'NumberOfMissingHeartBeatsToMarkMachineDown'

-- Get the heartbeat interval

select @interval = SettingValue from GlobalSettings GS

join ManagedTypeProperty MTP with(nolock) on GS.ManagedTypePropertyId = MTP.ManagedTypePropertyId

where MTP.ManagedTypePropertyName = 'HeartbeatInterval'

-- Calculate the amount of lapsed time before a system is marked as non contactable

select @substract = (@numberOfMissing * @interval)/100000

select B.DisplayName, AH.TimeStarted, (cast((cast(tmp.MaxTimeStarted as float)- @substract) as datetime)) as [ApproxLastContactedTime (UTC)],

dateadd(hh, +9, (cast((cast(tmp.MaxTimeStarted as float)- @substract) as datetime))) as 'ApproxLastContactedTime (Pacific)' from Availability A

join BaseManagedEntity B with(nolock) on B.BaseManagedEntityId = A.BaseManagedEntityId

join AvailabilityHistory AH with(nolock) on AH.BaseManagedEntityId = A.BaseManagedEntityId

join

(

select MAX(AHTMP.TimeStarted) AS MaxTimeStarted, BME.BaseManagedEntityId from AvailabilityHistory AHTMP

join BaseManagedEntity BME with(nolock) on BME.BaseManagedEntityId = AHTMP.BaseManagedEntityId

where BME.IsDeleted = 0

group by BME.BaseManagedEntityId

)

TMP on AH.TimeStarted = MaxTimeStarted

where A.IsAvailable = 0 and B.IsDeleted = 0

Robin, Thanks again!

Published Monday, July 28, 2008 2:57 AM by MSutara

Filed under: , ,

Comments

# re: Last contacted, better SQL query @ Monday, July 28, 2008 5:12 PM

Thought I would let you know both this and the other query return multiple results for cluster nodes.

DerekHar

# Only one row of data? @ Tuesday, July 29, 2008 6:43 PM

Why is there ever only one row of data (i.e. one computer) listed when I run this query? This is not very useful if it only returns one computer object and times checked in....how can this query be expanded to list more?

I was thinking of turning this into a task launched from the console and using sqlcmd.exe

C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe -s miwimo20 -d OperationsManager -E -i "c:\temp\sqlquerytest.sql" -W

Thoughts?

geist_23@hotmail.com

# re: Last contacted, better SQL query @ Thursday, July 31, 2008 10:15 AM

if you add a DISTINCT clause to the last SELECT you'll avoid to have duplicate rows...

select DISTINCT B.DisplayName, AH.TimeStarted ...

Brandubh

# re: Last contacted, better SQL query @ Friday, August 01, 2008 8:55 AM

Thanks! Adding DISTINCT is a good point. I guess I would do that immediatelly if I knew T-SQL better, but I'm just C++ developer :)

MSutara

# Only one row ... @ Friday, August 01, 2008 8:57 AM

As I said in my previous post, this works only against agent computers which were ever unavailable. This doesn't work for all health services within topology ...

MSutara

Anonymous comments are disabled
Page view tracker