Configuration for Wildfly 8.x application server on Windows

Microsoft.JEE.Wildfly.8.Windows.Configuration.Discovery (Discovery)

Discovers JBoss application server configurations on Windows.

Knowledge Base article:

Summary

The configuration discovery locates configurations for JBoss application server. After they have been discovered, a monitoring template should be applied to enable monitoring.

Element properties:

TargetMicrosoft.Windows.Server.Computer
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

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

Source Code:

<Discovery ID="Microsoft.JEE.Wildfly.8.Windows.Configuration.Discovery" Target="Windows!Microsoft.Windows.Server.Computer" Remotable="true" Enabled="true">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Microsoft.JEE.Wildfly.8.Windows.Configuration"/>
<DiscoveryRelationship TypeID="Microsoft.JEE.Wildfly.8.WindowsComputerContainsConfiguration.Relationship"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>14400</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.JEE.Wildfly.8.Discover.vbs</ScriptName>
<Arguments>$Target/ManagementGroup/Id$ $MPElement$ $Target/Id$ "$MPElement[Name='Microsoft.JEE.Wildfly.8.WindowsComputerContainsConfiguration.Relationship']$" $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $MPElement[Name='Microsoft.JEE.Wildfly.8.Windows.Configuration']$</Arguments>
<ScriptBody><Script>
''' Copyright (c) Microsoft Corporation. All rights reserved.
'''
''' Date Created: Mar 21st, 2011
'
SetLocale("en-us")
'' Check if a file is too big (larger than or equal to 100 MB).
'' Return true if too big, else return false.
'' If a file does not exist, return false.
FUNCTION isFileTooBig(userSuppliedFSO, filePath, fileName)
''Set the maximum file size to 100MB
const maxFileSize = 104857600
Dim strFile, myFSO
isFileTooBig = false
strFile = filePath &amp; fileName
IF userSuppliedFSO is Nothing THEN
SET myFSO = CreateObject("Scripting.FileSystemObject")
ELSE
SET myFSO = userSuppliedFSO
END IF
IF myFSO.FileExists(strFile) = true then
'' Get a File object from a file system
set objFile = myFSO.GetFile(strFile)
'' Get the file size
fileSize = objFile.Size
IF fileSize &gt;= maxFileSize THEN
isFileTooBig = true
END IF
END IF
END FUNCTION
'
' Method to parse out a command line arguments
' The arguments can be
'
'
Function ParseOutCommandLineArg(cmdLine, arg)
Dim done
Dim pos
Dim quoted
Dim startpos
Dim gotKey
gotkey = false
quoted = false
pos = 1
startpos = 1
done = false
While not done
Select Case mid ( cmdLine , pos , 1 )
Case ""&amp;chr(34)
If gotkey and quoted Then
ParseOutCommandLineArg = mid(cmdLine,startpos,pos-startpos)
done = true
else
quoted = not quoted
End If
startpos = pos+1
Case "="
If arg = mid(cmdline,startpos,pos-startpos) Then
startpos = pos+1
gotkey = true
End If
Case " "
If gotkey Then
If not quoted Then
ParseOutCommandLineArg = mid(cmdLine,startpos,pos-startpos)
done = true
End If
Else
If arg = mid(cmdline,startpos,pos-startpos) Then
startpos = pos+1
gotkey = true
End If
End If
If not quoted Then
startpos = pos+1
End If
End Select
pos = pos + 1
if not done then
if pos &gt;len(cmdLine) Then
If gotkey Then
If not quoted Then
ParseOutCommandLineArg = mid(cmdLine,startpos,pos-startpos)
done = true
End If
End If
done = true
End If
End If
Wend
End Function
'
' Method to log an error to the windows event log
'
Function LogError(oAPI, scriptName, description)
Call oAPI.LogScriptEvent(scriptName, 100, 1, description)
End Function
'
' Method to log an error when failing to find a file
'
Function LogErrorFileNotFound(oAPI, scriptName, fileName)
LogError oAPI, scriptName, "Could not find expected configuration file: " &amp; fileName
End Function
'
' Method to log an error when failing to find a folder
'
Function LogErrorFolderNotFound(oAPI, scriptName, folderName)
LogError oAPI, scriptName, "Could not find expected folder: " &amp; folderName
End Function
'
' Method to log an error when failing to parse a file
'
Function LogErrorParsingFile(oAPI, scriptName, fileName)
LogError oAPI, scriptName, "Failed to parse configuration file: " &amp; fileName
End Function
'
' Method to log an error when failing to commuincate over HTTP
'
Function LogErrorHTTP(oAPI, scriptName, url, description, errorNumber)
LogError oAPI, scriptName, "HTTP commucation failed with: " &amp; url &amp; " - " &amp; description &amp; " - " &amp; CStr(errorNumber)
End Function

'' Copyright (c) Microsoft Corporation. All rights reserved.
'''
''' Filters out discovered instances that do not match the specified major version
''' Returns true if the desired version is the Major version.
'''
''' i.e. if desired major version is 6 and given 6.0.22, the result is true.
''' if desired major version is 6 and given 5.0.12, the result is false
'''
PUBLIC FUNCTION FilterVersion(strDesiredMajorVersion, strActualVersion)
FilterVersion = FALSE
' Filter out specific version.
' Need to be careful that the given filter is not longer
' than the string to be filtered, otherwise just make sure that
' what is at the beginning of one string matches the filter
IF (0 &lt; Len(strDesiredMajorVersion)) AND (Len(strDesiredMajorVersion) &lt;= Len(strActualVersion)) THEN
IF (0 = StrComp(strDesiredMajorVersion, Left(strActualVersion, Len(strDesiredMajorVersion)))) THEN
FilterVersion = TRUE
END IF
END IF
END FUNCTION

''' Copyright (c) Microsoft Corporation. All rights reserved.
''' Date Created: July 29th, 2010
'
SetLocale("en-us")
'''
''' Constants for Registry Access
'''
CONST HKEY_LOCAL_MACHINE = &amp;H80000002
CONST KEY_QUERY_VALUE = &amp;H0001
CONST KEY_SET_VALUE = &amp;H0002
CONST KEY_CREATE_SUB_KEY = &amp;H0004
CONST DELETE = &amp;H00010000
CONST PERSISTED_DISCOVERY = "PersistedDiscovery"
CONST REGISTRY_PROP_APP_SERVER_TYPE = "APPLICATION_SERVER_TYPE"
CONST REGISTRY_PROP_APP_SERVER_TYPE_JBOSS = "JBOSS"
CONST REGISTRY_PROP_APP_SERVER_TYPE_TOMCAT = "TOMCAT"
CONST REGISTRY_PROP_CONFIGURATION = "CONFIGURATION"
CONST REGISTRY_PROP_HTTP_PORT = "HTTP_PORT"
CONST REGISTRY_PROP_HTTPS_PORT = "HTTPS_PORT"
CONST REGISTRY_PROP_PATH = "PATH"
CONST REGISTRY_PROP_VERSION = "VERSION"
'''
''' Simple CLASS defining all the Discovery data
'''
CLASS ApplicationServerDiscoveryInfo
PUBLIC DiscoveredInstances
PUBLIC RegistryAdds
PUBLIC RegistryDeletes
PRIVATE SUB CLASS_initialize()
SET DiscoveredInstances = CreateObject("Scripting.Dictionary")
SET RegistryAdds = CreateObject("Scripting.Dictionary")
SET RegistryDeletes = CreateObject("Scripting.Dictionary")
END SUB
END CLASS
'
' Class to abstractly represent information for discovery data that
' can be used to populate the registry as well as Operations Mangaer.
' This is shared between the registry, Tomcat, and JBoss scripts.
'
CLASS ApplicationServerInstance
PUBLIC AppServerType
PUBLIC Configuration
PUBLIC HttpPort
PUBLIC HttpsPort
PUBLIC Version
PRIVATE SUB CLASS_INITIALIZE()
AppServerType = "Undefined"
Configuration = "Undefined"
HttpPort = "0"
HttpsPort = "0"
Version = "0"
END SUB
'
' Generate a unique key that can be used internally
' for updating the registry with discovered instances.
'
PUBLIC FUNCTION GetKey()
GetKey = Configuration
END FUNCTION
'
' A Compare method to determine if the this current object
' matches the given argument (expecting the argument to be
' of the same type.
'
PUBLIC FUNCTION Matches(otherAppSrv)
Matches = FALSE
IF (Not (otherAppSrv IS NOTHING)) THEN
IF (AppServerType = otherAppSrv.AppServerType) AND (Configuration = LCase(otherAppSrv.Configuration)) AND (HttpPort = otherAppSrv.HttpPort) AND (HttpsPort = otherAppSrv.HttpsPort) AND (Version = otherAppSrv.Version) THEN
Matches = TRUE
END IF
END IF
END FUNCTION
END CLASS
'
' Registry C.R.U.D.
' Create
' Read
' Update
' Delete
'
CLASS RegistryCrud
PUBLIC objRegistry
PUBLIC DesiredApplicationServerType
PUBLIC ManagementGroup
PUBLIC objScriptAPI
PRIVATE SUB class_initialize()
SET objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
ManagementGroup = "Default"
END SUB
PRIVATE FUNCTION GetBaseRegistryPath()
IF objScriptAPI IS NOTHING THEN
SET objScriptAPI = CreateObject("MOM.ScriptAPI")
END IF
GetBaseRegistryPath = objScriptAPI.GetScriptStateKeyPath(ManagementGroup)
END FUNCTION
PRIVATE FUNCTION GetPersistedDiscoveryRegistryPath()
GetPersistedDiscoveryRegistryPath = GetBaseRegistryPath() &amp; "\" &amp; PERSISTED_DISCOVERY
END FUNCTION
'
' A boolean FUNCTION that checks IF the given registry key has sub keys.
' Returns true IF the key exisits, otherwise false
'
FUNCTION CheckIfRegistryKeyHasSubKeys(keyToCheck)
DIM arrSubKeys
objRegistry.EnumKey HKEY_LOCAL_MACHINE, keyToCheck, arrSubKeys
DIM returnValue
returnValue = FALSE
IF NOT IsNull(arrSubKeys) THEN
returnValue = TRUE
END IF
CheckIfRegistryKeyHasSubKeys = returnValue
END FUNCTION
FUNCTION GetListOfRegistryEntries()
SET GetListOfRegistryEntries = ReadRegistryForPreviouslyDiscoveredAppServers(ManagementGroup)
END FUNCTION
'
' Look in registry and return a list of the previously
' known items.
'
FUNCTION ReadRegistryForPreviouslyDiscoveredAppServers(ManagementGroup)
DIM returnValue
SET returnValue = CreateObject("Scripting.Dictionary")
DIM PersistentRegKey
PersistentRegKey = GetPersistedDiscoveryRegistryPath()
IF CheckIfRegistryKeyHasSubKeys(PersistentRegKey) THEN
' Registry key exists, so loop through the entries and
' place this information into the discovery objects.
DIM arrSubKeys
objRegistry.EnumKey HKEY_LOCAL_MACHINE, PersistentRegKey, arrSubKeys
IF NOT IsNull(arrSubKeys) THEN
DIM subKey
FOR EACH subKey In arrSubKeys
DIM theKey, foundEntry, strValueName, strValue
SET foundEntry = NEW ApplicationServerInstance
'
' To determine a unique instance, a string representing a combination
' of HTTP and HTTPS ports will be used
'
DIM fullSubKey
fullSubKey = PersistentRegKey &amp; "\" &amp; subKey
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_APP_SERVER_TYPE, strValue
foundEntry.AppServerType = strValue
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_CONFIGURATION, strValue
foundEntry.Configuration = LCase(strValue)
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_HTTP_PORT, strValue
foundEntry.HttpPort = strValue
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_HTTPS_PORT, strValue
foundEntry.HttpsPort = strValue
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_VERSION, strValue
foundEntry.Version = strValue
IF DesiredApplicationServerType = foundEntry.AppServerType THEN
returnValue.Add foundEntry.GetKey, foundEntry
END IF
Next
END IF
END IF
SET ReadRegistryForPreviouslyDiscoveredAppServers = returnValue
END FUNCTION
'
' Remove the supplied entries from the Registry
'
' Parameter ListOfDeletes: a dictionary that contains a list
' of name/value of path/string that represents a list of objects
' to delete from the Registry. The value is not used, only the
' key is important to this function.
'
FUNCTION UpdateRegistryWithDeletedAppServers(ListOfDeletes)
DIM PersistentRegKey
PersistentRegKey = GetPersistedDiscoveryRegistryPath()
IF CheckIfRegistryKeyHasSubKeys(PersistentRegKey) THEN
DIM itemToDelete
FOR EACH itemToDelete IN ListOfDeletes
' The current item is of a type ApplicationServerInstance
DIM currentItem
SET currentItem = ListOfDeletes.Item(itemToDelete)
DIM keyToDelete
keyToDelete = "NotFound"
'
' For each of the items in the registry, we need to examine if the current entry
' matches all of the discovery items. If everything exactly matches, then delete
' the item from the registry.
'
' Registry key exists, so loop through the entries and
' place this information into the discovery objects.
DIM arrSubKeys
objRegistry.EnumKey HKEY_LOCAL_MACHINE, PersistentRegKey, arrSubKeys
IF NOT IsNull(arrSubKeys) THEN
DIM subKey
FOR EACH subKey In arrSubKeys
DIM fullSubKey
fullSubKey = PersistentRegKey &amp; "\" &amp; subKey
DIM entryAppServerType, entryConfiguration, entryHttpPort, entryHttpsPort, entryPath, entryVersion
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_APP_SERVER_TYPE, entryAppServerType
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_CONFIGURATION, entryConfiguration
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_HTTP_PORT, entryHttpPort
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_HTTPS_PORT, entryHttpsPort
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_PATH, entryPath
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, fullSubKey, REGISTRY_PROP_VERSION, entryVersion
IF (entryAppServerType = currentItem.AppServerType) AND (entryConfiguration = currentItem.Configuration) AND (entryHttpPort = currentItem.HttpPort) AND (entryHttpsPort = currentItem.HttpsPort) AND (entryVersion = currentItem.Version) THEN
keyToDelete = fullSubKey
EXIT FOR
END IF
NEXT
END IF
objRegistry.DeleteKey HKEY_LOCAL_MACHINE, keyToDelete
NEXT
END IF
END FUNCTION
'
' Add the supplied entries to the registry
'
' Parameter ListOfAdds: a dictionary that contains a list
' of name/value of path/Discovery-Object that
'
FUNCTION UpdateRegistryWithNewlyAddedAppServers(ListOfAdds)
DIM baseRegSubKeyToAdd
baseRegSubKeyToAdd = GetBaseRegistryPath()
objRegistry.CreateKey HKEY_LOCAL_MACHINE, baseRegSubKeyToAdd
baseRegSubKeyToAdd = baseRegSubKeyToAdd &amp; "\" &amp; PERSISTED_DISCOVERY
objRegistry.CreateKey HKEY_LOCAL_MACHINE, baseRegSubKeyToAdd
DIM entry
FOR EACH entry IN ListOfAdds
DIM regSubKeyToAdd
regSubKeyToAdd = baseRegSubKeyToAdd
'
' Registry Key should look like:
'
' SOFTWARE\Microsoft\Microsoft Operations Manager\3.0\Modules\Default\S-1-5-21-124525095-708259637-1543119021-711584\Script\PersistedDiscovery\{A GUID}
'
' Turns out the GUID returned in a struct and not a string, hence the
' shell game of getting the object and then removing the last two parts.
' Also it is important to set the typeLib back to nothing as otherwise you
' will get the same GUID again(!) - see Bug #36417
DIM typeLib, objGuid, strGuid
SET typeLib = CreateObject("Scriptlet.TypeLib")
objGuid = typeLib.Guid
strGuid = Left(objGuid, Len(objGuid)-2)
SET typeLib = Nothing
regSubKeyToAdd = regSubKeyToAdd &amp; "\" &amp; strGuid
objRegistry.CreateKey HKEY_LOCAL_MACHINE, regSubKeyToAdd
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, regSubKeyToAdd, REGISTRY_PROP_APP_SERVER_TYPE, ListOfAdds.Item(entry).AppServerType
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, regSubKeyToAdd, REGISTRY_PROP_CONFIGURATION, LCase(ListOfAdds.Item(entry).Configuration)
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, regSubKeyToAdd, REGISTRY_PROP_HTTP_PORT, ListOfAdds.Item(entry).HttpPort
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, regSubKeyToAdd, REGISTRY_PROP_HTTPS_PORT, ListOfAdds.Item(entry).HttpsPort
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, regSubKeyToAdd, REGISTRY_PROP_VERSION, ListOfAdds.Item(entry).Version
NEXT
END FUNCTION
END CLASS
'
' Public interface to that the Tomcat and JBoss code will call
' to persist the running processes (for the actual algorithm
' details, see below).
'
' Parameter 1: Object which returns back a list of object representing running
' application server processes.
' Parameter 2: Management Group Name
' Parameter 3: File system object. For production code, leave this as NOTHING
'
FUNCTION DiscoveryWithPersistence(userSuppliedWmi, userSuppliedRegistry, userSuppliedMomApi, strManagementGroupName, strAppSrvType, userSuppliedFileSystemObject)
DIM algorithmOutput
DIM registryUpdater
SET registryUpdater = NEW RegistryCrud
IF NOT (userSuppliedRegistry IS NOTHING) THEN
SET registryUpdater.objRegistry = userSuppliedRegistry
END IF
IF (userSuppliedMomApi IS NOTHING) THEN
SET registryUpdater.objScriptAPI = CreateObject("MOM.ScriptAPI")
ELSE
SET registryUpdater.objScriptAPI = userSuppliedMomApi
END IF
registryUpdater.DesiredApplicationServerType = strAppSrvType
registryUpdater.ManagementGroup = strManagementGroupName
SET algorithmOutput = DiscoveryWithPersistenceAlgorithm(userSuppliedWmi, registryUpdater, userSuppliedFileSystemObject)
registryUpdater.UpdateRegistryWithDeletedAppServers(algorithmOutput.RegistryDeletes)
registryUpdater.UpdateRegistryWithNewlyAddedAppServers(algorithmOutput.RegistryAdds)
SET DiscoveryWithPersistence = algorithmOutput.DiscoveredInstances
END FUNCTION
'
' 1) Query WMI for a list of java processes, add this to list A
' 2) Query for registry and to get a list of the previously known instances, add this to list B
' 3) For each entry in A, create a discovery item
' 4) For each entry in A, find a corresponding entry for B
' a. If the entry is there, remove the entry from B
' A match is where the path, all ports match, and version matches
' b. If there is not a entry, add this to the addToRegistry list
' c. Assumption: when this step completes, B will only contain a list of entries that are not running either because they have been stopped or removed
' 5) For each entry in B, verify that the directory still exists
' a. If the entries "path to installation" folder exists, create a discovery item (this instance is currently stopped)
' b. If the entries "path to installation" folder does not exists, add this to the deleteFromRegistry list
' 6) Update registry
' a. Remove out-dated registry items
' b. Add new registry items for "first-time-run" processes
'
FUNCTION DiscoveryWithPersistenceAlgorithm(userSuppliedWmi, userSuppliedRegistry, userSuppliedFileSystemObject)
DIM objDiscoveryResults
SET objDiscoveryResults = NEW ApplicationServerDiscoveryInfo
DIM listOfDiscoveryData, listOfAddToRegistry, listOfDeleteFromRegistry
DIM listOfCurrentRunningProcesses, listOfCurrentRegistryEntries
SET listOfDiscoveryData = CreateObject("Scripting.Dictionary")
SET listOfAddToRegistry = CreateObject("Scripting.Dictionary")
SET listOfDeleteFromRegistry = CreateObject("Scripting.Dictionary")
SET listOfCurrentRunningProcesses = GetListOfRunningInstances(userSuppliedWmi)
SET listOfCurrentRegistryEntries = GetListOfRegistryEntries(userSuppliedRegistry)
DIM runningProcess, runningProcessInLowerCase
'
' For running process, create a discovery item. Also for each process,
' check IF there is a corresponding registry entry. IF there is an entry,
' remove it so we can narrow down the list of out-of-date registry entries.
' IF a running process does not have an entry in the registry list, then it
' is NEW and a entry should be added to the registry.
'
FOR EACH runningProcess IN listOfCurrentRunningProcesses
'
' All running processes should have a discovery item.
'
runningProcessInLowerCase = LCase(runningProcess)
listOfDiscoveryData.Add runningProcessInLowerCase, CopyApplicationServerInstance(listOfCurrentRunningProcesses.Item(runningProcess))
'
' IF a key exists in the registry representation, remove it (because that means)
' the cached value is correct. IF there is a miss, this this value is "new" and
' should be added to the registry/cache
'
' This is a workaround. So it turns out that if you call Item(a) on
' a dictionary and the key is NOT in the dictionary, an entry will
' be added. The key will 'a' and the value will be Empty. This is a
' problem. The code assumes that the value is an object and mixing
' Empty and Nothing does work.
'
' To bypass this troublesome scenaro, the code below will insert a NOTHING
' just to be safe. This is a workaround, and elsewhere we must not rely
' on the Exists function.
'
DIM keyExistsInRegistry
keyExistsInRegistry = listOfCurrentRegistryEntries.Exists(runningProcessInLowerCase)
IF NOT keyExistsInRegistry THEN
SET listOfCurrentRegistryEntries.Item(runningProcessInLowerCase) = NOTHING
END IF
IF keyExistsInRegistry AND (listOfDiscoveryData.Item(runningProcessInLowerCase).Matches(CopyApplicationServerInstance(listOfCurrentRegistryEntries.Item(runningProcessInLowerCase)))) THEN
listOfCurrentRegistryEntries.Remove runningProcessInLowerCase
ELSE
listOfAddToRegistry.Add runningProcessInLowerCase, CopyApplicationServerInstance(listOfCurrentRunningProcesses.Item(runningProcess))
END IF
NEXT
'
' Assumption: now that the above loop has completed, the
' listOfCurrentRegistryEntries should only contain a list of
' entries that are not running either because the instance
' has been stopped or deleted.
'
DIM fso
IF userSuppliedFileSystemObject Is Nothing Then
SET fso = CreateObject("Scripting.FileSystemObject")
ELSE
SET fso = userSuppliedFileSystemObject
END IF
'
' For each entry in listOfCurrentRegistryEntries, verify that the
' directory still exists. IF the entry's "path to installation"
' folder exists and if there is not already an entry (i.e. a port change),
' create a discovery item (because this instance is
' currently stopped). IF the entry's "path to installation" folder
' does NOT exists, then the instance has been deleted and the registry
' entry should be removed.
'
DIM remainingRegistryEntry
FOR EACH remainingRegistryEntry IN listOfCurrentRegistryEntries
'
' Due to how the Item method works, if the value is not available an Empty
' is inserted into the dictionary. To work around this, other parts of the
' code replace this with NOTHING so that the VBScript won't break. This
' IF statement is necessary to bypass that workaround.
'
IF NOT listOfCurrentRegistryEntries.Item(remainingRegistryEntry) IS NOTHING THEN
IF fso.FolderExists(listOfCurrentRegistryEntries.Item(remainingRegistryEntry).Configuration) AND (NOT listOfDiscoveryData.Exists(remainingRegistryEntry)) THEN
listOfDiscoveryData.Add remainingRegistryEntry, CopyApplicationServerInstance(listOfCurrentRegistryEntries.Item(remainingRegistryEntry))
ELSE
listOfDeleteFromRegistry.Add remainingRegistryEntry, CopyApplicationServerInstance(listOfCurrentRegistryEntries.Item(remainingRegistryEntry))
END IF
END IF
NEXT
SET objDiscoveryResults.DiscoveredInstances = listOfDiscoveryData
SET objDiscoveryResults.RegistryAdds = listOfAddToRegistry
SET objDiscoveryResults.RegistryDeletes = listOfDeleteFromRegistry
SET DiscoveryWithPersistenceAlgorithm = objDiscoveryResults
END FUNCTION
'
' Helper Method to copy the ApplicationServerInstance object.
' This is necessary b/c VBscript does not support 'shallow' copies
'
FUNCTION CopyApplicationServerInstance(oldAppSrvInstance)
DIM newAppSrvInstance
IF oldAppSrvInstance IS NOTHING THEN
SET newAppSrvInstance = NOTHING
ELSE
SET newAppSrvInstance = NEW ApplicationServerInstance
newAppSrvInstance.AppServerType = oldAppSrvInstance.AppServerType
newAppSrvInstance.Configuration = LCase(oldAppSrvInstance.Configuration)
newAppSrvInstance.HttpPort = oldAppSrvInstance.HttpPort
newAppSrvInstance.HttpsPort = oldAppSrvInstance.HttpsPort
newAppSrvInstance.Version = oldAppSrvInstance.Version
END IF
SET CopyApplicationServerInstance = newAppSrvInstance
END FUNCTION
'
' Abstraction for getting a list of the objects that represent running processes.
' The caller of the DiscoveryWithPersistence() method is expected to supply an object
' that returns a list of these objects. In practice, this is a dictionary where the
' key is path and the value associated is an ApplicationServerInstance object with
' the necessary items to populate a dicovery data item in Operations Manager.
'
PRIVATE FUNCTION GetListOfRunningInstances(userSuppliedWmi)
SET GetListOfRunningInstances = userSuppliedWmi.GetListOfRunningInstances()
END FUNCTION
'
' Abstraction for getting a list of the objects that represent registry
' entries. For the production code, please review the RegistryCrud object.
'
PRIVATE FUNCTION GetListOfRegistryEntries(userSuppliedRegistry)
SET GetListOfRegistryEntries = userSuppliedRegistry.GetListOfRegistryEntries()
END FUNCTION

' Copyright (c) Microsoft Corporation. All rights reserved.
' Date Created: Aug 13th, 2010
'
' This script is to be incorporated into the JBoss JEE MP.
' This script will discover the running java process of JBoss
' Web Application server Configurations.
'
SetLocale("en-us")
'''
''' Simple Class defining the Process Discovery data
Class ProcessInfo
Public Path
Public Configuration
Public ConfigurationPath
Public PortBinding
' Member varaibles for internal use that should not surface to the
' user. Needed as part of the solution for Bug #43159 (long paths
' prevent discovery), where the issue is long human-readible
' name may exceed 260 characters and thus prevent opening of
' the necessary filepaths.
Public ConfigurationShortPath
Public ShortPath
' variable used to determine if the instance is a domain instance
Public isDomainInstance
' Server name in the case of a domain instance
Public domainServerName
End Class
'''
''' Constants for use in this script
'''
Const JBOSS_DISCOVERY_SCRIPT_NAME = "JBossDiscovery.vbs"
'''
''' Simple Class defining the JBoss Configuration Discovery data
'''
Class ConfigurationDiscoveryInfoClass
Public ListOfConfigurations
Private Sub Class_Initialize()
Set ListOfConfigurations = CreateObject("Scripting.Dictionary")
End Sub
Function GetListOfRunningInstances()
Set GetListOfRunningInstances = ListOfConfigurations
End Function
End Class
'
' Simple class defining a set of ports
'
Class Ports
Public HTTPPort
Public HTTPSPort
Public FileTooBig
Private Sub Class_Initialize()
HTTPPort = ""
HTTPSPort = ""
FileTooBig = False
End Sub
End Class
'
' Get the HTTP &amp; HTTPS ports of the JBoss 4 installation that runs a specific configuration from the web deployer
' Do this by getting the value of the ports attribute of the Connector tag with a protocol attribute
' with the value "HTTP/1.1" in the file server.xml located in &lt;configuration&gt;\deploy\jboss-web.deployer
'
Function getJBossWebDeployerPorts (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Dim objXMLDoc, objNodeHTTPS, objNodeHTTP, objPorts, versionNode
Dim strFilePath, strFileName
Set objPorts = New Ports
If userSuppliedXmlDom Is Nothing Then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set objXMLDoc = userSuppliedXmlDom
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
objXMLDoc.async = False
strFilePath = objProcessInfo.ConfigurationShortPath &amp; "\deploy\jboss-web.deployer\"
strFileName = "server.xml"
objPorts.FileTooBig = isFileTooBig(objFso, strFilePath, strFileName)
If objFso.FileExists(strFilePath &amp; strFileName) And Not objPorts.FileTooBig Then
objXMLDoc.load(strFilePath &amp; strFileName)
Set objNodeHTTPS = objXMLDoc.selectSingleNode("/Server/Service/Connector[@protocol=""HTTP/1.1"" and @secure=""true""]")
Set objNodeHTTP = objXMLDoc.selectSingleNode("/Server/Service/Connector[@protocol=""HTTP/1.1"" and not(@secure)]")
If Not objNodeHTTP Is Nothing Then
Set versionNode = objNodeHTTP.attributes.getNamedItem("port")
If Not versionNode Is Nothing Then
objPorts.HTTPPort = versionNode.text
End If
End If
If Not objNodeHTTPS Is Nothing Then
Set versionNode = objNodeHTTPS.attributes.getNamedItem("port")
If Not versionNode Is Nothing Then
objPorts.HTTPSPort = versionNode.text
End If
End If
Else
LogErrorFileNotFound oAPI, JBOSS_DISCOVERY_SCRIPT_NAME, strFilePath &amp; strFileName
End If
Set getJBossWebDeployerPorts = objPorts
End Function
'
' Get the HTTP &amp; HTTPS ports of the JBoss 4 installation that runs a specific configuration
'
Function getJBoss4Ports (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Dim objPorts, objXMLDoc, bindNode, nameNode, fileNode
Dim fileName, portName, configNode, portNode
Dim strFilePath, strFileName
Set objPorts = New Ports
If userSuppliedXmlDom Is Nothing Then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set objXMLDoc = userSuppliedXmlDom
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
objXMLDoc.async = False
strFilePath = objProcessInfo.ConfigurationShortPath &amp; "\conf\"
strFileName = "jboss-service.xml"
objPorts.FileTooBig = isFileTooBig(objFso, strFilePath, strFileName)
If objFso.FileExists(strFilePath &amp; strFileName) And (Not objPorts.FileTooBig) Then
objXMLDoc.load(strFilePath &amp; strFileName)
Set bindNode = objXMLDoc.selectSingleNode("/server/mbean[@code=""org.jboss.services.binding.ServiceBindingManager""]")
If bindNode Is Nothing Then
Set objPorts = getJBossWebDeployerPorts (oAPi, objProcessInfo, objFso, userSuppliedXmlDom)
Else
Set nameNode = bindNode.selectSingleNode("attribute[@name=""ServerName""]")
Set fileNode = bindNode.selectSingleNode("attribute[@name=""StoreURL""]")
If Not fileNode Is Nothing And Not nameNode Is Nothing Then
fileName = Replace(fileNode.text, "${jboss.home.url}", objProcessInfo.Path)
portName = nameNode.text
objXMLDoc.load(fileName)
Set configNode = objXMLDoc.selectSingleNode("/service-bindings/server[@name=""" &amp; portName &amp; """]/service-config[@name=""jboss.web:service=WebServer""]/binding")
If Not configNode Is Nothing Then
Set portNode = configNode.attributes.getNamedItem("port")
If Not portNode Is Nothing Then
objPorts.HTTPPort = portNode.text
objPorts.HTTPSPort = CStr(CInt(portNode.text) + 363)
End If
End If
End If
End If
Else
LogErrorFileNotFound oAPI, JBOSS_DISCOVERY_SCRIPT_NAME, strFilePath &amp; strFileName
End If
Set getJBoss4Ports = objPorts
End Function
'
' Get the HTTP &amp; HTTPS ports of the JBoss 5 installation that runs a specific configuration
' Do this by adding the offset for the port binding to the base ports found in the XML file
' bindings-jboss-beans.xml located in &lt;configuration&gt;\conf\bindingservice.beans\META-INF\
'
Function getJBoss5Ports (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Dim objXMLDoc, objNodeHTTPS, objNodeHTTP, objPorts, setNodes, setNode
Dim foundOffset, paramNodes, offset, foundHttpBase, foundHttpsBase
Dim beanNodes, beanNode, nameNode, portNode, bindNode, httpbase, httpsbase
Dim strFilePath, strFileName
Dim bindingFactory, bindingObjectParameters
Const cBindingSet = "${jboss.service.binding.set:"
Set objPorts = New Ports
If userSuppliedXmlDom Is Nothing Then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set objXMLDoc = userSuppliedXmlDom
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
objXMLDoc.async = False
strFilePath = objProcessInfo.ConfigurationShortPath &amp; "\conf\bindingservice.beans\META-INF\"
strFileName = "bindings-jboss-beans.xml"
objPorts.FileTooBig = isFileTooBig(objFso, strFilePath, strFileName)
If objFso.FileExists(strFilePath &amp; strFileName) And Not objPorts.FileTooBig Then
objXMLDoc.load(strFilePath &amp; strFileName)
' If no portsBinding has been set (no command line option specified) we get the
' assiciated factory from the "ServiceBindingManager". Once we have got the factory we use its value to
' to get the default portsBinding. This is done by getting the properties for the factory and looking for the
' "${jboss.service.binding.set:XXX" value. If we still do not have a portsBinding value we use "ports-default"
' as the value.
If (IsEmpty(objProcessInfo.PortBinding) ) Then
Set bindingFactory = objXMLDoc.selectNodes("/deployment/bean[@name=""ServiceBindingManager""]/constructor[@factoryMethod=""getServiceBindingManager""]/factory/@bean")
If (Not bindingFactory Is Nothing) Then
If ( bindingFactory.length &gt; 0 ) Then
Set bindingObjectParameters = objXMLDoc.selectNodes("/deployment/bean[@name=""" &amp; bindingFactory(0).text &amp; """]/constructor/parameter")
If Not bindingObjectParameters Is Nothing Then
For Each bindingObjectParameter In bindingObjectParameters
If (Left(bindingObjectParameter.text,Len(cBindingSet)) = cBindingSet) Then
objProcessInfo.PortBinding = Mid(bindingObjectParameter.text,InStrRev(bindingObjectParameter.text,":") + 1,Len ( bindingObjectParameter.text ) - InStrRev(bindingObjectParameter.text,":") -1)
End If
Next
End If
End If
End If
End If
' The objProcessInfo.PortBinding is set by either checking the command line switches (GetJBossProcessesInfo) or by
' checking the bindings-jboss-beans.xml file ( code above ).
' If neither process has set the value we will set it to the default value, this can only be done after
' exhausting all other possibilities.
If (IsEmpty(objProcessInfo.PortBinding) ) Then
objProcessInfo.PortBinding = "ports-default"
End If
' Get offset
foundOffset = False
Set setNodes = objXMLDoc.selectNodes("/deployment/bean[@ class=""org.jboss.services.binding.impl.ServiceBindingSet""]")
If Not setNodes Is Nothing Then
For Each setNode In setNodes
Set paramNodes = setNode.selectNodes("constructor/parameter")
If Not paramNodes Is Nothing Then
If paramNodes.length &gt; 2 Then
If paramNodes.item(0).text = objProcessInfo.PortBinding Then
offset = CInt(paramNodes.item(2).text)
foundOffset = True
Exit For
End If
End If
End If
Next
End If
' Get base ports
foundHttpBase = False
foundHttpsBase = False
Set beanNodes = objXMLDoc.selectNodes("/deployment/bean[@name=""StandardBindings""]/constructor/parameter/set/bean")
If Not beanNodes Is Nothing Then
For Each beanNode In beanNodes
Set nameNode = beanNode.selectSingleNode("property[@name=""serviceName""]")
If Not nameNode Is Nothing Then
If nameNode.text = "jboss.web:service=WebServer" Then
Set portNode = beanNode.selectSingleNode("property[@name=""port""]")
Set bindNode = beanNode.selectSingleNode("property[@name=""bindingName""]")
If Not portNode Is Nothing Then
If bindNode Is Nothing Then
httpbase = CInt(portNode.text)
foundHttpBase = True
Else
If bindNode.text = "HttpConnector" Then
httpbase = CInt(portNode.text)
foundHttpBase = True
End If
If bindNode.text = "HttpsConnector" Then
httpsbase = CInt(portNode.text)
foundHttpsBase = True
End If
End If
End If
End If
End If
Next
End If
' Add offset to base
If foundOffset = True Then
If foundHttpBase = True Then
objPorts.HTTPPort = CStr(httpbase + offset)
End If
If foundHttpsBase = True Then
objPorts.HTTPSPort = CStr(httpsbase + offset)
End If
End If
Else
LogErrorFileNotFound oAPI, JBOSS_DISCOVERY_SCRIPT_NAME, strFilePath &amp; strFileName
End If
Set getJBoss5Ports = objPorts
End Function
'
' Get the HTTP and HTTPS ports for a JBoss 7 or Wildfly installation that is running in domain mode
' In order to get the HTTP Ports we must first retrieve the group that the server belongs too, as well as the port offset for each server
' These values both resiode within the host.xml file
'
' We then look within domain.xml to find the profile reference based on the group name that we retrieved from host.xml
' After the profile reference we then can find the socket-bindings for http and https ports
Function getJBossDomainPorts (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedHostXmlDom, userSuppliedDomainXmlDom)
Dim hostXMLDoc, domainXMLDoc, objPorts, objHttpNode, objHttpsNode, offsetNode
Dim hostAndDomainFilePath, hostFileName, domainFileName
Dim groupNameNode, groupName, portOffsetNode
Dim offset, objHttp, objHttps
Dim profileRefNode, profileRef
Dim numRegex, portOffsetMatch, httpMatch, httpsMatch
Dim numOffset, serverName
serverName = objProcessInfo.domainServerName
Set objPorts = New Ports
If userSuppliedHostXmlDom Is Nothing And userSuppliedDomainXmlDom Is Nothing Then
Set hostXMLDoc = CreateObject("Microsoft.XMLDOM")
Set domainXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set hostXMLDoc = userSuppliedHostXmlDom
Set domainXMLDoc = userSuppliedDomainXmlDom
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
hostXMLDoc.async = False
domainXMLDoc.async = False
hostAndDomainFilePath = objProcessInfo.ShortPath &amp; "\domain\configuration\"
hostFileName = "host.xml"
domainFileName = "domain.xml"
' the numRegex will be used to ensure only numbers are present in the file
Set numRegex = New RegExp
numRegex.IgnoreCase = True
numRegex.Global = False
numRegex.Pattern = "[0-9]+"
If objFso.FileExists(hostAndDomainFilePath &amp; hostFileName) And objFso.FileExists(hostAndDomainFilePath &amp; domainFileName) And Not objPorts.FileTooBig Then
hostXMLDoc.Load(hostAndDomainFilePath &amp; hostFileName)
domainXMLDoc.Load(hostAndDomainFilePath &amp; domainFileName)
' First we will find the server group and port offset from the host xml file
xPathForGroup = "/host/servers/server[@name=""" + serverName + """]/@group"
xPathForPortOffset = "/host/servers/server[@name=""" + serverName + """]/socket-bindings/@port-offset"
Set groupNode = hostXMLDoc.selectSingleNode(xPathForGroup)
Set portOffsetNode = hostXMLDoc.selectSingleNode(xPathForPortOffset)
' Set group name
If Not groupNode Is Nothing Then
groupName = groupNode.text
End If
' Set the port offset
If Not portOffsetNode Is Nothing Then
If numRegex.Test(portOffsetNode.Text) Then
Set portOffsetMatch = numRegex.Execute(portOffsetNode.Text)
numOffset = CInt(portOffsetMatch(0))
Else
numOffset = 0
End If
Else
numOffset = 0
End If
xPathForProfileRef = "/domain/server-groups/server-group[@name=""" + groupName + """]/socket-binding-group/@ref"
' Using the group name from host.xml we can find the profile reference in domain.xml
Set profileRefNode = domainXMLDoc.selectSingleNode(xPathForProfileRef)
If Not profileRefNode Is Nothing Then
profileRef = profileRefNode.Text
End If
' We use the profile reference to then find the http and https ports within the domain.xml file
xPathForHttp = "/domain/socket-binding-groups/socket-binding-group[@name=""" + profileRef + """]/socket-binding[@name = ""http""]/@port"
xPathForHttps = "/domain/socket-binding-groups/socket-binding-group[@name=""" + profileRef + """]/socket-binding[@name = ""https""]/@port"
Set objHttpNode = domainXMLDoc.selectSingleNode(xPathForHttp)
If Not objHttpNode Is Nothing Then
If numRegex.Test(objHttpNode.Text) Then
Set httpMatch = numRegex.Execute(objHttpNode.Text)
objHttp = httpMatch(0)
objPorts.HTTPPort = CStr(objHttp + numOffset)
End If
End If
Set objHttpsNode = domainXMLDoc.selectSingleNode(xPathForHttps)
If Not objHttpsNode Is Nothing Then
If numRegex.Test(objHttpsNode.Text) Then
Set httpsMatch = numRegex.Execute(objHttpsNode.Text)
objHttps = httpsMatch(0)
objPorts.HTTPSPort = CStr(objHttps + numOffset)
End If
End If
Else
LogErrorFileNotFound oAPI, JBOSS_DISCOVERY_SCRIPT_NAME, strFilePath &amp; strFileName
End If
Set getJBossDomainPorts = objPorts
End Function
'
' Get the HTTP &amp; HTTPS ports of the JBoss 7 installation that runs a specific configuration
'
Function getJBoss7Ports (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Dim objXMLDoc, objPorts, objNodeHTTP, objNodeHTTPS, offsetNode
Dim strFilePath, strFileName
Dim foundHttp, foundHttps, offset, objHttp, objHttps
Dim myRegExp, portOffsetMatch, httpMatch, httpsMatch
Dim numOffset, numHttp, numHttps
Set objPorts = New Ports
If userSuppliedXmlDom Is Nothing Then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set objXMLDoc = userSuppliedXmlDom
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
objXMLDoc.async = False
strFilePath = objProcessInfo.ShortPath &amp; "\standalone\configuration\"
strFileName = "standalone.xml"
If objFso.FileExists(strFilePath &amp; strFileName) And Not objPorts.FileTooBig Then
objXMLDoc.Load(strFilePath &amp; strFileName)
Set offsetNode = objXMLDoc.selectSingleNode("/server/socket-binding-group")
offset = offsetNode.getAttribute("port-offset")
Set myRegExp = New RegExp
myRegExp.IgnoreCase = True
myRegExp.Global = False
myRegExp.Pattern = "[0-9]+"
If Len(offset) &gt; 0 Then
Set portOffsetMatch = myRegExp.Execute(offset)
If portOffsetMatch(0) Is Nothing Then
numOffset = 0
Else
numOffset = CInt(portOffsetMatch(0))
End If
Else
numOffset=0
End If
Set objNodeHTTP = objXMLDoc.selectSingleNode("/server/socket-binding-group/socket-binding[@name =""http""]/@port")
Set httpMatch = myRegExp.Execute(objNodeHTTP.text)
If Not objNodeHTTP Is Nothing And Len(httpMatch(0)) Then
objHttp = httpMatch(0)
objPorts.HTTPPort = CStr(objHttp + numOffset)
End If
Set objNodeHTTPS = objXMLDoc.selectSingleNode("/server/socket-binding-group/socket-binding[@name =""https""]/@port")
Set httpsMatch = myRegExp.Execute(objNodeHTTPS.text)
If Not objNodeHTTPS Is Nothing And Len(httpsMatch(0))Then
objHttps = httpsMatch(0)
objPorts.HTTPSPort = CStr(objHttps + numOffset)
End If
Else
LogErrorFileNotFound oAPI, JBOSS_DISCOVERY_SCRIPT_NAME, strFilePath &amp; strFileName
End If
Set getJBoss7Ports = objPorts
End Function
'
' Get the version number of the JBoss installation that runs a specific configuration
' Do this by getting the value of the specVersion attribute of the jar tag with a name attribute
' with the value "jboss.jar" in the file jar-versions.xml located in the root install folder
'
Function getJBossVersion (oAPI, objProcessInfo, userSuppliedFso, userSuppliedXmlDom)
Dim objXMLDoc, modXMLDoc, objNode, objFso, versionNode
Dim strFilePath, strFileName, fullPath
Dim strFilePath7, strFileName7, strFilePath8, strFileName8
getJBossVersion = "Unknown"
If userSuppliedXmlDom Is Nothing Then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Set modXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set objXMLDoc = userSuppliedXmlDom
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
objXMLDoc.async = False
modXMLDoc.async = False
strFilePath = objProcessInfo.ShortPath &amp; "\"
strFileName = "jar-versions.xml"
strFilePath7 = objProcessInfo.ShortPath &amp; "\modules\org\jboss\as\server\main\"
strFileName7 = "module.xml"
strFilePath8 = objProcessInfo.ShortPath &amp; "\modules\system\layers\base\org\jboss\as\server\main\"
strFileName8 = "module.xml"
Set versionRegex = New RegExp
versionRegex.IgnoreCase = True
versionRegex.Global = True
versionRegex.Pattern = "([0-9]\.[0-9]\.[0-9]\..*)(\.jar)"
If objFso.FileExists(strFilePath &amp; strFileName) And Not isFileTooBig(objFso, strFilePath, strFileName) Then
objXMLDoc.load(strFilePath &amp; strFileName)
Set objNode = objXMLDoc.selectSingleNode("/jar-versions/jar[@name=""jboss.jar""]")
If Not objNode Is Nothing Then
Set versionNode = objNode.attributes.getNamedItem("specVersion")
If Not versionNode Is Nothing Then
getJBossVersion = versionNode.text
End If
End If
'
' For JBoss 7 travsere into the java packages and find the module.xml file within the server jar directory
' For Wildfly and JBoss EAS traverse into the java packages and find the module.xml file within the version jar directory
'
ElseIf objFso.FileExists(strFilePath8 &amp; strFileName8) And Not isFileTooBig(objFso, strFilePath8, strFileName8) Then
modXMLDoc.load(strFilePath8 &amp; strFileName8)
Set objNode = modXMLDoc.selectSingleNode("/module/resources/resource-root/@path")
If Not objNode Is Nothing Then
If versionRegex.Test(objNode.Text) Then
Set versionMatch = versionRegex.Execute(objNode.Text)
getJBossVersion = versionMatch(0).Submatches(0)
End If
End If
ElseIf objFso.FileExists(strFilePath7 &amp; strFileName7) And Not isFileTooBig(objFso, strFilePath7, strFileName7) Then
modXMLDoc.load(strFilePath7 &amp; strFileName7)
Set objNode = modXMLDoc.selectSingleNode("/module/resources/resource-root/@path")
If Not objNode Is Nothing Then
If versionRegex.Test(objNode.Text) Then
Set versionMatch = versionRegex.Execute(objNode.Text)
getJBossVersion = versionMatch(0).Submatches(0)
End If
End If
Else
LogErrorFileNotFound oAPI, JBOSS_DISCOVERY_SCRIPT_NAME, strFilePath &amp; strFileName
getJBossVersion = "Unknown"
End If
End Function
'
' From the base folder for a JBoss installation, locate the configurations for
' this installation.
'
Function getJBossConfigurationInfo (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Dim objConfigurationInfo, thePorts
Set objConfigurationInfo = New ApplicationServerInstance
objConfigurationInfo.AppServerType = REGISTRY_PROP_APP_SERVER_TYPE_JBOSS
objConfigurationInfo.Configuration = objProcessInfo.ConfigurationPath
objConfigurationInfo.Version = getJBossVersion (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
' We assume that the way we get the ports for JBoss 5 will work in 6 as well and that
' the old way we use for 4 will work in older versions
If objConfigurationInfo.Version &lt;&gt; "Unknown" Then
If CInt(Left(objConfigurationInfo.Version, 1)) &gt;= 7 Then
If objProcessInfo.isDomainInstance Then
Set thePorts = getJBossDomainPorts (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom, userSuppliedXmlDom)
Else
Set thePorts = getJBoss7Ports (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
End If
ElseIf CInt(Left(objConfigurationInfo.Version, 1)) &gt;= 5 Then
Set thePorts = getJBoss5Ports (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Else
Set thePorts = getJBoss4Ports (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
End If
objConfigurationInfo.HttpPort = thePorts.HTTPPort
objConfigurationInfo.HttpsPort = thePorts.HTTPSPort
If thePorts.FileTooBig Then
Set getJBossConfigurationInfo = Nothing
Else
Set getJBossConfigurationInfo = objConfigurationInfo
End If
Else
Set getJBossConfigurationInfo = Nothing
End If
End Function
'
' Extract the install path of JBoss from the class path
' Example of class path for JBoss 4.2: C:\Program Files (x86)\Java\jdk1.6.0_20\lib\tools.jar;C:\jboss-4.2.1.GA\jboss-4.2.1.GA\bin\run.jar
'
Function GetJBossPathFromClassPath(classPath)
Dim paths, path, pos
GetJBossPathFromClassPath = ""
paths = Split(classPath, ";")
For Each path In paths
pos = InStr(path, "\bin\run.jar")
If pos &gt; 0 Then
GetJBossPathFromClassPath = LCase(Left(path, pos - 1))
End If
Next
End Function
'
' Scan the running processes on the local machine for 'JAVA%.EXE' or 'CONHOST.EXE'
' to locate running JBoss instances.
'
Function GetJBossProcessesInfo(userSuppliedWmi, userSuppliedFso, userSuppliedRegExp)
Dim objWMIService, objFso
Dim objProcessInfoList
Set objProcessInfoList = CreateObject("Scripting.Dictionary")
If userSuppliedWmi Is Nothing Then
Set objWMIService = GetObject("winmgmts:\root\cimv2")
Else
Set objWMIService = userSuppliedWmi
End If
If userSuppliedFso Is Nothing Then
Set objFso = CreateObject("Scripting.FileSystemObject")
Else
Set objFso = userSuppliedFso
End If
' Get a list of the running processes
Dim collectionOfProcesses
Set collectionOfProcesses = objWMIService.ExecQuery("SELECT CommandLine FROM Win32_Process WHERE Name LIKE 'java%.exe' or Name = 'conhost.exe'")
Dim intCollectionCounter
For Each processInstance In collectionOfProcesses
If Len(processInstance.CommandLine) &gt; 0 Then
If CheckIfJBossProcess(userSuppliedRegExp, processInstance.CommandLine) Then
Dim objProcInfo, pos
Set objProcInfo = New ProcessInfo
'Get -classpath command line argument
Dim classpath
classpath = ParseOutCommandLineArg(processInstance.CommandLine, "-classpath")
Dim classpath7
classpath7 = ParseOutCommandLineArg(processInstance.CommandLine, "-Djboss.home.dir")
Dim classpathDomain
classpathDomain = ParseOutCommandLineArg(processInstance.CommandLine, "-Djboss.server.data.dir")
If Not (IsEmpty(classpath) ) Then
objProcInfo.Path = GetJBossPathFromClassPath(classpath)
objProcInfo.ShortPath = objFso.GetFolder(objProcInfo.Path).ShortPath
'Get -c command line argument, if set
'this argument is used to name the configuration folder. IF not set, assume "default"
Dim instance
cInstance = ParseOutCommandLineArg(processInstance.CommandLine, "-c")
serverNameInstance = ParseOutCommandLineArg(processInstance.CommandLine, "-Djboss.server.name")
If Not (IsEmpty(cInstance) ) Then
objProcInfo.Configuration = cInstance
ElseIf Not (IsEmpty(serverNameInstance) ) Then
objProcInfo.Configuration = serverNameInstance
Else
objProcInfo.Configuration = "default"
End If
objProcInfo.ConfigurationPath = objProcInfo.Path + "\server\" + objProcInfo.Configuration
Dim tempShortPath
tempShortPath = objProcInfo.ShortPath + "\server\" + objProcInfo.Configuration
objProcInfo.ConfigurationShortPath = objFso.GetFolder(tempShortPath).ShortPath
objProcessInfoList.Add objProcInfo.ConfigurationPath, objProcInfo
ElseIf Not(IsEmpty(classpath7) ) Then
objProcInfo.Path = classpath7
objProcInfo.ShortPath = classpath7
' If we recieved a standalone instance we will have no value for -Djboss.server.data.dir
' If we recieved a domain instance we will have a directory for the server in data
If Not (IsEmpty(classpathDomain) ) Then
' We will set the configuration of the domain instance to the server data directory
objProcInfo.ConfigurationPath = classpathDomain
objProcInfo.Configuration = classpathDomain
' We will set the domain instance to true
objProcInfo.isDomainInstance = true
' In order to get the domain server name we will need the value between these directories
domainStr = "\domain\servers\"
dataStr = "\data"
pos1 = InStr(classpathDomain, domainStr)
pos2 = InStr(classpathDomain, dataStr)
' This will return the whole path without the data directory at the end
strBeforeDataDir = Left(classpathDomain, pos2 - 1)
' We will get the total length of the string then subtract the end position of the /domain/servers directory
' This will return the specified servername
strAfterDomainDir = Right(strBeforeDataDir, Len(strBeforeDataDir) - (pos1 + Len(domainStr) - 1))
objProcInfo.domainServerName = strAfterDomainDir
objProcInfo.ConfigurationShortPath = objProcInfo.ConfigurationPath
objProcessInfoList.Add objProcInfo.ConfigurationPath, objProcInfo
Else
cInstance = ParseOutCommandLineArg(processInstance.CommandLine, "-Dlogging.configuration")
If Not (IsEmpty(cInstance) ) Then
pos = InStr(cInstance, "/logging.properties")
pos1 = InStr(cInstance, "file:")
If pos&gt;0 Then
' first we retrieve the string without the file: characters preceeding the disk path
positionOfStr = pos1 + Len("file:") - 1
strWithoutFile = Right(cInstance, Len(cInstance) - positionOfStr)
' We set the configurationPath to the diskpath plus the standalone configuration folder
' Since VBScript position is from the first character we must subtract one
objProcInfo.ConfigurationPath = Left(strWithoutfile, pos - positionOfStr - 1)
objProcInfo.Configuration = Left(strWithoutfile, pos - positionOfStr - 1)
End If
End If
objProcInfo.ConfigurationShortPath = objProcInfo.ConfigurationPath
objProcessInfoList.Add objProcInfo.ConfigurationPath, objProcInfo
End If
End If
'Get -Djboss.service.binding.set command line argument, if set
'This is new in JBoss 5 and used to control what set of ports is used
Dim portbinding
portbinding = ParseOutCommandLineArg(processInstance.CommandLine, "-Djboss.service.binding.set")
objProcInfo.PortBinding = portbinding
End If
End If
Next
Set GetJBossProcessesInfo = objProcessInfoList
End Function
'
' Method to verify if the given command line is a JBoss process.
' This is done by verifying the string contains:
' org.jboss.Main
'
Public Function CheckIfJBossProcess(userSuppliedRegExp, strInput)
Dim objIsRegExp, objIsRegExp7, objIsRegExpDomain
If userSuppliedRegExp Is Nothing Then
Set objIsRegExp = New RegExp
Set objIsRegExp7 = New RegExp
Set objIsRegExpDomain = New RegExp
objIsRegExp.IgnoreCase = True
objIsRegExp.Global = True
objIsRegExp.Pattern = " org\.jboss\.Main"
'Jboss 7 process details
objIsRegExp7.IgnoreCase = True
objIsRegExp7.Global = True
objIsRegExp7.Pattern = "org\.jboss\.as\.standalone"
'JBoss and Wildfly domain mode process
objIsRegExpDomain.IgnoreCase = True
objIsRegExpDomain.Global = True
objIsRegExpDomain.Pattern = "org\.jboss\.as\.server"
Else
Set objIsRegExp = userSuppliedRegExp
Set objIsRegExp7 = userSuppliedRegExp
Set objIsRegExpDomain = userSuppliedRegExp
End If
Dim objMatchesCol,objMatchesCol7, boolIsJBoss
boolIsJBoss = False
Set objMatchesCol = objIsRegExp.Execute(strInput)
Set objMatchesCol7 = objIsRegExp7.Execute(strInput)
Set objMatchesColDomain = objIsRegExpDomain.Execute(strInput)
If ((1 = objMatchesCol.Count) Or (1 = objMatchesCol7.Count) Or (1 = objMatchesColDomain.Count)) Then
boolIsJBoss = True
End If
CheckIfJBossProcess = boolIsJBoss
End Function
'''
''' Returns a list of JBoss instances after checkinf running process
''' and parsing the data from server.xml in the conf directory
'''
Function GetJBossInstances (oAPI, userSuppliedWmi, userSuppliedFso, userSuppliedRegExp, userSuppliedXmlDom)
Dim objProcessInfoList
Set objProcessInfoList = GetJBossProcessesInfo(userSuppliedWmi, userSuppliedFso, userSuppliedRegExp)
Dim objConfigurationDiscoveryInfoList
Set objConfigurationDiscoveryInfoList = CreateObject("Scripting.Dictionary")
Dim objProcessInfo
For Each objProcessInfo In objProcessInfoList
Dim profDiscInfo
Set profDiscInfo = getJBossConfigurationInfo (oAPI, objProcessInfoList.Item(objProcessInfo), userSuppliedFso, userSuppliedXmlDom)
If Not (profDiscInfo Is Nothing) Then
objConfigurationDiscoveryInfoList.Add profDiscInfo.GetKey, profDiscInfo
End If
Next
Set GetJBossInstances = objConfigurationDiscoveryInfoList
End Function
'''
''' Create instances in OpsMgr for all found instances of JBoss configuration
'''
Public Function ReturnJBossConfigurations(oAPI, ManagementGroup, SourceId, ManagedEntityId, ReleationGuid, TargetComputer, JBossClassGuid, MajorJBossVersion)
Dim oDiscoveryData, oInst
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Dim objConfigurationDiscoveryInfoClass
Set objConfigurationDiscoveryInfoClass = New ConfigurationDiscoveryInfoClass
Set objConfigurationDiscoveryInfoClass.ListOfConfigurations = GetJBossInstances(oAPI, Nothing, Nothing, Nothing, Nothing)
Dim objConfigurationMonitoringInfo
Set objConfigurationMonitoringInfo = objConfigurationDiscoveryInfoClass.ListOfConfigurations
Set objConfigurationMonitoringInfo = DiscoveryWithPersistence(objConfigurationDiscoveryInfoClass, Nothing, Nothing, ManagementGroup, REGISTRY_PROP_APP_SERVER_TYPE_JBOSS, Nothing)
Dim entry
For Each entry In objConfigurationMonitoringInfo
If FilterVersion(MajorJBossVersion, objConfigurationMonitoringInfo.Item(entry).Version) Then
Set oInst = oDiscoveryData.CreateClassInstance(JBossClassGuid)
' Bug 43159: Workaround for extra long paths, default to DOS-style paths
Dim pathToUse
If Len(objConfigurationMonitoringInfo.Item(entry).Configuration) &gt; 260 Then
pathToUse = objConfigurationMonitoringInfo.Item(entry).ShortConfiguration
Else
pathToUse = objConfigurationMonitoringInfo.Item(entry).Configuration
End If
Call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/Id$", pathToUse)
Call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/HostName$", TargetComputer)
Call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/HttpPort$", objConfigurationMonitoringInfo.Item(entry).HttpPort)
Call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/HttpsPort$", objConfigurationMonitoringInfo.Item(entry).HttpsPort)
Call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/Version$", objConfigurationMonitoringInfo.Item(entry).Version)
Call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/DiskPath$", pathToUse)
Call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "JBoss|" &amp; pathToUse)
Call oDiscoveryData.AddInstance(oInst)
Set oComputer = oDiscoveryData.CreateClassInstance("$MPElement[Name='Windows!Microsoft.Windows.Computer']$")
Call oComputer.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
Set oContains = oDiscoveryData.CreateRelationShipInstance(ReleationGuid)
oContains.Source = oComputer
oContains.Target = oInst
Call oDiscoveryData.AddInstance(oContains)
Set oHealthServiceInstance = oDiscoveryData.CreateClassInstance( "$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$" )
Call oHealthServiceInstance.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer )
Set oHsCnRel = oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
oHsCnRel.Source = oHealthServiceInstance
oHsCnRel.Target = oInst
Call oDiscoveryData.AddInstance(oHsCnRel)
End If
Next
Call oAPI.Return(oDiscoveryData)
End Function

Dim oArgs, oAPI, guidManagementGroup, guidMpElement, guidConfiguration, guidId, guidRelation, strMachineName, strJBossMajorVersion

Set oArgs = WScript.Arguments

if oArgs.Count &lt; 6 Then
Wscript.Quit -1
End If

guidManagementGroup = oArgs(0)
guidMpElement = oArgs(1)
guidId = oArgs(2)
guidRelation = oArgs(3)
strMachineName = oArgs(4)
guidConfiguration = oArgs(5)
strJBossMajorVersion = "8"

Set oAPI = CreateObject("MOM.ScriptAPI")
ReturnJBossConfigurations oAPI, guidManagementGroup, guidMpElement, guidId, guidRelation, strMachineName, guidConfiguration, strJBossMajorVersion
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>