SCOM System Center Operations Manager VBS VBScript VB Script 클래스 인스턴스 Class Instance Discovery
아래는 특정 레지스트리 키와 문자열 값을 확인해 값이 있으면 해당 클래스의 인스턴스를 생성하고, 값이 없는 경우 다시 미등록 컴퓨터라는 클래스로 빠지게 하는 스크립트다.
' $MPElement$ $Target/Id$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$
Dim oAPI
Set oAPI = CreateObject("MOM.ScriptAPI")
Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count < 3 Then
Call oAPI.LogScriptEvent("AppDiscovery.vbs",101,0, "Arguments Error.")
WScript.Quit -1
End If
Dim SourceID, ManagedEntityId, TargetComputer, oDiscoveryData, oInst
SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputer = oArgs(2)
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
strKeyPath = "SOFTWARE\TEST-SCOM"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Site",strSite
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Process",strProcess
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Line",strLine
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,"Role",strRole
Set oReg=Nothing
If IsNull(strSite) OR IsNull(strProcess) OR IsNull(strLine) OR IsNull(strRole) OR strSite="" OR strProcess="" OR strLine="" OR strRole="" Then
' 미등록 컴퓨터 인스턴스 생성
Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='TEST.Unregistered']$")
Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
Call oDiscoveryData.AddInstance(oInst)
Call oAPI.Return(oDiscoveryData)
WScript.Quit
End If
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each Item in colItems
strVendor = Item.Manufacturer
strModel = Item.Model
Next
Set colItems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
For Each Item in colItems
strOS = Item.Caption
strSP = Item.CSDVersion
Next
Set colItems = Nothing
Set objWMIService = Nothing
' TEST 설비 인스턴스 생성
Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='TEST.ALLEQUIP']$")
Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Site$", strSite)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Process$", strProcess)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Line$", strLine)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Role$", strRole)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Vendor$", strVendor)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/Model$", strModel)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/OS$", strOS)
Call oInst.AddProperty("$MPElement[Name='TEST.ALLEQUIP']/SP$", strSP)
Call oDiscoveryData.AddInstance(oInst)
Call oAPI.Return(oDiscoveryData)
WScript.Quit