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

Microsoft.JEE.Tomcat.Windows.ConfigurationProcessAvailabilityProbeAction (ProbeActionModuleType)

Действие выборки, определяющее, выполняется ли процесс сервера веб-приложений Tomcat в Windows.

Element properties:

TypeProbeActionModuleType
IsolationAny
AccessibilityPublic
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.Tomcat.Windows.ConfigurationProcessAvailabilityProbeAction" Accessibility="Public" 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>IsTomcatProcessRunning.vbs</ScriptName>
<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.
' Date Created: July 6th, 2010
'
' This script is to be incorporated into the Tomcat JEE MP.
' This script will discover the running java process of Tomcat
' Web Application server Configurations.
'
SetLocale("en-us")
'
' String found before the version in the Tomcat RELEASE NOTES file
'
CONST TOMCAT_VERSION_PRECURSOR = "Apache Tomcat Version "
'''
''' Constants for use in this script
'''
CONST TOMCAT_DISCOVERY_SCRIPT_NAME = "TomcatDiscovery.vbs"
'''
''' Simple Class defining the Process Discovery data
'''
Class ProcessInfo
Public CatalinaHomePath
Public Profile
End Class
'''
''' Simple Class defining the Tomact Configuration Discovery data
'''
Class ProfileDiscoveryInfoClass
Public ListOfProfiles
Private Sub CLASS_initialize()
Set ListOfProfiles = CreateObject("Scripting.Dictionary")
End Sub
Function GetListOfRunningInstances()
Set GetListOfRunningInstances = ListOfProfiles
End Function
End Class
'
' From the base folder for a Tomcat installation, look in the
' conf/server.xml file to locate the configurations for
' this installation.
'
Function getTomcatProfileInfo (oAPI, objProcessInfo, userSuppliedFSO, userSuppliedXmlDom)
Dim fso
Dim counter
Dim objXMLDoc, objNodeList, objNode
Dim strProfileServerXmlPath
Dim objProfileInfo
Dim strFilePath, strFileName
Set getTomcatProfileInfo = nothing
If userSuppliedFso Is Nothing Then
Set fso = CreateObject("Scripting.FileSystemObject")
Else
Set fso = userSuppliedFso
End If
If objProcessInfo.Profile = "" Then
Wscript.Echo "getTomcatProfileInfo: No folder parameter supplied, script exiting in error."
Exit Function
End If
strProfileServerXmlPath = objProcessInfo.Profile &amp; "\conf\server.xml"
strFilePath = objProcessInfo.Profile &amp; "\conf\"
strFileName = "server.xml"
IF fso.FileExists(strProfileServerXmlPath) and (Not isFileTooBig(fso, strFilePath, strFileName)) THEN
If userSuppliedXmlDom Is Nothing Then
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
Else
Set objXMLDoc = userSuppliedXmlDom
End If
objXMLDoc.async = False
objXMLDoc.load(strProfileServerXmlPath)
Set objProfileInfo = new ApplicationServerInstance
objProfileInfo.AppServerType = REGISTRY_PROP_APP_SERVER_TYPE_TOMCAT
objProfileInfo.Configuration = objProcessInfo.Profile
objProfileInfo.Version = getTomcatVersion(objProcessInfo, fso)
'
' Extract necessary information from the server.xml file
' This gives us the HttpPort and HttpsPort
' Try use the &lt;Service name="Catalina"&gt; if that fails use the first &lt;Service&gt; entry in the file
Dim ServerName
Set objNodeList = objXMLDoc.selectNodes("/Server/Service/@name")
If objNodeList is nothing then
Wscript.Echo "getTomcatProfileInfo: server.xml does not contain a service, script exiting in error."
LogErrorParsingFile oAPI, TOMCAT_DISCOVERY_SCRIPT_NAME, strProfileServerXmlPath
Exit Function
End If
ServerName = objNodeList.Item(0).text
Dim acounter
for acounter = 0 to objNodeList.length-1
If "Catalina" = objNodeList.Item(acounter).text Then
ServerName = objNodeList.Item(acounter).text
End If
Next
' Retrieve the http and https port from the service found
Set objNodeList = objXMLDoc.selectNodes("/Server/Service[@name='"&amp;ServerName&amp;"']/Connector")
If not objNodeList is nothing then
If objNodeList.length &gt; 0 Then
' Step through all the connectors looking for the HTTP and HTTPS connector
FOR acounter = 0 to objNodeList.length-1
Dim strProtocol
strProtocol = objNodeList.item(acounter).GetAttribute("protocol")
' For Tomcat 5.5 the protocol attribute is not specified
' It is supplied for Tomcat 6 and 7
If "HTTP/1.1" = strProtocol OR IsEmpty(strProtocol) OR IsNull(strProtocol) Then
Dim strSecure
strSecure = objNodeList.item(acounter).GetAttribute("secure")
If IsEmpty(strSecure) OR IsNull(strSecure) THEN
' Use the first available connector that does not have the 'Secure' attribute
IF 0 = objProfileInfo.HttpPort THEN
objProfileInfo.HttpPort = objNodeList.item(acounter).GetAttribute("port")
END IF
ELSE
' Use the first available connector that has the 'Secure' attribute
IF 0 = objProfileInfo.HttpsPort THEN
objProfileInfo.HttpsPort = objNodeList.item(acounter).GetAttribute("port")
END IF
END IF
END IF
NEXT
End If
End If
if objProfileInfo.HttpsPort = 0 and objProfileInfo.HttpPort = 0 then
Set getTomcatProfileInfo = nothing
else
Set getTomcatProfileInfo = objProfileInfo
End If
ELSE
LogErrorFileNotFound oAPI, TOMCAT_DISCOVERY_SCRIPT_NAME, strProfileServerXmlPath
Set getTomcatProfileInfo = nothing
END IF
End Function
'
' Function to parse the text of the RELEASE-NOTES text file for version information.
' The parser assumes that there is a line in the file like:
'
' Apache Tomcat Version 5.5.30
'
' The method will search for said line and then take the string after
' "Apache Tomcat Version " and return this as the version parameter. If the string
' cannot be found (or say the file does not exist), then UNKNOWN will be returned.
'
' Argument objProcessInfo : Object Describing Tomcat (Process) Instance
' (needed for providing path to the Tomcat Configuration)
' Argument objFso : File System Object
' (needed for determing existence of the RELEASE-NOTES
' file and reading it)
PRIVATE FUNCTION getTomcatVersion(objProcessInfo, objFso)
getTomcatVersion = "UNKNOWN"
DIM strReleaseNotes, strLine
strReleaseNotes = objProcessInfo.CatalinaHomePath &amp; "\RELEASE-NOTES"
IF objFso.FileExists(strReleaseNotes) THEN
DIM objTextFile
' The second argument represents the constant ForReading
SET objTextFile = objFSO.OpenTextFile (strReleaseNotes, 1)
DO UNTIL objTextFile.AtEndOfStream
strLine = objTextFile.Readline
DIM intFindResult
intFindResult = InStr(strLine, TOMCAT_VERSION_PRECURSOR)
IF 0 &lt; intFindResult THEN
'
' Parse out the version information from a line that should look
' similar to:
'
' Apache Tomcat Version 5.5.30
'
' Assuming the string only appears once in the file, then
' we can stop reading the file too.
'
getTomcatVersion = Mid(strLine, intFindResult + Len(TOMCAT_VERSION_PRECURSOR))
EXIT DO
END IF ' Found Tomcat Version String
LOOP ' Read File Loop
END IF ' File Existence Check
END FUNCTION
'
' Scan the running processes on the local machine for 'JAVA%.EXE' or 'CONHOST.EXE'
' to locate running tomcat instances.
'
Function GetTomcatProcessesInfo(userSuppliedWmi, userSuppliedRegExp)
DIM objWMIService
DIM objProcessInfoList
Set objProcessInfoList = CreateObject("Scripting.Dictionary")
If 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' or Name = 'conhost.exe'")
FOR EACH processInstance IN collectionOfProcesses
If Len(processInstance.CommandLine) &gt; 0 Then
If CheckIfTomcatProcess(userSuppliedRegExp, processInstance.CommandLine) THEN
Dim objProcInfo
Set objProcInfo = NEW ProcessInfo
'Get CATALINA_HOME command line argument
DIM strCatalinaHome
strCatalinaHome = ParseOutCommandLineArg(processInstance.CommandLine, "-Dcatalina.home")
IF NOT (IsEmpty(strCatalinaHome) ) THEN
objProcInfo.CatalinaHomePath = LCase(strCatalinaHome)
'Get CATALINA_BASE command line argument
'CATALINA_BASE is used to point to a configuration folder which contains conf and webapps folders
Dim instance
instance = ParseOutCommandLineArg(processInstance.CommandLine, "-Dcatalina.base")
IF NOT (IsEmpty(instance) ) THEN
instance = LCase(instance)
objProcInfo.Profile = instance
objProcessInfoList.Add objProcInfo.Profile, objProcInfo
END IF ' empty instance
End If ' empty strCatalinaHome
End If ' Tomcat Process Check
End If
Next
Set GetTomcatProcessesInfo = objProcessInfoList
End Function
'
' Method to verify if the given command line is a Tomcat process.
' This is done by verifying the string contains:
' org.apache.catalina.startup.Bootstrap
'
Public Function CheckIfTomcatProcess(userSuppliedRegExp, strInput)
Dim objIsRegExp
If userSuppliedRegExp is Nothing Then
Set objIsRegExp = New RegExp
objIsRegExp.IgnoreCase = True
objIsRegExp.Global = True
objIsRegExp.Pattern = " org\.apache\.catalina\.startup\.Bootstrap"
Else
Set objIsRegExp = userSuppliedRegExp
End If
DIM objMatchesCol, boolIsTomcat
boolIsTomcat = false
Set objMatchesCol = objIsRegExp.Execute(strInput)
If (1 = objMatchesCol.Count) Then
boolIsTomcat = true
End If
CheckIfTomcatProcess = boolIsTomcat
End Function
'''
''' Returns a list of Tomcat instances after checkinf running process
''' and parsing the data from server.xml in the conf directory
'''
Function GetTomcatInstances (oAPI, userSuppliedWmi, userSuppliedRegExp, userSuppliedFSO, userSuppliedXmlDom)
Dim objProcessInfoList
Set objProcessInfoList = GetTomcatProcessesInfo(userSuppliedWmi, userSuppliedRegExp)
Dim objProfileDiscoveryInfoList
Set objProfileDiscoveryInfoList = CreateObject("Scripting.Dictionary")
Dim objProcessInfo
For Each objProcessInfo in objProcessInfoList
Dim profDiscInfo
Set profDiscInfo = getTomcatProfileInfo (oAPI, objProcessInfoList.Item(objProcessInfo), userSuppliedFSO, userSuppliedXmlDom)
If Not (profDiscInfo is nothing) Then
objProfileDiscoveryInfoList.Add profDiscInfo.GetKey, profDiscInfo
End if
Next
Set GetTomcatInstances = objProfileDiscoveryInfoList
End Function
'''
''' Create instances in OpsMgr for all found instances of Tomcat configuration
'''
Public Function ReturnTomcatProfiles(oAPI, ManagementGroup, SourceId, TomcatClassGuid, TomcatReleationGuid, ManagedEntityId, TargetComputer, MajorTomcatVersion)
Dim oDiscoveryData, oInst
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Dim objProfileDiscoveryInfoClass
Set objProfileDiscoveryInfoClass = New ProfileDiscoveryInfoClass
Set objProfileDiscoveryInfoClass.ListOfProfiles = GetTomcatInstances(oAPI, Nothing, Nothing, Nothing, Nothing)
DIM objProfileMonitoringInfo
SET objProfileMonitoringInfo = objProfileDiscoveryInfoClass.ListOfProfiles
Set objProfileMonitoringInfo = DiscoveryWithPersistence(objProfileDiscoveryInfoClass, Nothing, Nothing, ManagementGroup, REGISTRY_PROP_APP_SERVER_TYPE_TOMCAT, Nothing)
DIM entry
FOR EACH entry IN objProfileMonitoringInfo
IF FilterVersion(MajorTomcatVersion, objProfileMonitoringInfo.Item(entry).Version) THEN
set oInst = oDiscoveryData.CreateClassInstance(TomcatClassGuid)
call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/HostName$", TargetComputer)
call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/Id$", objProfileMonitoringInfo.Item(entry).Configuration)
call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/HttpPort$", objProfileMonitoringInfo.Item(entry).HttpPort)
call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/HttpsPort$", objProfileMonitoringInfo.Item(entry).HttpsPort)
call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/Version$", objProfileMonitoringInfo.Item(entry).Version)
call oInst.AddProperty("$MPElement[Name='JEE!Microsoft.JEE.ApplicationServer.Instance']/DiskPath$", objProfileMonitoringInfo.Item(entry).Configuration)
call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Tomcat|" &amp; objProfileMonitoringInfo.Item(entry).Configuration)
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(TomcatReleationGuid)
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

' Copyright (c) Microsoft Corporation. All rights reserved.
' Date Created: August 19th, 2010
'
' This script is to be incorporated into the Tomcat JEE MP.
' This script will discover the running java process of a Tomcat
' Application server's configurations.
' This is captured and returned back to the MP's unit monitor as
' a property bag
'
SetLocale("en-us")
'
' Return the discovered process information to OpsMgr
'
Function ReturnProcessRunning(oAPI, oWmi)
Dim objTomcatProcs
Set objTomcatProcs = GetTomcatProcessesInfo(oWmi, Nothing)
Dim oBag
If oAPI Is Nothing Then
Set oAPI = CreateObject("MOM.ScriptAPI")
End If
Set oBag = oAPI.CreatePropertyBag()
oBag.AddValue "Count", objTomcatProcs.Count
FOR EACH entry IN objTomcatProcs.Keys
oBag.AddValue LCase(entry), "Running"
NEXT
Call oAPI.Return(oBag)
End Function

ReturnProcessRunning nothing, nothing
</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>