Действие выборки данных процесса сервера приложений WebSphere

Microsoft.JEE.WebSphere.Windows.ProfileProcessAvailabilityProbe (ProbeActionModuleType)

Действие выборки данных для проверки выполнения процесса сервера приложений WebSphere в Windows.

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
PassThrough ProbeAction System.PassThroughProbe Default
Script ProbeAction Microsoft.Windows.ScriptPropertyBagProbe Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Тайм-аут

Source Code:

<ProbeActionModuleType ID="Microsoft.JEE.WebSphere.Windows.ProfileProcessAvailabilityProbe" Accessibility="Internal" Batching="false" PassThrough="false">
<Configuration>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>IsWebSphereProcessRunning.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>
' Copyright (c) Microsoft Corporation. All rights reserved.
' Date Created: July 6th, 2010
'
' This script is to be incorporated into the WebSphere JEE MP.
' This script will discover the running java process of an IBM
' WebSphere Application server's profiles.
' This is captured and returned back to the MP's unit monitor as
' a property bag
'
SetLocale("en-us")
'''
''' Simple Class defining the Profile Discovery data
'''
Class ProfileMonitoringInfo
Public ProcessCount
Public ProfileCellNodeList
Private Sub class_initialize()
Set ProfileCellNodeList = CreateObject("Scripting.Dictionary")
End Sub
End Class
Function GetProcessInformation(userSuppliedWmi, userSuppliedRegExp)
DIM objWMIService
If IsEmpty(userSuppliedWmi) Or userSuppliedWmi Is Nothing Then
Set objWMIService = GetObject("winmgmts:\root\cimv2")
Else
Set objWMIService = userSuppliedWmi
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'")
DIM objProfileMonitoringInfo
SET objProfileMonitoringInfo = new ProfileMonitoringInfo
' Get the Process count. This is returned because something always must be returned
' or otherwise the workflow will terminate. Also, this is used to determine the ERROR
' condition when there are no java processes running
IF 0 = collectionOfProcesses.Count THEN
objProfileMonitoringInfo.ProcessCount = 0
ELSE
' For the value returned, we need some way of indicating which profile this content
' pertains to. This must be unique because there is not a way to have the XPATH match
' the appropriate piece of the property bag (i.e. the Name attribute should be unique).
DIM runningProcess
FOR EACH runningProcess IN collectionOfProcesses
IF CheckIfWebSphereProcess(userSuppliedRegExp, runningProcess.CommandLine) THEN
Dim strProfile, strCell, strNode, strServer
strProfile = ParseOutProfileNameFromCommandLine(userSuppliedRegExp, runningProcess.CommandLine)
strCell = ParseOutCellNameFromCommandLine(userSuppliedRegExp, runningProcess.CommandLine)
strNode = ParseOutNodeNameFromCommandLine(userSuppliedRegExp, runningProcess.CommandLine)
strServer = ParseOutServerNameFromCommandLine(userSuppliedRegExp, runningProcess.CommandLine)
IF NOT (IsEmpty(strProfile) OR IsEmpty(strCell) OR IsEmpty(strNode) OR IsEmpty(strServer)) THEN
objProfileMonitoringInfo.ProcessCount = 1 + objProfileMonitoringInfo.ProcessCount
Dim strKey
strKey = strProfile &amp; " " &amp; strCell &amp; " " &amp; strNode &amp; " " &amp; strServer
objProfileMonitoringInfo.ProfileCellNodeList.Add strKey, "Running"
' NB: The 'Running' value is presently not used. A dynamicly sized array/vector is
' needed here and VBscript does not (easily) support this. Hence the use of a dictionary
END IF
END IF
NEXT
END IF
Set GetProcessInformation = objProfileMonitoringInfo
End Function
'
' Method to verify if the given command line is a WebSphere process.
' This is done by verifying the string contains:
' com.ibm.ws.bootstrap.WSLauncher com.ibm.ws.runtime.WsServer
'
Public Function CheckIfWebSphereProcess(userSuppliedRegExp, strInput)
DIM objIsWebSphereRegExp
DIM boolIsWebSphere
boolIsWebSphere = false
IF NOT IsNull(strInput) THEN
IF userSuppliedRegExp is Nothing THEN
Set objIsWebSphereRegExp = New RegExp
objIsWebSphereRegExp.IgnoreCase = True
objIsWebSphereRegExp.Global = True
' Find the third-to-last word in the Command Line
objIsWebSphereRegExp.Pattern = " com\.ibm\.ws\.bootstrap\.WSLauncher com\.ibm\.ws\.runtime\.WsServer "
ELSE
Set objIsWebSphereRegExp = userSuppliedRegExp
END IF
DIM objMatchesCol
Set objMatchesCol = objIsWebSphereRegExp.Execute(strInput)
IF (1 = objMatchesCol.Count) THEN
boolIsWebSphere = true
END IF
END IF
CheckIfWebSphereProcess = boolIsWebSphere
End Function
'
' Method for parsing out the profile path name from the command line.
'
' The expectation is that this will be found from the section/argument
' starting with -Dserver.root, something that might look like:
'
' -Dserver.root=C:\IBM\WebSphere\AppServer\profiles\AppSrv02 -D
'
' or
'
' "-Dserver.root=C:\IBM\WebSphere\AppServer\profiles\AppSrv02" -D
'
' or
'
' "-Dserver.root=C:\IBM\WebSphere\AppServer\profiles\AppSrv02" "-D
'
' Originally, the desire was to return back the profile name; however, it
' turns out that the profile name is not available. The next best thing
' is the path to the profile (as above)
'
Public Function ParseOutProfileNameFromCommandLine(userSuppliedRegExp, strInput)
' Parse out the contents of the profile name
DIM objProfileRegExp
IF userSuppliedRegExp is Nothing THEN
Set objProfileRegExp = New RegExp
objProfileRegExp.IgnoreCase = True
objProfileRegExp.Global = True
'
' regular expression says look for -Dserver.root=&lt;something&gt; -D
' where &lt;something&gt; is the path that may or may not end with a
' doublequote (hence the char(34)?)
'
' Without the escapes, here is the 'raw' regex that is (slightly)
' more human-readible
'
' "\-Dserver\.root=(.+?"? "?\-D)
'
objProfileRegExp.Pattern = "\-Dserver\.root=(.+?" &amp; chr(34) &amp; "? "&amp; chr(34) &amp;"?\-D)"
ELSE
Set objProfileRegExp = userSuppliedRegExp
END IF
DIM objMatchesCol, strProfileName
Set objMatchesCol = objProfileRegExp.Execute(strInput)
IF (1 = objMatchesCol.Count) THEN
'
' A bit of of a workaround to parse the profile name out of here.
' There seems to be a discrepency when it comes to searching for a
' backslash character (b/c it is an escape character?) that behaves
' differently if the script is run local versus extracted and run from
' the MP
DIM intProfileIndex, intLength, keyProfiles
intLength = Len(objMatchesCol.Item(0))
' Parse out the last word in the -Dserver.root and then take of the final '" -D'
' from the end of the string
strProfileName = Right(objMatchesCol.Item(0), intLength - Len("-Dserver.root=") )
strProfileName = TrimTrailingStringIfExists(strProfileName, " " &amp; chr(34) &amp; "-D")
strProfileName = TrimTrailingStringIfExists(strProfileName, " -D")
' Bug 23087: Allow spaces in profile path
' If the path has spaces, it will look like:
' "-Dserver.root=C:\IBM\WebSphere\AppServer\profiles\AppSrv02"
' So the current string will have a trailing double-quote. As this is an illegal
' character for a real path, remove this character from the end if it exists
strProfileName = TrimTrailingStringIfExists(strProfileName, chr(34))
END IF
ParseOutProfileNameFromCommandLine = strProfileName
End Function
Private Function TrimTrailingStringIfExists(strInput, strStrip)
DIM returnValue
returnValue = strInput
IF strStrip = Mid(strInput, Len(strInput) - Len(strStrip) + 1, Len(strStrip)) THEN
returnValue = Left(strInput, Len(strInput) - Len(strStrip))
END IF
TrimTrailingStringIfExists = returnValue
End Function
'
' Method for parsing out the cell name from the command line.
'
' This is expected to be something like 'SCXOM64-WS7-02Node02Cell'
' and located near the end of the command-line. This function will assume
' that it is the third word from the end of the command line.
'
'
Public Function ParseOutCellNameFromCommandLine(userSuppliedRegExp, strInput)
DIM objCellRegExp
IF userSuppliedRegExp is Nothing THEN
Set objCellRegExp = New RegExp
objCellRegExp.IgnoreCase = True
objCellRegExp.Global = True
' Find the third-to-last word in the Command Line
objCellRegExp.Pattern = "\S+ \S+ \S+$"
ELSE
Set objCellRegExp = userSuppliedRegExp
END IF
DIM objMatchesCol, strCellName
Set objMatchesCol = objCellRegExp.Execute(strInput)
IF (1 = objMatchesCol.Count) THEN
'
' The regular expression found the third word from the end.
' (minus one b/c the index found is the position of the space)
'
Dim stopIndex
stopIndex = InStr(1, objMatchesCol.Item(0), " ")
strCellName = Left(objMatchesCol.Item(0), stopIndex-1)
END IF
ParseOutCellNameFromCommandLine = strCellName
End Function
'
' Method for parsing out the Node name from the command line.
'
' This is expected to be something like 'SCXOM64-WS7-02Node02'
' and located near the end of the command-line. This function will assume
' that it is the second word from the end of the command line.
'
'
Public Function ParseOutNodeNameFromCommandLine(userSuppliedRegExp, strInput)
DIM objNodeRegExp
IF userSuppliedRegExp is Nothing THEN
Set objNodeRegExp = New RegExp
objNodeRegExp.IgnoreCase = True
objNodeRegExp.Global = True
' Find the second-to-last word in the Command Line
objNodeRegExp.Pattern = "\S+ \S+$"
ELSE
Set objNodeRegExp = userSuppliedRegExp
END IF
DIM objMatchesCol, strNodeName
Set objMatchesCol = objNodeRegExp.Execute(strInput)
IF (1 = objMatchesCol.Count) THEN
'
' The regular expression found the second word from the end.
' (minus one b/c the index found is the position of the space)
'
Dim stopIndex
stopIndex = InStr(1, objMatchesCol.Item(0), " ")
strNodeName = Left(objMatchesCol.Item(0), stopIndex-1)
END IF
ParseOutNodeNameFromCommandLine = strNodeName
End Function
'
' Method for parsing out the Server name from the command line.
'
' This is expected to be something like 'server1'
' and located near the end of the command-line. This function will assume
' that it is the last word at the end of the command line.
'
'
Public Function ParseOutServerNameFromCommandLine(userSuppliedRegExp, strInput)
DIM objServerRegExp
IF userSuppliedRegExp is Nothing THEN
Set objServerRegExp = New RegExp
objServerRegExp.IgnoreCase = True
objServerRegExp.Global = True
' Find the last word in the Command Line
objServerRegExp.Pattern = "\S+$"
ELSE
Set objServerRegExp = userSuppliedRegExp
END IF
DIM objMatchesCol, strServerName
Set objMatchesCol = objServerRegExp.Execute(strInput)
IF (1 = objMatchesCol.Count) THEN
'
' The regular expression found the last word from the end.
' (minus one b/c the index found is the position of the space)
'
strServerName = objMatchesCol.Item(0)
END IF
ParseOutServerNameFromCommandLine = strServerName
End Function
'
' Return the discovered process information back to
'
Function ReturnProcessRunning()
Dim objProfileMonitoringInfo
Set objProfileMonitoringInfo = GetProcessInformation(Nothing, Nothing)
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue "Count", objProfileMonitoringInfo.ProcessCount
'
' The key added here is a combination of Profile, Cell, Node and Server
' seperated by spaces. As far as we know, these names cannot have spaces.
' These values must be in the keys so that the XPATH in the MP can find
' them in the attributes of the Property Bag.
'
FOR EACH entry IN objProfileMonitoringInfo.ProfileCellNodeList.keys
oBag.AddValue entry, objProfileMonitoringInfo.ProfileCellNodeList.Item(entry)
NEXT
Call oAPI.Return(oBag)
End Function

ReturnProcessRunning()
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
</MemberModules>
<Composition>
<Node ID="Script">
<Node ID="PassThrough"/>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
<TriggerOnly>true</TriggerOnly>
</ProbeActionModuleType>