For debugging management pack script issues. Not recommended for general use.
TimeoutSeconds
int
$Config/TimeoutSeconds$
Script Timeout Seconds
Not recommended to override. This value is the length of time individually allowed for each helper script to run within this monitor.
IntervalSeconds
int
$Config/IntervalSeconds$
Script Interval Seconds
Not recommended to override. This number represents how often this monitor should be run. This number does not affect the functionality of the monitor which is to test that the number of messages received has changed by at least 1 in X minutes. Functionality is actually controlled by the 'Schedules' and 'Default Interval Minutes' properties.
dim WRITELINEHEADER
WRITELINEHEADER = "Amalga.2.0.PhysicalServer_discovery_using_serverseed.vbs" & vbcrlf & "Microsoft.Amalga.UIS.2009.PhysicalServer.DiscoveryDataDiscovery" & vbcrlf & "script version: " & SCRIPT_VERSION & vbcrlf & "script start: " & now()
Dim oAPI
set oAPI = CreateObject("MOM.ScriptAPI")
dim LogEnabled
LogEnabled = false
dim DebugEventSource
dim LogEventSource
dim LogSeverity
Dim oArgs
Set oArgs = WScript.Arguments
dim SourceId, ManagedEntityId
SourceId = GetArg(oArgs(0))
ManagedEntityId = GetArg(oArgs(1))
LogSeverity = LOGSEVERITY_INFO
DebugEventSource = "$Config/DebugEventSource$"
if instr(DebugEventSource,"$") then
LogEventSource = "Amalga"
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in DebugEventSource - $ not translated - " & DebugEventSource
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
else
LogEventSource = trim(DebugEventSource & "")
if (LogEventSource = "") then
LogEventSource = "Amalga"
LogEnabled = true
LogSeverity = LOGSEVERITY_WARN
WriteLine "missing DebugEventSource, defaulting to 'Amalga'"
LogEnabled = false
LogSeverity = LOGSEVERITY_INFO
end if
end if
Dim DebugEnabled
DebugEnabled = "$Config/DebugEnabled$"
if instr(DebugEnabled,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in DebugEnabled - $ not translated - " & DebugEnabled
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
DebugEnabled = trim(ucase(DebugEnabled & " "))
LogEnabled = (DebugEnabled = "TRUE")
WriteLine(Now() & " - script version " & SCRIPT_VERSION)
WriteLine("checking arguments...")
DumpArgs(oArgs)
If (oArgs.Count <> EXPECTED_PARAM_COUNT) then '' should be only 2 parameter
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "invalid arg count: " & oArgs.Count & " expected " & EXPECTED_PARAM_COUNT
oArgs = cdate("invalid arg count") ''' intentionally crash
End If
Dim TargetComputer, NetBIOSName, IPAddress, IsVirtualNode, PrincipalName
TargetComputer = "$Config/PrincipalName$"
if instr(TargetComputer,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in TargetComputer - $ not translated - " & TargetComputer
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
PrincipalName = TargetComputer
NetBIOSName = "$Config/NetBIOSComputerName$"
if instr(NetBIOSName,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in NetBIOSName - $ not translated - " & NetBIOSName
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
IPAddress = "$Config/IPAddress$"
if instr(IPAddress,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in IPAddress - $ not translated - " & IPAddress
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
Dim VirtualNodeStr
VirtualNodeStr = "$Config/IsVirtualNode$"
if instr(VirtualNodeStr,"$") then
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "Error in IsVirtualNode - $ not translated - " & IsVirtualNode
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
If (instr(lcase(VirtualNodeStr),"true") > 0) Then
IsVirtualNode = true
Else
IsVirtualNode = false
End If
WriteLine(NetBIOSName)
WriteLine(Now() & " - script version " & SCRIPT_VERSION)
DumpArgs(oArgs)
WriteLine("0: SourceId=" & SourceId)
WriteLine("1: ManagedEntityId=" & ManagedEntityId)
WriteLine("2: TargetComputer=" & TargetComputer)
WriteLine(" PrincipalName=" & PrincipalName)
WriteLine("3: NetBIOSName=" & NetBIOSName)
WriteLine("4: IPAddress=" & IPAddress)
WriteLine("5: IsVirtualNode=" & IsVirtualNode)
WriteLine("6: LogEnabled=" & LogEnabled)
WriteLine "running script on machine: "
dim wshshell, objenv
on error resume next
Set WshShell = CreateObject("WScript.Shell")
Set objEnv = WshShell.Environment("Process")
dim ThisMachineName
ThisMachineName = "" & objEnv("COMPUTERNAME")
WriteLine "This machine's name is: " & ThisMachineName
on error goto 0
WriteLine("checking the registry for the Amalga 2009 key")
dim oReg, strComputer, strKeyPath, arrValueNames, keyfound
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Amalga\2.0\"
If oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " & strKeyPath)
keyfound = true
Else
WriteLine("The registry path does not exist " & strKeyPath)
keyfound = false
end if
''
'' Declare some working variables and then create an empty discovery payload.
''
Dim oDiscoveryData, srvInst, groupInst, relInst, parentseedInst, distributedappInst, configInst, configrollupInst, distconfiggroupInst
Dim oHealthServiceInstance, oHsCnRel
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
dim RoleName, EnvironmentNum
If (keyfound) Then
WriteLine("found Amalga 2009 root key, starting building discovery objects and relationships")
call EnumerateEnvironments()
Else '' not keyfound
'' not keyfound
'' don't add any objects or relationships to the discovery data payload
WriteLine("did not find Amalga 2009 root key, sending an empty payload")
End If
''
'' return the discovery data
''
WriteLine("submitting the discovery data ...")
Call oAPI.Return(oDiscoveryData)
WriteLine("end script.")
'////////////////////////////
sub EnumerateEnvironments()
dim oReg2
dim arrSubKeys
dim Environment
Set oReg2=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
If oReg2.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " & strKeyPath)
Else
WriteLine("The registry path does not exist " & strKeyPath)
WriteLine("defaulting to 'Default'")
Environment = "Default"
call DiscoverObjects(Environment)
exit sub
end if
on error resume next
numSubKeys = UBound(arrSubKeys)
on error goto 0
EnvironmentNum = 0
if (numSubKeys >= 0) then
For EnvironmentNum = 0 to numSubKeys
WriteLine("processing Environment " & EnvironmentNum & "...")
Environment = arrSubKeys(EnvironmentNum)
WriteLine("Environment name: " & Environment)
call DiscoverObjects(Environment)
Next
else
WriteLine("The sub key count for Environments is < 1 (" & numSubKeys & ")")
WriteLine("defaulting to 'Default'")
Environment = "Default"
call DiscoverObjects(Environment)
end if
end sub
'////////////////////////////
sub DiscoverObjects(Environment)
RoleName = "2.0 Physical Server"
if (IsVirtualNode) then
WriteLine ("IsVirtualNode is true, skipping Physical Server discovery for " & TargetComputer)
exit sub
end if
WriteLine ("IsVirtualNode is false, building discovery payload (it's a physical box) for " & TargetComputer)
'' create the environment instance
set distributedappInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.DistributedApp']$")
call distributedappInst.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.DistributedApp']/Environment$", Environment)
call distributedappInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", Environment & " (Amalga UIS 2009)")
call oDiscoveryData.AddInstance(distributedappInst)
'' it's always from a different machine since we're targeting a seed on the RMS, so this if doesn't make sense here:
'' (yes technically we're lying about it being from self node, but this is how we distinguish between physical discovery and
'' discovered physical boxes from within another discovery like DADE discovery
''if (lcase(NetBIOSName) = lcase(ThisMachineName)) then
'' do not supply the DiscoveredFromOtherNode setting in this discovery instance!!
call srvInst.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.PhysicalServer']/DiscoveredFromSelfNode$", "True")
call srvInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", NetBIOSName & " (" & RoleName & ")")
call oDiscoveryData.AddInstance(srvInst)
''
'' To force the RMS to re-assign the local agent as the managing agent for the discovered physical server object (srvInst)
'' we have to get a reference to the local health service class and then create a SPECIAL SECRET relationship :)
set oHsCnRel = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
oHsCnRel.Source = oHealthServiceInstance
oHsCnRel.Target = srvInst
call oDiscoveryData.AddInstance(oHsCnRel)
'' Get the parent seed instance
set parentseedInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerSeed']$")
call parentseedInst.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerSeed']/PrincipalName$", PrincipalName)
call parentseedInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", NetBIOSName)
call oDiscoveryData.AddInstance(parentseedInst)
'' Create the relationship - parent seed : physical server
set relInst = nothing
set relInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerSeed_contains_Amalga.2.0.PhysicalServer']$")
relInst.Source = parentseedInst
relInst.Target = srvInst
call oDiscoveryData.AddInstance(relInst)
'' Create the computer group object
set groupInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.Servers.ComputerGroup']$")
call groupInst.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.Servers.ComputerGroup']/GroupName$", "Amalga Physical Servers")
call groupInst.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.Servers.ComputerGroup']/Environment$", Environment)
call groupInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Physical Servers (" & Environment & ")")
call oDiscoveryData.AddInstance(groupInst)
'' Create the relationship - computer group : physical server
set relInst = nothing
set relInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.Servers_computergroup_contains_Amalga.2.0.PhysicalServer']$")
relInst.Source = groupInst
relInst.Target = srvInst
call oDiscoveryData.AddInstance(relInst)
'' Add the computer group to the Distributed App instance
set relInst = nothing
set relInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.DistributedApp_contains_AmalgaServers_computergroup']$")
relInst.Source = distributedappInst
relInst.Target = groupInst
call oDiscoveryData.AddInstance(relInst)
'' create the physical machine's own roles group for this specific environment, and attach it to the physical server instance
dim physicalServerRolesGroup
set physicalServerRolesGroup = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerRolesGroup']$")
call physicalServerRolesGroup.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerRolesGroup']/GroupName$", NetBIOSName & " " & Environment & " Roles")
call physicalServerRolesGroup.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerRolesGroup']/Environment$", Environment)
call physicalServerRolesGroup.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", Environment & " Roles")
call oDiscoveryData.AddInstance(physicalServerRolesGroup)
set relInst = nothing
set relInst = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.Microsoft.Amalga.UIS.2009.PhysicalServer.Contains.Microsoft.Amalga.UIS.2009.ServerRolesGroup']$")
relInst.Source = srvInst
relInst.Target = physicalServerRolesGroup
call oDiscoveryData.AddInstance(relInst)
'' To force the RMS to re-assign the local agent as the managing agent for the discovered physical server object (srvInst)
'' we have to get a reference to the local health service class and then create a SPECIAL SECRET relationship :)
Set oHealthServiceInstance = oDiscoveryData.CreateClassInstance( "$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$" )
call oHealthServiceInstance.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", PrincipalName )
call oDiscoveryData.AddInstance(oHealthServiceInstance)
set oHsCnRel = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
oHsCnRel.Source = oHealthServiceInstance
oHsCnRel.Target = physicalServerRolesGroup
call oDiscoveryData.AddInstance(oHsCnRel)
end sub
'////////////////////////////
function GetArg(quotedarg)
dim s
s = quotedarg
if s <> "" then
if mid(s,1,1) = """" then
s = mid(s,2, len(s)-1)
end if
if mid(s,len(s),1) = """" then
s = mid(s, 1, len(s)-1)
end if
end if
GetArg = s
end function
'////////////////////////////
sub DumpArgs(Args)
dim i
WriteLine("Dumping args as passed in.")
WriteLine("Note: If you see quotes, they are actually part of the argument literal.")
for i = 0 to Args.Count - 1
WriteLine(i & ": " & Args(i))
next
end sub
'////////////////////////////
sub WriteLine(in_line)
if (LogEnabled) then
dim s
s = vbcrlf & "ID: " & ManagedEntityId & vbcrlf & WRITELINEHEADER & vbcrlf & vbcrlf & in_line
wscript.echo in_line
call oAPI.LogScriptEvent(LogEventSource, 100, LogSeverity, s)
end if
end sub
'////////////////////////////</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>