How to use RESTfulAPI and Windows WGET for automation of LoadMaster Configuration Tasks
The LoadMaster RESTful API allows a user or application to pass HTTPS requests (which can execute configuration commands or retrieve LoadMaster information) to the LoadMaster. This is very useful for automatic device configuration.
Please refer to the following article in order to Enable RESTful API Interface.
The KEMP RESTful API Programmer Guide provides details on how to perform a number of tasks.
Some examples of how to use the RESTful API for scripting some tasks performed through Windows are provided below.
The following is a guide for using Bash Scripts in Windows to automate some LoadMaster configuration tasks.
These can be adjusted to perform many tasks where the basic operation is to iterate through the same command numerous times with slight changes, for example, adding multiple Virtual Services with incrementing IP addresses.
1.Install WGET for Windows
To follow these examples, first download and install WGET for Windows:
--2015-06-30 08:54:00-- http://www.google.com/
Resolving www.google.com... 216.58.208.68
Connecting to www.google.com|216.58.208.68|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.google.ie/?gws_rd=cr&ei=F0uSVZSKDKiy7QbK-oTQCg [following]
--2015-06-30 08:54:00-- http://www.google.ie/?gws_rd=cr&ei=F0uSVZSKDKiy7QbK-oTQ
Cg
Resolving www.google.ie... 216.58.208.35
Connecting to www.google.ie|216.58.208.35|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: `index.html@gws_rd=cr&ei=F0uSVZSKDKiy7QbK-oTQCg'
[ <=> ] 18,532 --.-K/s in 0.001s
2015-06-30 08:54:00 (22.2 MB/s) - `index.html@gws_rd=cr&ei=F0uSVZSKDKiy7QbK-oTQC
g' saved [18532]
:: Loadmaster IP is 10.140.0.183. bal:2fourall
:: Win wget installed in c:\GNUwin32\bin\wget-1.12
:: Restful API enabled on Loadmaser
:: Start at 6000
set loopcount=8000
:loop
set var="https://bal:2fourall@10.140.0.183/access/addvs?vs=10.140.0.88&port="
set var2="&prot=tcp"
set fullstring=%var%%loopcount%%var2%
echo %fullstring%
c:\GNUwin32\bin\wget-1.12 -q -O NUL %fullstring% --no-check-certificate
:: Increment by one each time i.e 8000,8001 as far as 8051(This will cause exitloop and not run for 8051)
set /a loopcount=loopcount+1
if %loopcount%==8051 goto exitloop
goto loop
:exitloop
pause
:: LoadMaster IP is 10.140.0.183. bal:2fourall
:: Win WGET installed in c:\GNUwin32\bin\wget-1.12
:: RESTful API enabled on Loadmaser
:: Start at 170
set loopcount=170
:loop
set var="https://bal:2fourall@10.140.0.183/access/addvs?vs=10.140.0."
set var2="&port=80&prot=tcp"
set fullstring=%var%%loopcount%%var2%
echo %fullstring%
c:\GNUwin32\bin\wget-1.12 -q -O NUL %fullstring% --no-check-certificate
:: Increment by one each time i.e 170,171.. 200
set /a loopcount=loopcount+1
if %loopcount%==200 goto exitloop
goto loop
:exitloop
pause
:: The LoadMaster IP address is 10.140.0.183. bal:2fourall
:: Win WGET is installed in c:\GNUwin32\bin\wget-1.12
:: RESTful API is enabled on the LoadMaster - command https://<LoadMasterIPAddress>/access/addrs?vs=<IPaddr>&port=<Port>&prot=<tcp/udp>&rs=<RS IPaddr>&rsport=<RS-Port>
:: Start at 20
set loopcount=20
:loop
set var="https://bal:2fourall@10.140.0.183/access/addrs?vs=10.140.0.201&port=80&prot=tcp&rs=10.140.0."
set var2="&rsport=80"
set fullstring=%var%%loopcount%%var2%
echo %fullstring%
c:\GNUwin32\bin\wget-1.12 -q -O NUL %fullstring% --no-check-certificate
:: Increment by one each time i.e 20,21 .. 41 (41 will exit)
if %loopcount%==41 goto exitloop
goto loop
:exitloop
pause