Kemp Support, how can we help?

The latest application delivery knowledge and expertise at your fingertips.

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:

http://sourceforge.net/projects/getgnuwin32/files/latest/download?source=rw_dlp_t5
 
The installation will ask which directory to use - in this example  C:\ was used and the files extracted were located in C:\GNUwin32\bin was used.
 
To test WGET for Windows, execute from the command line:
 
C:\>c:\GNUwin32\bin\wget-1.12 www.google.com
--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]
 
2. Enable the API Interface on the LoadMaster
 
Once installed, WGET for Windows can be used with the API to automate large jobs. To allow the API commands to work with the LoadMaster, the API interface on the LoadMaster must be enabled. For instructions on how to do this, refer to the Enabling the LoadMaster RESTful API Interface section of the KEMP RESTful API Interface Description document.
 
3. Create a file in Notepad and save it as a .bat file e.g script.bat.
 
An example of the file to be created is provided in the screenshot below.
 
 
Text:
:: Script to Create Virtual Services on IP 10.140.0.188 Port 8000 up to 8050
:: 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
 
To execute this, open a cmd prompt, navigate to the script location and execute, for example:
C:\Users\exampleusername\Desktop>script
 
More sample scripts are provided below.
 
 
Script to Create Virtual Services
:: Script to Create Virtual Services on IP 10.140.0.170->199 Port 80
:: 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 
 
 
Script to Add Real Servers to a Virtual Service
:: Script to add Real Servers of IP 10.140.0.20->40 Port 80 to VS 10.140.0.201;80 (assuming this Virtual Service was already created)
:: 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)
 
set /a loopcount=loopcount+1
if %loopcount%==41 goto exitloop
goto loop
:exitloop
pause
 
 

Was this article helpful?
0 out of 0 found this helpful

Comments