Webservice setup and overview: Difference between revisions
Jump to navigation
Jump to search
(10 intermediate revisions by the same user not shown) | |||
Line 20: | Line 20: | ||
$result->faultstring; | $result->faultstring; | ||
} | } | ||
Sample script (test.pl) | Sample script output (test.pl) | ||
root@myLVS-LinuxClient:/usr/local/dev/mylvs# '''perl test.pl''' | root@myLVS-LinuxClient:/usr/local/dev/mylvs# '''perl test.pl''' | ||
'''200 192.168.2.222''' | '''200 192.168.2.222''' | ||
Line 47: | Line 47: | ||
$result->faultstring; | $result->faultstring; | ||
} | } | ||
Sample script (test.pl): | Sample script output (test.pl): | ||
C:\Users\Administrator\Documents\lvs>'''perl test.pl''' | C:\Users\Administrator\Documents\lvs>'''perl test.pl''' | ||
'''200 192.168.2.221''' | '''200 192.168.2.221''' | ||
Line 77: | Line 77: | ||
xmlDoc.Load objDispatch | xmlDoc.Load objDispatch | ||
WScript.Echo xmlDoc.selectSingleNode("//WHATISMYIPResponse").text | WScript.Echo xmlDoc.selectSingleNode("//WHATISMYIPResponse").text | ||
Sample script (test.vbs): | Sample script output (test.vbs): | ||
C:\Users\Administrator\Documents\lvs>'''cscript test.vbs //Nologo''' | C:\Users\Administrator\Documents\lvs>'''cscript test.vbs //Nologo''' | ||
'''200 192.168.2.221''' | '''200 192.168.2.221''' | ||
Line 104: | Line 104: | ||
'wscript.echo wso.WHATISMYIP(strBLA).result 'Sample for an alternative parameter | 'wscript.echo wso.WHATISMYIP(strBLA).result 'Sample for an alternative parameter | ||
wscript.echo wso.WHATISMYIP().result | wscript.echo wso.WHATISMYIP().result | ||
Sample script (test-lite.vbs): | Sample script output (test-lite.vbs): | ||
C:\Users\Administrator\Documents\lvs>c:\Windows\SysWOW64\cscript.exe test-lite.vbs //nologo | C:\Users\Administrator\Documents\lvs>c:\Windows\SysWOW64\cscript.exe test-lite.vbs //nologo | ||
'''200 192.168.2.221''' | '''200 192.168.2.221''' | ||
Line 115: | Line 115: | ||
<br><br> | <br><br> | ||
= | =Webservice functions= | ||
Note: Additional steps were required to setup webservices, see more details here:<br> | |||
*[[SQL database setup#Webservice prepare|Webservice prepare]] | *[[SQL database setup#Webservice prepare|Webservice prepare]] | ||
Line 143: | Line 143: | ||
=Return Codes= | =Return Codes= | ||
*The LVS-WFE Webservice | *The LVS-WFE Webservice returns the following codes: | ||
*Log Categories | *Log Categories | ||
**2nn = Success | **2nn = Success | ||
Line 184: | Line 184: | ||
<br> | <br> | ||
=Alternative example using Chilkat= | |||
'https://www.example-code.com/vbscript/http_soapPost11.asp | |||
Dim fso, outFile | |||
Set fso = CreateObject("Scripting.FileSystemObject") | |||
Set outFile = fso.CreateTextFile("output.txt", True) | |||
set http = CreateObject("Chilkat_9_5_0.Http") | |||
success = http.UnlockComponent("any code to test") | |||
If (success <> 1) Then | |||
outFile.WriteLine(crypt.LastErrorText) | |||
outFile.WriteLine("unlock failed.") | |||
WScript.Quit | |||
End If | |||
set soapXml = CreateObject("Chilkat_9_5_0.Xml") | |||
soapXml.Tag = "soap:Envelope" | |||
success = soapXml.AddAttribute("soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") | |||
success = soapXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/") | |||
success = soapXml.AddAttribute("xmlns:soapenc","http://schemas.xmlsoap.org/soap/encoding/") | |||
success = soapXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") | |||
success = soapXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") | |||
success = soapXml.UpdateAttrAt("Body|REQUESTWEIGHTSTATUS",1,"xmlns","urn:lvs") | |||
''outFile.WriteLine(soapXml.GetXml()) | |||
set req = CreateObject("Chilkat_9_5_0.HttpRequest") | |||
req.HttpVerb = "POST" | |||
req.SendCharset = 0 | |||
req.AddHeader "Content-Type","text/xml; charset=utf-8" | |||
req.AddHeader "SOAPAction","urn:lvs#REQUESTWEIGHTSTATUS" | |||
req.Path = "/cgi-bin/lvs.cgi" | |||
success = req.LoadBodyFromString(soapXml.GetXml(),"utf-8") | |||
'http.SessionLogFilename = "httpSessionLog.txt" | |||
' resp is a Chilkat_9_5_0.HttpResponse | |||
Set resp = http.SynchronousRequest("ws.hhlvs.intern",80,0,req) | |||
If (http.LastMethodSuccess = 0) Then | |||
outFile.WriteLine(http.LastErrorText) | |||
Else | |||
set xmlResponse = CreateObject("Chilkat_9_5_0.Xml") | |||
success = xmlResponse.LoadXml(resp.BodyStr) | |||
outFile.WriteLine(xmlResponse.AccumulateTagContent("s-gensym3","nothing")) | |||
End If | |||
outFile.Close | |||
'''Same but using the IP Address parameter''' | |||
Dim fso, outFile, strLVSCmd, strLVSHost,strLVSPort,strLVSClientIP | |||
strLVSCmd="REQUESTWEIGHTSTATUS" | |||
strLVSHost="ws.domain.com" | |||
strLVSPort=80 | |||
strLVSClientIP="192.168.x.y" | |||
Set fso = CreateObject("Scripting.FileSystemObject") | |||
Set outFile = fso.CreateTextFile("output.txt", True) | |||
set http = CreateObject("Chilkat_9_5_0.Http") | |||
success = http.UnlockComponent("...code...") | |||
If (success <> 1) Then | |||
outFile.WriteLine(crypt.LastErrorText) | |||
outFile.WriteLine("unlock failed.") | |||
WScript.Quit | |||
End If | |||
set soapXml = CreateObject("Chilkat_9_5_0.Xml") | |||
soapXml.Tag = "soap:Envelope" | |||
success = soapXml.AddAttribute("soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") | |||
success = soapXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/") | |||
success = soapXml.AddAttribute("xmlns:soapenc","http://schemas.xmlsoap.org/soap/encoding/") | |||
success = soapXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") | |||
success = soapXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") | |||
success = soapXml.UpdateAttrAt("soap:Body|" & strLVSCmd ,1,"xmlns","urn:lvs") | |||
success = soapXml.UpdateAttrAt("soap:Body|" & strLVSCmd & "|c-gensym3",1,"xsi:type","xsd:string") | |||
soapXml.UpdateChildContent "soap:Body|" & strLVSCmd & "|c-gensym3",strLVSClientIP | |||
'wscript.echo soapXml.GetXml() | |||
set req = CreateObject("Chilkat_9_5_0.HttpRequest") | |||
req.HttpVerb = "POST" | |||
req.SendCharset = 0 | |||
req.AddHeader "Content-Type","text/xml; charset=utf-8" | |||
req.AddHeader "SOAPAction","urn:lvs#" & strLVSCmd | |||
req.Path = "/cgi-bin/lvs.cgi" | |||
success = req.LoadBodyFromString(soapXml.GetXml(),"utf-8") | |||
'http.SessionLogFilename = "httpSessionLog.txt" | |||
' resp is a Chilkat_9_5_0.HttpResponse | |||
Set resp = http.SynchronousRequest(strLVSHost,strLVSPort,0,req) | |||
If (http.LastMethodSuccess = 0) Then | |||
outFile.WriteLine(http.LastErrorText) | |||
Else | |||
set xmlResponse = CreateObject("Chilkat_9_5_0.Xml") | |||
success = xmlResponse.LoadXml(resp.BodyStr) | |||
outFile.WriteLine(xmlResponse.AccumulateTagContent("s-gensym3","nothing")) | |||
wscript.echo "Status=>" & cint(mid(xmlResponse.AccumulateTagContent("s-gensym3","nothing"),1,3)) & "<= =>" & xmlResponse.AccumulateTagContent("s-gensym3","nothing") | |||
End If | |||
outFile.Close | |||
*'''Note: The webservice requires mylvsmon to run''' | *'''Note: The webservice requires mylvsmon to run''' |
Latest revision as of 15:55, 21 February 2019
Samples
Sample request from a Linux client using perl
Sample script (test.pl) #!/usr/bin/perl -w use SOAP::Lite; # + qw/ trace /; my $soap = SOAP::Lite -> uri('urn:lvs') -> proxy('http://ws.mylvs.foo/cgi-bin/lvs.cgi'); my $result = $soap->WHATISMYIP (); unless ($result->fault) { print $result->result(); } else { print join ', ', $result->faultcode, $result->faultstring; } Sample script output (test.pl) root@myLVS-LinuxClient:/usr/local/dev/mylvs# perl test.pl 200 192.168.2.222 |
|
Sample request from a Windows client using perl
To install the ActiveState Perl Module use: C:\Users\Administrator\Documents\lvs> ppm install Soap-Lite Sample script (test.pl): #!/usr/bin/perl -w use SOAP::Lite; # + qw/ trace /; my $soap = SOAP::Lite -> uri('urn:lvs') -> proxy('http://ws.mylvs.foo/cgi-bin/lvs.cgi'); my $result = $soap->WHATISMYIP (); unless ($result->fault) { print $result->result(); } else { print join ', ', $result->faultcode, $result->faultstring; } Sample script output (test.pl): C:\Users\Administrator\Documents\lvs>perl test.pl 200 192.168.2.221 |
|
Sample request from a Windows client using cscript with MSXML
Set xmlReq = CreateObject("MSXML2.DOMDocument.6.0") request="<SOAP-ENV:Envelope xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' " request = request & "xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' " request = request & "xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' " request = request & "xmlns:xsd='http://www.w3.org/1999/XMLSchema' " request = request & "SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>" request = request & "<SOAP-ENV:Body><mylvs:WHATISMYIP xmlns:mylvs='urn:lvs'/>" 'request = request & "<c-gensym3 xsi:type='xsd:string'>192.168.xx.yy</c-gensym3>" 'alternative param request = request & "</SOAP-ENV:Body></SOAP-ENV:Envelope>" xmlReq.loadXML request 'load our request Set xmlRes = CreateObject("MSXML2.XMLHTTP.6.0") xmlRes.open "POST", "http://ws.mylvs.foo/cgi-bin/lvs.cgi" xmlRes.send (xmlReq) while xmlRes.readyState <> 4 wend Set objDispatch = xmlRes.responseXML set xmlDoc = CreateObject("MSXML2.DOMDocument") xmlDoc.Load objDispatch WScript.Echo xmlDoc.selectSingleNode("//WHATISMYIPResponse").text Sample script output (test.vbs): C:\Users\Administrator\Documents\lvs>cscript test.vbs //Nologo 200 192.168.2.221 |
|
Sample request from a Windows client using cscript with SoapLite
Soaplite is a smart way to handle our request. It still runs as 32bit application on Server2012
Soaplite must be registered with the 32bit part of regsvr: C:\Users\Administrator\Documents\lvs>c:\Windows\SysWOW64\regsvr32.exe Lite.dll Sample script (test-lite.vbs): strSoapProxy="http://ws.mylvs.foo/cgi-bin/lvs.cgi" strSoapURI = "urn:lvs" set wso = CreateObject("SOAP.Lite").new("proxy", strSoapProxy, "uri",strSoapURI ) 'wscript.echo wso.WHATISMYIP(strBLA).result 'Sample for an alternative parameter wscript.echo wso.WHATISMYIP().result Sample script output (test-lite.vbs): C:\Users\Administrator\Documents\lvs>c:\Windows\SysWOW64\cscript.exe test-lite.vbs //nologo 200 192.168.2.221 |
|
Webservice functions
Note: Additional steps were required to setup webservices, see more details here:
- The LVS-WFE Webservice offers the following functions:
Function | Optional Paramter | Description | Return |
---|---|---|---|
REQUESTWEIGHTDOWN | String (a ip address like 192.168.1.1) | Request to set the host offline | String (Code(d{3}) Description |
REQUESTWEIGHTUP | String (a ip address like 192.168.1.1) | Request to set the host online | String (Code(d{3}) Description |
REQUESTWEIGHTSTATUS | String (a ip address like 192.168.1.1) | Request the current status | String (Code(d{3}) Description |
REQUESTGROUPINFORMATION | String (a ip address like 192.168.1.1) | Request the current group configuration | String (Code(d{3}) Description |
WHATISMYIP | - | - | - |
Return Codes
- The LVS-WFE Webservice returns the following codes:
- Log Categories
- 2nn = Success
- 3nn = Logical Errors
- 4nn = Functional Errors
- 5nn = Access or Request Errors
Code | Description | Return |
---|---|---|
200 | Request accepted (function defined message) | True |
300 | WeigthDown in process | False |
301 | TurnOff in process | False |
302 | Another maintenance service is already running | False |
304 | Host has already maintenance running, please come back later | False |
305 | Host has already ip renew set, please come back later | False |
306 | Host has already ip renewed a few minutes ago, please come back later | False |
307 | Host not found in inventory | False |
407 | IP renew is not set (debugging only) | False |
408 | Function not supported (debugging only) | False |
500 | Access denied or Request Refused | False |
501 | Access denied - update failed, contact IT-Admin | False |
Alternative example using Chilkat
'https://www.example-code.com/vbscript/http_soapPost11.asp Dim fso, outFile Set fso = CreateObject("Scripting.FileSystemObject") Set outFile = fso.CreateTextFile("output.txt", True) set http = CreateObject("Chilkat_9_5_0.Http") success = http.UnlockComponent("any code to test") If (success <> 1) Then outFile.WriteLine(crypt.LastErrorText) outFile.WriteLine("unlock failed.") WScript.Quit End If set soapXml = CreateObject("Chilkat_9_5_0.Xml") soapXml.Tag = "soap:Envelope" success = soapXml.AddAttribute("soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") success = soapXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/") success = soapXml.AddAttribute("xmlns:soapenc","http://schemas.xmlsoap.org/soap/encoding/") success = soapXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") success = soapXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") success = soapXml.UpdateAttrAt("Body|REQUESTWEIGHTSTATUS",1,"xmlns","urn:lvs") outFile.WriteLine(soapXml.GetXml()) set req = CreateObject("Chilkat_9_5_0.HttpRequest") req.HttpVerb = "POST" req.SendCharset = 0 req.AddHeader "Content-Type","text/xml; charset=utf-8" req.AddHeader "SOAPAction","urn:lvs#REQUESTWEIGHTSTATUS" req.Path = "/cgi-bin/lvs.cgi" success = req.LoadBodyFromString(soapXml.GetXml(),"utf-8") 'http.SessionLogFilename = "httpSessionLog.txt" ' resp is a Chilkat_9_5_0.HttpResponse Set resp = http.SynchronousRequest("ws.hhlvs.intern",80,0,req) If (http.LastMethodSuccess = 0) Then outFile.WriteLine(http.LastErrorText) Else set xmlResponse = CreateObject("Chilkat_9_5_0.Xml") success = xmlResponse.LoadXml(resp.BodyStr) outFile.WriteLine(xmlResponse.AccumulateTagContent("s-gensym3","nothing")) End If outFile.Close
Same but using the IP Address parameter
Dim fso, outFile, strLVSCmd, strLVSHost,strLVSPort,strLVSClientIP strLVSCmd="REQUESTWEIGHTSTATUS" strLVSHost="ws.domain.com" strLVSPort=80 strLVSClientIP="192.168.x.y" Set fso = CreateObject("Scripting.FileSystemObject") Set outFile = fso.CreateTextFile("output.txt", True) set http = CreateObject("Chilkat_9_5_0.Http") success = http.UnlockComponent("...code...") If (success <> 1) Then outFile.WriteLine(crypt.LastErrorText) outFile.WriteLine("unlock failed.") WScript.Quit End If set soapXml = CreateObject("Chilkat_9_5_0.Xml") soapXml.Tag = "soap:Envelope" success = soapXml.AddAttribute("soap:encodingStyle","http://schemas.xmlsoap.org/soap/encoding/") success = soapXml.AddAttribute("xmlns:soap","http://schemas.xmlsoap.org/soap/envelope/") success = soapXml.AddAttribute("xmlns:soapenc","http://schemas.xmlsoap.org/soap/encoding/") success = soapXml.AddAttribute("xmlns:xsd","http://www.w3.org/2001/XMLSchema") success = soapXml.AddAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance") success = soapXml.UpdateAttrAt("soap:Body|" & strLVSCmd ,1,"xmlns","urn:lvs") success = soapXml.UpdateAttrAt("soap:Body|" & strLVSCmd & "|c-gensym3",1,"xsi:type","xsd:string") soapXml.UpdateChildContent "soap:Body|" & strLVSCmd & "|c-gensym3",strLVSClientIP 'wscript.echo soapXml.GetXml() set req = CreateObject("Chilkat_9_5_0.HttpRequest") req.HttpVerb = "POST" req.SendCharset = 0 req.AddHeader "Content-Type","text/xml; charset=utf-8" req.AddHeader "SOAPAction","urn:lvs#" & strLVSCmd req.Path = "/cgi-bin/lvs.cgi" success = req.LoadBodyFromString(soapXml.GetXml(),"utf-8") 'http.SessionLogFilename = "httpSessionLog.txt" ' resp is a Chilkat_9_5_0.HttpResponse Set resp = http.SynchronousRequest(strLVSHost,strLVSPort,0,req) If (http.LastMethodSuccess = 0) Then outFile.WriteLine(http.LastErrorText) Else set xmlResponse = CreateObject("Chilkat_9_5_0.Xml") success = xmlResponse.LoadXml(resp.BodyStr) outFile.WriteLine(xmlResponse.AccumulateTagContent("s-gensym3","nothing")) wscript.echo "Status=>" & cint(mid(xmlResponse.AccumulateTagContent("s-gensym3","nothing"),1,3)) & "<= =>" & xmlResponse.AccumulateTagContent("s-gensym3","nothing") End If outFile.Close
- Note: The webservice requires mylvsmon to run