Detect duplicate relationships for agents to server Monitor Type

Microsoft.SystemCenter.2007.OpsMgrDB.DetectDuplicateRelationshipsforAgentsToServers.MonitorType (UnitMonitorType)

This monitor type detects any duplicate relationships that exist in the operational database to avoid excessive data being generated by discoveries which can cause a problem in updating configurations.

Knowledge Base article:

Summary

Monitor type to check for duplicate relationships between agents and servers.

Element properties:

RunAsDefault
AccessibilityInternal
Support Monitor RecalculateTrue

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.Scheduler Default
Probe ProbeAction Microsoft.SystemCenter.2007.OpsMgrDB.Generic.DS Default
CDCritical ConditionDetection System.ExpressionFilter Default
CDHealthy ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval (seconds)
Synctimestring$Config/Synctime$Sync time
TimeoutSecondsint$Config/TimeoutSeconds$Timeout (seconds)

Source Code:

<UnitMonitorType ID="Microsoft.SystemCenter.2007.OpsMgrDB.DetectDuplicateRelationshipsforAgentsToServers.MonitorType" Accessibility="Internal">
<MonitorTypeStates>
<MonitorTypeState ID="Healthy" NoDetection="false"/>
<MonitorTypeState ID="Critical" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="Synctime" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:int"/>
<xsd:element name="DatabaseServerName" type="xsd:string"/>
<xsd:element name="DatabaseName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="Synctime" Selector="$Config/Synctime$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.Scheduler">
<Scheduler>
<SimpleReccuringSchedule>
<Interval>$Config/IntervalSeconds$</Interval>
<SyncTime>$Config/Synctime$</SyncTime>
</SimpleReccuringSchedule>
<ExcludeDates/>
</Scheduler>
</DataSource>
<ProbeAction ID="Probe" TypeID="Microsoft.SystemCenter.2007.OpsMgrDB.Generic.DS">
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<ScriptName>DetectDuplicateRelAgnToSrvMonitor.vbs</ScriptName>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved.

'*************************************************************************
' $ScriptName: "GetSqlNativeClientComman" $
'
' Purpose: This script is used to get SQL native client Driver name.
'
' $File: GetSqlNativeClientComman.vbs $
'*************************************************************************


Option Explicit

Function GetSqlDriverName
Dim oAPI1, oReg
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Dim strComputer, strDriverPath, strKeyPath, intValue, strValueName,arrSubKeys,oSubkey,strNewKeyPath,intDotIndex
strComputer = "."
strDriverPath="SQLOLEDB"
Set oReg=GetObject("winmgmts:\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\ODBC\ODBCINST.INI"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each oSubkey In arrSubKeys
intValue = InStr(oSubkey, "SQL Server Native Client")
if intValue &lt;&gt; 0 Then
strValueName = "Driver"
strNewKeyPath = strKeyPath&amp;"\"&amp;oSubkey
oReg.GetStringValue HKEY_LOCAL_MACHINE, strNewKeyPath, strValueName , strDriverPath
strDriverPath = Mid (strDriverPath, InStrRev(strDriverPath, "\")+1)
intDotIndex = InStr(strDriverPath, ".")
strDriverPath = Left(strDriverPath , intDotIndex-1)
end if
Next
GetSqlDriverName = strDriverPath
End Function

'Copyright (c) Microsoft Corporation. All rights reserved.

'*************************************************************************
' $ScriptName: "DetectDuplicateRelAgnToSrvMonitor" $
'
' Purpose: This script checks for duplicate relationships between agents and servers.
'
' $File: DetectDuplicateRelAgnToSrvMonitor.vbs $
'*************************************************************************



'Declarations
Dim objCN,objRS,strQuery, strRecordsCount
Dim oArgs,oAPI,oBag
Dim strDBServer,strDatabase, strDriverName

'Define local event constants
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

SetLocale("en-us")

'Create objects
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oArgs = WScript.Arguments
Set oBag = oAPI.CreatePropertyBag()
'Define parameters
strDBServer = oArgs(0)
strDatabase = oArgs(1)

Dim ObjError
Set ObjError = New Error

On Error Resume Next

'Set DB connection
Set objCN = CreateObject("ADODB.Connection")
strDriverName = GetSqlDriverName
objCN.Open "Provider="&amp; strDriverName &amp;";Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" &amp; _
strDatabase &amp; ";Data Source=" &amp; strDBServer &amp; ""

ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Error", "Error Number: " &amp; ObjError.number &amp; " Error Details: " &amp; ObjError.Description)
Call oBag.AddValue("RecordsCount", "0")
Call oAPI.Return(oBag)
oAPI.LogScriptEvent "DetectDuplicateRelAgnToSrvMonitor.vbs",100,EVENT_TYPE_ERROR,"Script executed with Error Number: " &amp; ObjError.number &amp; " Error Details: " &amp; ObjError.Description
WScript.Quit
End If


strQuery = "SELECT Count(TT.RecordsCount) As RecordsCount From (SELECT Count(*) AS RecordsCount FROM Relationship R (NoLock) " &amp; _
"JOIN RelationshipType RT (NoLock) " &amp; _
"ON RT.RelationshipTypeId = R.RelationshipTypeId " &amp; _
"JOIN BaseManagedEntity BE1 (NoLock) " &amp; _
"ON R.SourceEntityId = BE1.BaseManagedEntityId " &amp; _
"JOIN BaseManagedEntity BE2 (NoLock) " &amp; _
"ON R.TargetEntityId = BE2.BaseManagedEntityId " &amp; _
"WHERE (RT.RelationshipTypeName = 'Microsoft.SystemCenter.HealthServiceCommunication' " &amp; _
"OR RT.RelationshipTypeName = 'Microsoft.SystemCenter.HealthServiceSecondaryCommunication') " &amp; _
"AND R.IsDeleted = 0 " &amp; _
"group by R.SourceEntityId, R.TargetEntityId, BE1.FullName, BE2.FullName " &amp; _
"having count(*) &gt; 1 ) As TT"

'Query DB
Set objRS = objCN.Execute(strQuery)

ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Error", "Error Number: " &amp; ObjError.number &amp; " Error Details: " &amp; ObjError.Description)
Call oBag.AddValue("RecordsCount", "0")
Call oAPI.Return(oBag)
oAPI.LogScriptEvent "DetectDuplicateRelAgnToSrvMonitor.vbs",100,EVENT_TYPE_ERROR,"Script executed with Error Number: " &amp; ObjError.number &amp; " Error Details: " &amp; ObjError.Description
WScript.Quit
End If

'Set variables
strRecordsCount = objRS("RecordsCount")

Call oBag.AddValue("RecordsCount", strRecordsCount)
oAPI.LogScriptEvent "DetectDuplicateRelAgnToSrvMonitor.vbs",100,EVENT_TYPE_INFORMATION,"Script executed with Duplicate Records Count " &amp; strRecordsCount

'Return property values
Call oAPI.Return(oBag)

Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile

Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub

Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub

Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub

Public Default Property Get Number()
Number = m_lNumber
End Property

Public Property Get Source()
Source = m_sSource
End Property

Public Property Get Description()
Description = m_sDescription
End Property

Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property

Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class
</Script></ScriptBody>
<DatabaseServerName>$Config/DatabaseServerName$</DatabaseServerName>
<DatabaseName>$Config/DatabaseName$</DatabaseName>
<Threshold>0</Threshold>
</ProbeAction>
<ConditionDetection ID="CDHealthy" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">
Property[@Name='RecordsCount']
</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Double">0</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="CDCritical" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Double">
Property[@Name='RecordsCount']
</XPathQuery>
</ValueExpression>
<Operator>Greater</Operator>
<ValueExpression>
<Value Type="Double">0</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="Healthy">
<Node ID="CDHealthy">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="Critical">
<Node ID="CDCritical">
<Node ID="Probe">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
<OnDemandDetections>
<OnDemandDetection MonitorTypeStateID="Healthy">
<Node ID="CDHealthy">
<Node ID="Probe"/>
</Node>
</OnDemandDetection>
<OnDemandDetection MonitorTypeStateID="Critical">
<Node ID="CDCritical">
<Node ID="Probe"/>
</Node>
</OnDemandDetection>
</OnDemandDetections>
</MonitorImplementation>
</UnitMonitorType>