【发布时间】:2021-08-09 20:33:33
【问题描述】:
我有一个 powershell 脚本,它将进行一次肥皂调用,并执行以下操作: 1.连接到托管 WSDL 的服务器(在应用程序术语中称为单元) 2.在其中创建一个事件(警报)。 3.与托管 WSDL 的服务器断开连接(在应用程序术语中称为单元) 我想创建这个脚本的 perl 版本.. 它执行相同的操作,请帮助我提供功能和示例。或者如果可能的话,用 perl 重写下面的脚本。 提前非常感谢您:
PS脚本如下:
================================================ =================================
$severity = "MAJOR"
$msg = "Test event from Powershell"
$cellname = "mycell"
$url = "http://iiwshostname:9080/imws/services/ImpactManager/"
$headers = @{ "SOAPAction" = "Connect"}
$soap = [xml]@"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:imap="http://blueprint.bmc.com/ImapiElems">
<soapenv:Header/>
<soapenv:Body>
<imap:Connect>
<imap:userName>admin</imap:userName>
<imap:password>admin</imap:password>
<imap:imname>$cellname</imap:imname>
<imap:bufferType>BMCII_BUFFER_MODE_DEFAULT</imap:bufferType>
</imap:Connect>
</soapenv:Body>
</soapenv:Envelope>
"@
[xml]$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers
$connectionId = $ret.GetElementsByTagName("imap:connectionId").'#text'
$headers = @{ "SOAPAction" = "SendEvent"}
$soap = [xml]@"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:imap="http://blueprint.bmc.com/ImapiElems" xmlns:bas="http://blueprint.bmc.com/BasicTypes" xmlns:even="http://blueprint.bmc.com/Event">
<soapenv:Header/>
<soapenv:Body>
<imap:SendEvent>
<imap:connection>$connectionId</imap:connection>
<imap:message>
<bas:NameValue_element>
<bas:name>msg</bas:name>
<bas:value>
<bas:string_value>$msg</bas:string_value>
</bas:value>
<bas:value_type>STRING</bas:value_type>
</bas:NameValue_element>
<bas:NameValue_element>
<bas:name>severity</bas:name>
<bas:value>
<bas:string_alue>$severity</bas:string_value>
</bas:value>
<bas:value_type>STRING</bas:value_type>
</bas:NameValue_element>
<even:subject></even:subject>
</imap:message>
<imap:timeout>60</imap:timeout>
<imap:messageClass>EVENT</imap:messageClass>
<imap:messageType>MSG_TYPE_NEW_EVENT</imap:messageType>
</imap:SendEvent>
</soapenv:Body>
</soapenv:Envelope>
"@
[xml]$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers
$mc_ueid = $ret.GetElementsByTagName("imap:response").'#text'
$headers = @{ "SOAPAction" = "Disconnect"}
$soap = [xml]@"
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soapenvelope/" xmlns:imap="http://blueprint.bmc.com/ImapiElems">
<soapenv:Header/>
<soapenv:Body>
<imap:Disconnect>
<imap:connection>$connectionId</imap:connection>
<imap:deleteBuffer>No</imap:deleteBuffer>
</imap:Disconnect>
</soapenv:Body>
</soapenv:Envelope>
"@
$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' -Body $soap -Headers $headers
write-host $mc_ueid
================================================ =================================
【问题讨论】:
-
这里是上述 PS 脚本communities.bmc.com/thread/92279 的来源,但我想修改和增强这个脚本以供我自己使用。所以我想了解要使用哪些功能。如何?在 perl 中“SOAP::lite 模块是最好的一种使用”是从研究中得到的。
-
我不知道你是从什么研究中得到的,但比起可怕的 SOAP::Lite,强烈推荐 XML::Compile::SOAP,并且得到作者更好的支持。
-
@Grinnz 非常感谢。,但我想知道 -----[xml]$ret = Invoke-WebRequest $url -Method post -ContentType 'text/xml' 的等效功能-Body $soap -Headers $headers------这个在perl中,我会通过你提到的模块????
标签: xml powershell perl web-services soap