NSX Advanced Load Balancer is configured directly through the GUI, CLI, or API. However, there may be occasions where the native feature set is not robust enough to cater to a specific use case. For this purpose, NSX Advanced Load Balancer provides DataScript, a Lua-based scripting environment capable of adding significant extensibility to the NSX Advanced Load Balancer functionality.

DataScripts are advanced versions of the policies, allowing inspection and manipulation of client and server traffic. DataScripts are used to inspect client HTTP requests or server HTTP responses and perform content switching, redirection, header manipulation, logging, and more. The DataScript scripting language is built upon an embedded Lua interpreter, with additional NSX Advanced Load Balancer-specific libraries added to extend the power. The basic DataScript syntax is based on Lua, with additional commands, called functions, available for NSX Advanced Load Balancer-specific tasks. For in-depth help on Lua scripting syntax and usage, see www.lua.org.

DataScripts are executed within the data plane on the Service Engines hosting the virtual service to which the DataScript has been attached. DataScript is different from ControlScript, a Python-based scripting tool for automation of the control plane and executed from the NSX Advanced Load Balancer Controller. A typical DataScript will typically be in some form of if / then logic, similar to a policy’s match/action logic.

path = avi.http.get_path()
if string.beginswith(path, "/docs/") then
   avi.http.redirect("http://docs.avinetworks.com/index.html")
end
Note:

IPv6 is not supported for DataScripts as yet in NSX Advanced Load Balancer.

  • DataScript Events: Each DataScript will be executed when an event is triggered, such as when thezxz virtual service receives an HTTP request or HTTP response. A DataScript must be executed within one or more events.

  • DataScript Constructs Operators: DataScripts may make use of operators, which can be relational, logical, or arithmetic.

  • DataScript Functions: Functions are NSX Advanced Load Balancer-specific commands, such as HTTP redirects or closing a client connection.

    Datascript contains two types of functions which are Layer 4 DataScript functions and Layer 7 DataScript functions , respectively.

  • Execution Priority: DataScripts have a complex relationship with other features within NSX Advanced Load Balancer. It is important to understand the order of execution priority when multiple DataScripts are attached to a virtual service or when policies and other features conflict with the DataScripts.

  • Troubleshooting: DataScripts may fail to save or load at the time of configuration, or they may be created without issue but fail to execute when applied to traffic.