Este tipo de monitor detecta las relaciones duplicadas que puedan existir en la base de datos operativa para evitar que los procesos de detección generen un exceso de datos, lo cual podría causar problemas en la actualización de configuraciones.
Knowledge Base article:
Resumen
Tipo de monitor para comprobar si hay relaciones duplicadas entre agentes y servidores.
'*************************************************************************
' $ScriptName: "GetSqlNativeClientComman" $
'
' Purpose: This script is used to get SQL native client Driver name.
'
' $File: GetSqlNativeClientComman.vbs $
'*************************************************************************
Option Explicit
Function GetSqlDriverName
Dim oReg
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_CLASSES_ROOT = &H80000000
Dim strComputer, strDriverPath, strKeyPath, intValue, strValueName,arrSubKeys,oSubkey,strNewKeyPath,intDotIndex, strDriverPathFromHKeyClassRoot
strComputer = "."
strDriverPath="SQLOLEDB"
Set oReg=GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "CLSID\{5A23DE84-1D7B-4A16-8DED-B29C09CB648D}"
'strDriverPathFromHKeyClassRoot is used to check driver MSOLEDBSQL is installed or not. If found MSOLEDBSQL will be returned from function else strDriverPath="SQLOLEDB" will be used for further checking.
oReg.GetStringValue HKEY_CLASSES_ROOT, strKeyPath, "", strDriverPathFromHKeyClassRoot
If strDriverPathFromHKeyClassRoot = "MSOLEDBSQL" Then
GetSqlDriverName = strDriverPathFromHKeyClassRoot
Exit Function
End If
For Each oSubkey In arrSubKeys
intValue = InStr(oSubkey, "SQL Server Native Client")
if intValue <> 0 Then
strValueName = "Driver"
strNewKeyPath = strKeyPath&"\"&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
'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="& strDriverName &";Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" & _
strDatabase & ";Data Source=" & strDBServer & ""
ObjError.Save
On Error Goto 0
If ObjError.Number <> 0 Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Error", "Error Number: " & ObjError.number & " Error Details: " & ObjError.Description)
Call oBag.AddValue("RecordsCount", "0")
Call oAPI.Return(oBag)
oAPI.LogScriptEvent "DetectDuplicateRelAgnToSrvMonitor.vbs",100,EVENT_TYPE_ERROR,"Script executed with Error Number: " & ObjError.number & " Error Details: " & ObjError.Description
WScript.Quit
End If
strQuery = "SELECT Count(TT.RecordsCount) As RecordsCount From (SELECT Count(*) AS RecordsCount FROM Relationship R (NoLock) " & _
"JOIN RelationshipType RT (NoLock) " & _
"ON RT.RelationshipTypeId = R.RelationshipTypeId " & _
"JOIN BaseManagedEntity BE1 (NoLock) " & _
"ON R.SourceEntityId = BE1.BaseManagedEntityId " & _
"JOIN BaseManagedEntity BE2 (NoLock) " & _
"ON R.TargetEntityId = BE2.BaseManagedEntityId " & _
"WHERE (RT.RelationshipTypeName = 'Microsoft.SystemCenter.HealthServiceCommunication' " & _
"OR RT.RelationshipTypeName = 'Microsoft.SystemCenter.HealthServiceSecondaryCommunication') " & _
"AND R.IsDeleted = 0 " & _
"group by R.SourceEntityId, R.TargetEntityId, BE1.FullName, BE2.FullName " & _
"having count(*) > 1 ) As TT"
'Query DB
Set objRS = objCN.Execute(strQuery)
ObjError.Save
On Error Goto 0
If ObjError.Number <> 0 Then
Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue("Error", "Error Number: " & ObjError.number & " Error Details: " & ObjError.Description)
Call oBag.AddValue("RecordsCount", "0")
Call oAPI.Return(oBag)
oAPI.LogScriptEvent "DetectDuplicateRelAgnToSrvMonitor.vbs",100,EVENT_TYPE_ERROR,"Script executed with Error Number: " & ObjError.number & " Error Details: " & ObjError.Description
WScript.Quit
End If
Call oBag.AddValue("RecordsCount", strRecordsCount)
oAPI.LogScriptEvent "DetectDuplicateRelAgnToSrvMonitor.vbs",100,EVENT_TYPE_INFORMATION,"Script executed with Duplicate Records Count " & strRecordsCount
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