Découvre les propriétés de Microsoft System Center Service Manager.
Knowledge Base article:
Résumé
Cette découverte remplit les propriétés de Service Manager. La découverte s’exécute immédiatement après l’importation, puis de nouveau à 13:00, heure de la synchronisation. Après cela, elle s’exécute toutes les 24 heures. L’heure de synchronisation, la fréquence et le délai d’expiration sont modifiables. La modification des arguments n’est pas recommandée.
'*************************************************************************
' ScriptName: ManagementServerPropertyDiscovery.vbs
'
' Purpose - Populate properties of SM Management Server
'
' Parameters - 0 - discovery id
' 1 - Target managed entity id
' 2 - Host Computer Principal Name
' 3 - Version
'*************************************************************************
Option Explicit
SetLocale("en-us")
On Error Resume Next
Dim oAPI, sourceId, managedEntityId, hostCompPrincipalName, discoveryData, serverRunningWorkflows, isRunningWorkflows, version
'Creating discovery data
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Starting discovery of Service Manager Management Server Properties.")
Set discoveryData = oAPI.CreateDiscoveryData(0, sourceId, managedEntityId)
'Get management group name from registry
Dim oReg, iResult, arrSubKeys, managementGroupName, oMgtServer, smDbHostName, smDbName
Set oReg = GetObject("winmgmts:\\" & hostCompPrincipalName & "\root\default:StdRegProv")
If Err <> 0 Then
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Unable to bind to WMI registry provider on " & hostCompPrincipalName & ". Terminating Discovery.")
Call oAPI.Return(discoveryData)
WScript.Quit
End if
Const HKLM = &H80000002
If version = "2010" or version = "2012" then
iResult = oReg.Enumkey(HKLM, "SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Server Management Groups", arrSubKeys)
If iResult = 0 then
managementGroupName = arrSubKeys(0)
iResult = oReg.GetStringValue(HKLM, "SOFTWARE\Microsoft\System Center\2010\Common\Database", "DatabaseServerName", smDbHostName)
If iResult = 0 then
iResult = oReg.GetStringValue(HKLM, "SOFTWARE\Microsoft\System Center\2010\Common\Database", "DatabaseName", smDbName)
If iResult = 0 then
'Instantiate Management Server Class
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Discovered SCSM " & version & " Management Server Properties.")
If version = "2010" then
Set oMgtServer = discoveryData.CreateClassInstance("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer.2010']$")
ElseIf version = "2012" then
Set oMgtServer = discoveryData.CreateClassInstance("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer.2012']$")
End If
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.ManagementServer']/ManagementGroupName$", managementGroupName)
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer']/SmDbHostName$", smDbHostName)
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer']/SMDbName$", smDbName)
Call oMgtServer.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",hostCompPrincipalName)
Dim connectionString, cnADOConnection, oResults,oQuery,sourceName
connectionString = "Provider=SQLOLEDB.1; Data Source=" & smDbHostName & "; Trusted_Connection=Yes; Initial Catalog=" & smDbName & ";"
Set cnADOConnection = CreateObject("ADODB.Connection")
cnADOConnection.Open connectionString
cnADOConnection.CommandTimeout = 300
oQuery = "select CONVERT(nvarchar(4000),B.Name) as ServerName from ScopedInstanceTargetClass SCT inner join ManagedType MT on MT.ManagedTypeId = SCT.ManagedTypeId inner join BaseManagedEntity B on B.BaseManagedEntityId = SCT.ScopedInstanceId where MT.TypeName ='Microsoft.SystemCenter.WorkflowTarget'"
Set oResults = CreateObject("ADODB.Recordset")
oResults.Open oQuery, cnADOConnection, 3, 3
If oResults.State <> 0 and oResults.RecordCount > 0 Then
Do Until oResults.EOF
serverRunningWorkflows = oResults.Fields("ServerName")
oResults.MoveNext
Loop
End If
If oResults.State <> 0 Then
oResults.Close
End If
cnADOConnection.Close
if(isEmpty(serverRunningWorkflows)) Then
serverRunningWorkflows = ""
End If
If LCase(hostCompPrincipalName) = LCase(serverRunningWorkflows) then
isRunningWorkflows = true
Else
isRunningWorkflows = false
End If
Call oMgtServer.AddProperty("$MPElement[Name='SM!Microsoft.SystemCenter.ServiceManager.SmManagementServer']/isRunningWorkflows$",isRunningWorkflows)
Call discoveryData.AddInstance(oMgtServer)
End If
End If
End If
End If
Call oAPI.Return(discoveryData)
Call oAPI.LogScriptEvent("ManagementServerPropertyDiscovery.vbs", 3000, 4, "Finishined Discovering SCSM " & version &" Management Server Properties.")
WScript.Quit