Действие выборки данных на базе метода HTTP GET (на основе VBScript)

Microsoft.JEE.HttpGet.ProbeAction (ProbeActionModuleType)

Проверка, основанная на методе HTTP GET, которая служит для получения данных

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
ApplicationServerGuidstring$Config/ApplicationServerGuid$GUID сервера приложенийГлобальный уникальный идентификатор (GUID) экземпляра сервера приложений
ComputerNamestring$Config/ComputerName$Имя компьютераИмя компьютера, на котором размещен сервер приложений
Protocolstring$Config/Protocol$ПротоколПротокол, который будет использоваться для выполнения вызовов HTTP
Portstring$Config/Port$ПортНомер порта, который будет использоваться для выполнения вызовов HTTP
URLstring$Config/URL$URL-адресБазовый URL-адрес BeanSpy для выполнения вызова HTTP.
TimeoutSecondsint$Config/TimeoutSeconds$Тайм-аутЗначение времени ожидания (в секундах) периода бездействия для модуля выборки данных

Source Code:

<ProbeActionModuleType ID="Microsoft.JEE.HttpGet.ProbeAction" Accessibility="Public" Batching="false" PassThrough="false">
<Configuration>
<xsd:element name="ApplicationServerGuid" type="xsd:string"/>
<xsd:element name="ComputerName" type="xsd:string"/>
<xsd:element name="Protocol" type="xsd:string"/>
<xsd:element name="Port" type="xsd:string"/>
<xsd:element name="URL" type="xsd:string"/>
<xsd:element name="ReturnMultiplePropertyBags" type="xsd:boolean"/>
<xsd:element name="UseAttributesInKeysOfReturnedPropertyBags" type="xsd:boolean"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="ApplicationServerGuid" ParameterType="string" Selector="$Config/ApplicationServerGuid$"/>
<OverrideableParameter ID="ComputerName" ParameterType="string" Selector="$Config/ComputerName$"/>
<OverrideableParameter ID="Protocol" ParameterType="string" Selector="$Config/Protocol$"/>
<OverrideableParameter ID="Port" ParameterType="string" Selector="$Config/Port$"/>
<OverrideableParameter ID="URL" ParameterType="string" Selector="$Config/URL$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<ProbeAction ID="PassThrough" TypeID="System!System.PassThroughProbe"/>
<ProbeAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
<ScriptName>Microsoft.JEE.HttpGet.vbs</ScriptName>
<Arguments>"$Config/ComputerName$" "$Config/ApplicationServerGuid$" "$Config/Protocol$" "$Config/Port$" "$Config/URL$" $Config/ReturnMultiplePropertyBags$ $Config/UseAttributesInKeysOfReturnedPropertyBags$ "$RunAs[Name="Microsoft.JEE.MonitoringAccount"]/UserName$"</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: June 16th, 2010
'
' This script will perform a a HTTP get call and return a
' propertybag containing the flattened out xml in the key
' and the value in the value.
'
SetLocale("en-us")
Class JVMMonitoringInfo
Public NameValueList
Private Sub class_initialize()
Set NameValueList = CreateObject("Scripting.Dictionary")
End Sub
End Class
'''
''' Constants for use in this script
'''
CONST HTTPGET_SCRIPT_NAME = "HTTPGet.vbs"
'''
''' Return response from HTTP get call
'''
public Function HTTPGet(URL, strUserName, strPassword, objSvrHTTP, xDoc, oAPI)
'response.ContentType = "text/xml"
' Create an XML parser object
if objSvrHTTP is nothing then
Set objSvrHTTP = CreateObject("Microsoft.XmlHttp")
end if
if xDoc is nothing then
set xDoc = CreateObject("Microsoft.XMLDOM")
end if
xDoc.async = False
if URL = Empty then
xDoc.LoadXML("&lt;ERROR&gt;&lt;HTTP&gt;Invalid URL&lt;/HTTP&gt;&lt;/ERROR&gt;")
set HTTPGet = xDoc
LogErrorHTTP oAPI, HTTPGET_SCRIPT_NAME, URL, "Invalid URL", 0
exit function
end if
on error resume next
objSvrHTTP.open "GET", URL, false, strUserName, strPassword
If Err.Number &lt;&gt; 0 Then
xDoc.LoadXML("&lt;ERROR&gt;&lt;HTTP&gt;Error connecting to server&lt;/HTTP&gt;&lt;/ERROR&gt;")
set HTTPGet = xDoc
LogErrorHTTP oAPI, HTTPGET_SCRIPT_NAME, URL, "Error connecting", Err.Number
exit function
End If
objSvrHTTP.send
If Err.Number &lt;&gt; 0 Then
xDoc.LoadXML("&lt;ERROR&gt;&lt;HTTP&gt;Send Error&lt;/HTTP&gt;&lt;/ERROR&gt;")
set HTTPGet = xDoc
LogErrorHTTP oAPI, HTTPGET_SCRIPT_NAME, URL, "Send Error", Err.Number
exit function
End If
IF objSvrHTTP.status &lt;&gt; 200 THEN
xDoc.LoadXML("&lt;ERROR&gt;&lt;HTTP&gt;"&amp; objSvrHTTP.status&amp;"&lt;/HTTP&gt;&lt;/ERROR&gt;")
set HTTPGet = xDoc
LogErrorHTTP oAPI, HTTPGET_SCRIPT_NAME, URL, "HTTP Error", objSvrHTTP.status
exit function
else
if not xDoc.LoadXML(objSvrHTTP.responseText) then
xDoc.LoadXML("&lt;ERROR&gt;&lt;XML&gt;Error loading page XML&lt;/XML&gt;&lt;/ERROR&gt;")
set HTTPGet = xDoc
LogErrorHTTP oAPI, HTTPGET_SCRIPT_NAME, URL, "Error loading page XML", 0
exit function
End If
set HTTPGet = xDoc
end if
End Function
'''
''' Create multiple property bags from the given XML. This is less efficient thaqn containing the HTTP Get result
'''
Public Function ReturnHttpGetResultAsMultiplePropertyBags(objAPI, strHost, strProtocol, strPort, strSourceURL, strUserName, strPassword, boolIncludeAttributes)
DIM objHttpResult
DIM objListOfMonitoringInfo
SET objHttpResult = HTTPGet(strProtocol &amp; "://" &amp; strHost &amp; ":" &amp; strPort &amp; strSourceURL, strUserName, strPassword, NOTHING, NOTHING, objAPI)
SET objListOfMonitoringInfo = FlattenXmlToMultiplePropertyBags(objHttpResult.childNodes, boolIncludeAttributes)
' For the list of objects, create one property bag per returned object
' The flag below is needed to workaround an issue in OpsMgr (see if-statement below)
DIM boolFoundSomething
boolFoundSomething = FALSE
DIM monitoringInfoKey
FOR EACH monitoringInfoKey IN objListOfMonitoringInfo
boolFoundSomething = TRUE
DIM objBag
SET objBag = objAPI.CreatePropertyBag()
DIM objMonitoringInfo
FOR EACH objMonitoringInfo IN objListOfMonitoringInfo.Item(monitoringInfoKey).NameValueList
objBag.AddValue objMonitoringInfo, objListOfMonitoringInfo.Item(monitoringInfoKey).NameValueList.Item(objMonitoringInfo)
NEXT
' Now that the property bag is full, add this to the in memory queue
objAPI.AddItem(objBag)
NEXT
'
' The Operations Manger expects that something should be returned, a warning is
' issued if no property bags are returned. If nothing was found, this warning
' falls under the category of a 'false positive' (i.e. warning when there is no
' error). To workaroound this, a property bag with a well-defined error is returned
' and the expectation is that a Condition/Detection will filter this out.
'
IF NOT boolFoundSomething THEN
DIM objErrorBag
SET objErrorBag = objAPI.CreatePropertyBag()
objErrorBag.AddValue "/ERROR/XML", "MBean query returned an empty set"
objAPI.AddItem(objErrorBag)
END IF
CALL objAPI.ReturnItems
End Function
'''
''' Create property bag containing the HTTP Get result
'''
Public Function ReturnHttpGetResultAsSinglePropertyBag(objAPI, strHost, strProtocol, strPort, strSourceURL, strUserName, strPassword, boolIncludeAttributes)
DIM objBag
DIM objHttpResult
DIM objJVMMonitoringInfo
SET objHttpResult = HTTPGet(strProtocol &amp; "://" &amp; strHost + ":" &amp; strPort &amp; strSourceURL, strUserName, strPassword, NOTHING, NOTHING, objAPI)
SET objBag = objAPI.CreatePropertyBag()
SET objJVMMonitoringInfo = NEW JVMMonitoringInfo
FlattenXmlToSinglePropertyBag objHttpResult.childNodes, "", objJVMMonitoringInfo, boolIncludeAttributes
DIM entry
FOR EACH entry IN objJVMMonitoringInfo.NameValueList.keys
CALL objBag.AddValue(entry, objJVMMonitoringInfo.NameValueList.Item(entry))
NEXT
CALL objAPI.Return(objBag)
End Function
'''
''' Flatten out the xml structure and place the items in the Dictionary.
'''
''' The input nodes element has the xml structure that is recursively parsed
''' and flattened out.
''' The flattened xml elements and their associated values are added
''' to the dictionary. Only elements with values are places in the dictionary.
''' input: &lt;elem1&gt;
''' &lt;elem2&gt;
''' &lt;elem3&gt;val1&lt;/elem3&gt;
''' &lt;elem4&gt;
''' &lt;elem5&gt;val2&lt;/elem5&gt;
''' &lt;/elem4&gt;
''' &lt;/elem2&gt;
''' &lt;elem2&gt;
''' &lt;elem3&gt;val3&lt;/elem3&gt;
''' &lt;elem4&gt;
''' &lt;elem5&gt;val4&lt;/elem5&gt;
''' &lt;/elem4&gt;
''' &lt;/elem2&gt;
''' &lt;/elem1&gt;
''' output:
''' First Property Bag
''' elem1/elem2/elem3 val1
''' elem1/elem2/elem4/elem5 val2
'''
''' Second Property Bag
''' elem1/elem2/elem3 val3
''' elem1/elem2/elem4/elem5 val4
'''
Public Function FlattenXmlToMultiplePropertyBags(objNodes, boolIncludeAttributes)
DIM output
SET output = CreateObject("Scripting.Dictionary")
'
' This logic assumes that the data return is "deep". By that,
' it is meant that the expectation is that the given XML has at least
' two levels. For instance, the first level is MBeans and the second
' level a list of MBeans.
'
' Therefore, the first level of the loop should be unraveled.
'
DIM objXmlNode, intCounter
intCounter = 0
FOR EACH objXmlNode IN objNodes
IF objXmlNode.hasChildNodes THEN
DIM innerNode
FOR EACH innerNode IN objXmlNode.childNodes
DIM objJVMMonitoringInfo
SET objJVMMonitoringInfo = new JVMMonitoringInfo
DIM dispName
dispName = innerNode.nodeName
IF dispName = "MBean" THEN
DIM objNameAttribute
Set objNameAttribute = innerNode.getAttributeNode("Name")
IF NOT objNameAttribute IS NOTHING THEN
dispName = objNameAttribute.text
END IF
END IF
FlattenXmlToSinglePropertyBag innerNode.childNodes, "/" &amp; objXmlNode.nodeName &amp; "/" &amp; dispName, objJVMMonitoringInfo, boolIncludeAttributes
output.Add intCounter, objJVMMonitoringInfo
intCounter = intCounter + 1
NEXT
END IF
NEXT
SET FlattenXmlToMultiplePropertyBags = output
End Function
'''
''' Flatten out the xml structure into a single property bag.
'''
''' The input nodes element has the xml structure that is recursively parsed
''' and flattened out.
''' The flattened xml elements and their associated values are added
''' to the dictionary. Only elements with values are places in the dictionary.
'''
Public Function FlattenXmlToSinglePropertyBag(objNodes, strName, objJVMMonitoringInfo, boolIncludeAttributes)
'
' For each XML node, find the text nodes and add these to the property bag
' with the key being a path to the XML elements (excluding attributes).
DIM objXmlNode
DIM gotValidNode
FOR EACH objXmlNode IN objNodes
gotValidNode = false
' For items that are of type ElementNode and have no children we want to
' add them to the list of XML elements
IF (objXmlNode.nodeType = 1 AND NOT objXmlNode.hasChildNodes) THEN
strName = CreateStringRepresentation(objXmlNode, strName, boolIncludeAttributes)
gotValidNode = true
ELSE
' For items that are of type TextNode add the key and value to the list of XML elements
IF (objXmlNode.nodeType = 3) THEN
gotValidNode = true
END IF
END IF
' Only unique values may be added to the Dictionary
' (as well as the Property Bag upstream). Thus, if the key
' already exists we should NOT add it. This WILL truncate that
' will eventually be used in the Operations Manager workflow.
IF gotValidNode THEN
DIM keyExists
keyExists = objJVMMonitoringInfo.NameValueList.Exists(strName)
IF NOT keyExists THEN
objJVMMonitoringInfo.NameValueList.Add strName, objXmlNode.nodeValue
END IF
END IF
IF objXmlNode.hasChildNodes THEN
DIM strKey
strKey = CreateStringRepresentation(objXmlNode, strName, boolIncludeAttributes)
FlattenXmlToSinglePropertyBag objXmlNode.childNodes, strKey, objJVMMonitoringInfo, boolIncludeAttributes
END IF
NEXT
End Function
'
' Create a unique string representation of the XML. If there are no
' attributes for the XML, then the name conists only of the Node Names
'
''' input: &lt;elem1&gt;
''' &lt;elem2&gt;
''' &lt;elem3&gt;val1&lt;/elem3&gt;
''' &lt;elem4&gt;
''' &lt;elem5&gt;val2&lt;/elem5&gt;
''' &lt;/elem4&gt;
''' &lt;/elem2&gt;
''' &lt;/elem1&gt;
''' output:
''' elem1/elem2/elem3 val1
''' elem1/elem2/elem4/elem5 val2
'
' If include attributes flag has been set, then the attributes
' are then added into the path
'
''' input: &lt;elem1&gt;
''' &lt;elem2 meta="data"&gt;
''' &lt;elem3 type="blah"&gt;val1&lt;/elem3&gt;
''' &lt;elem4&gt;
''' &lt;elem5&gt;val2&lt;/elem5&gt;
''' &lt;/elem4&gt;
''' &lt;/elem2&gt;
''' &lt;/elem1&gt;
''' output:
''' elem1/elem2[meta="data"]/elem3[type="blah"] val1
''' elem1/elem2[meta="data"]/elem4/elem5 val2
'''
Private Function CreateStringRepresentation(objXmlNode, strName, boolIncludeAttributes)
DIM strReturnValue
strReturnValue = strName &amp; "/" &amp; objXmlNode.nodeName
IF objXmlNode.nodeName = "MBean" OR objXmlNode.nodeName = "Property" THEN
DIM objNameAttribute
Set objNameAttribute = objXmlNode.getAttributeNode("Name")
IF NOT objNameAttribute IS NOTHING THEN
strReturnValue = strName &amp; "/" &amp; objNameAttribute.text
END IF
END IF
IF boolIncludeAttributes THEN
DIM objAttributeMap
SET objAttributeMap = objXmlNode.Attributes
IF NOT objAttributeMap IS NOTHING THEN
IF 0 &lt; objAttributeMap.length THEN
DIM i, objAttribute, strAppend
strAppend = ""
FOR i = 0 TO (objAttributeMap.length - 1)
SET objAttribute = objAttributeMap.nextNode
IF strAppend &lt;&gt; "" THEN
strAppend = strAppend &amp; " "
END IF
strAppend = strAppend &amp; objAttribute.nodeName &amp; "=" &amp; chr(34) &amp; objAttribute.Text &amp; chr(34)
NEXT
strReturnValue = strReturnValue &amp; "[" &amp; strAppend &amp; "]"
END IF
END IF
END IF
CreateStringRepresentation = strReturnValue
END Function

'
' Expectation:
' Argument 0 : Computer Name (String)
' Argument 1 : Application Server Instance (GUID)
' Not used directly by the script, but this is necessary to prevent
' cookdown from occuring if from two different Application Servers
' that share the same port and happen to run on the same port (at
' different times obviously)
' Argument 2 : Protocol - HTTP or HTTPS (String)
' Argument 3 : Port (String)
' Argument 4 : Base URL to call (String)
' Argument 5 : Return back as multiple property bags with a MBean per bag (Boolean - true)
' or as a single property bag containing all MBeans (Boolean - false)
' Argument 6 : Include Attributes with keys of returned property bags
' Argument 7 : Username (optional)
'

DIM oArgs, oAPI, strUserName, strPassword

SET oArgs = WScript.Arguments
if oArgs.Count &lt; 7 Then
Wscript.Quit -1
End If

strPassword = ""
IF oArgs.Count &lt; 8 THEN
strUserName = ""
ELSE
strUserName = oArgs(7)
IF NOT WScript.StdIn.AtEndOfStream THEN
strPassword = WScript.StdIn.ReadLine()
END IF
END IF

SET oAPI = CreateObject("MOM.ScriptAPI")

IF oArgs(5) = "true" THEN
ReturnHttpGetResultAsMultiplePropertyBags oAPI, oArgs(0), oArgs(2), oArgs(3), oArgs(4), strUserName, strPassword, oArgs(6)
ELSE
ReturnHttpGetResultAsSinglePropertyBag oAPI, oArgs(0), oArgs(2), oArgs(3), oArgs(4), strUserName, strPassword, oArgs(6)
END IF

</Script></ScriptBody>
<SecureInput>$RunAs[Name="Microsoft.JEE.MonitoringAccount"]/Password$</SecureInput>
<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>