Amalga 2009 Physical Server Discovery Data Source

Microsoft.Amalga.UIS.2009.PhysicalServer.DiscoveryDataSource (DataSourceModuleType)

Data Source to Discover Amalga 2009 Physical Server on agents

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
DebugEnabledbool$Config/DebugEnabled$Log EnabledFor debugging management pack script issues. Not recommended for general use.
TimeoutSecondsint$Config/TimeoutSeconds$Script Timeout SecondsNot recommended to override. This value is the length of time individually allowed for each helper script to run within this monitor.
IntervalSecondsint$Config/IntervalSeconds$Script Interval SecondsNot 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.
SyncTimestring$Config/SyncTime$Sync Time

Source Code:

<DataSourceModuleType ID="Microsoft.Amalga.UIS.2009.PhysicalServer.DiscoveryDataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element minOccurs="1" name="DebugEventSource" type="xsd:string"/>
<xsd:element minOccurs="1" name="DebugEnabled" type="xsd:boolean"/>
<xsd:element minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element minOccurs="1" name="PrincipalName" type="xsd:string"/>
<xsd:element minOccurs="1" name="NetBIOSComputerName" type="xsd:string"/>
<xsd:element minOccurs="1" name="IPAddress" type="xsd:string"/>
<xsd:element minOccurs="1" name="IsVirtualNode" type="xsd:string"/>
<xsd:element minOccurs="1" name="SyncTime" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="DebugEnabled" Selector="$Config/DebugEnabled$" ParameterType="bool"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
<ScriptName>Amalga.2.0.PhysicalServer_discovery_using_serverseed_at_agent.vbs</ScriptName>
<Arguments>"$MPElement$" "$Target/Id$"</Arguments>
<ScriptBody><Script>'' Amalga.2.0.PhysicalServer_discovery_using_serverseed.vbs
''

Option Explicit
SetLocale("en-us")

const SCRIPT_VERSION = "1.1"
const EXPECTED_PARAM_COUNT = 2
const LOGSEVERITY_INFO = 4
const LOGSEVERITY_WARN = 2
const LOGSEVERITY_ERROR = 1

dim WRITELINEHEADER
WRITELINEHEADER = "Amalga.2.0.PhysicalServer_discovery_using_serverseed.vbs" &amp; vbcrlf &amp; "Microsoft.Amalga.UIS.2009.PhysicalServer.DiscoveryDataDiscovery" &amp; vbcrlf &amp; "script version: " &amp; SCRIPT_VERSION &amp; vbcrlf &amp; "script start: " &amp; 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 - " &amp; DebugEventSource
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
else
LogEventSource = trim(DebugEventSource &amp; "")
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 - " &amp; DebugEnabled
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if
DebugEnabled = trim(ucase(DebugEnabled &amp; " "))
LogEnabled = (DebugEnabled = "TRUE")

WriteLine(Now() &amp; " - script version " &amp; SCRIPT_VERSION)

WriteLine("checking arguments...")
DumpArgs(oArgs)
If (oArgs.Count &lt;&gt; EXPECTED_PARAM_COUNT) then '' should be only 2 parameter
LogEnabled = true
LogSeverity = LOGSEVERITY_ERROR
WriteLine "invalid arg count: " &amp; oArgs.Count &amp; " expected " &amp; 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 - " &amp; 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 - " &amp; 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 - " &amp; 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 - " &amp; IsVirtualNode
cdate("unexpected error - macro subsitution did not happen") ''' intentionally crash
end if

If (instr(lcase(VirtualNodeStr),"true") &gt; 0) Then
IsVirtualNode = true
Else
IsVirtualNode = false
End If

WriteLine(NetBIOSName)

WriteLine(Now() &amp; " - script version " &amp; SCRIPT_VERSION)
DumpArgs(oArgs)

WriteLine("0: SourceId=" &amp; SourceId)
WriteLine("1: ManagedEntityId=" &amp; ManagedEntityId)
WriteLine("2: TargetComputer=" &amp; TargetComputer)
WriteLine(" PrincipalName=" &amp; PrincipalName)
WriteLine("3: NetBIOSName=" &amp; NetBIOSName)
WriteLine("4: IPAddress=" &amp; IPAddress)
WriteLine("5: IsVirtualNode=" &amp; IsVirtualNode)
WriteLine("6: LogEnabled=" &amp; 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 = "" &amp; objEnv("COMPUTERNAME")
WriteLine "This machine's name is: " &amp; ThisMachineName
on error goto 0


WriteLine("checking the registry for the Amalga 2009 key")

dim oReg, strComputer, strKeyPath, arrValueNames, keyfound

Const HKEY_LOCAL_MACHINE = &amp;H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")


strKeyPath = "SOFTWARE\Microsoft\Amalga\2.0\"

If oReg.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " &amp; strKeyPath)
keyfound = true
Else
WriteLine("The registry path does not exist " &amp; 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}!\\" &amp; _
strComputer &amp; "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Amalga\SCOM\Environments\"
oReg2.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

If oReg2.EnumKey (HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames) = 0 Then
WriteLine("The registry path exists " &amp; strKeyPath)
Else
WriteLine("The registry path does not exist " &amp; strKeyPath)
WriteLine("defaulting to 'Default'")
Environment = "Default"
call DiscoverObjects(Environment)
exit sub
end if

strKeyPath = "SOFTWARE\Microsoft\Amalga\SCOM\Environments"
oReg2.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

dim numSubKeys
numSubKeys = -1

on error resume next
numSubKeys = UBound(arrSubKeys)
on error goto 0

EnvironmentNum = 0

if (numSubKeys &gt;= 0) then
For EnvironmentNum = 0 to numSubKeys
WriteLine("processing Environment " &amp; EnvironmentNum &amp; "...")
Environment = arrSubKeys(EnvironmentNum)
WriteLine("Environment name: " &amp; Environment)
call DiscoverObjects(Environment)
Next
else
WriteLine("The sub key count for Environments is &lt; 1 (" &amp; numSubKeys &amp; ")")
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 " &amp; TargetComputer)
exit sub
end if

WriteLine ("IsVirtualNode is false, building discovery payload (it's a physical box) for " &amp; 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 &amp; " (Amalga UIS 2009)")
call oDiscoveryData.AddInstance(distributedappInst)


'' create the Server
set srvInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Amalga.UIS.2009.PhysicalServer']$")
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.ApplicationComponent']/ClassName$", "Microsoft.Amalga.UIS.2009.PhysicalServer")
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.PhysicalServer']/PrincipalName$", PrincipalName)
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.PhysicalServer']/Environment$", Environment)
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.PhysicalServer']/NetBIOSComputerName$", NetBIOSName)
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.PhysicalServer']/BoxEnvNum$", EnvironmentNum)
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.ApplicationComponent']/EventSourceName$", "Amalga")
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.ApplicationComponent']/EventLogName$", "Amalga")
call srvInst.AddProperty("$MPElement[Name='AmalgaLib!Microsoft.Amalga.Library.ApplicationComponent']/AgentName$", PrincipalName)
call srvInst.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.PhysicalServer']/IP$", IPAddress)

'' 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 &amp; " (" &amp; RoleName &amp; ")")
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 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 = 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 (" &amp; Environment &amp; ")")
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 &amp; " " &amp; Environment &amp; " Roles")
call physicalServerRolesGroup.AddProperty("$MPElement[Name='Microsoft.Amalga.UIS.2009.ServerRolesGroup']/Environment$", Environment)
call physicalServerRolesGroup.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", Environment &amp; " 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 &lt;&gt; "" 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 &amp; ": " &amp; Args(i))
next

end sub

'////////////////////////////
sub WriteLine(in_line)

if (LogEnabled) then
dim s
s = vbcrlf &amp; "ID: " &amp; ManagedEntityId &amp; vbcrlf &amp; WRITELINEHEADER &amp; vbcrlf &amp; vbcrlf &amp; 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>