Avi 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, Avi Load Balancer provides DataScript, a Lua-based scripting environment capable of adding significant extensibility to the Avi 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 Avi Load Balancer-specific libraries added to extend the power. The basic DataScript syntax is based on Lua, with additional commands, called functions, available for Avi 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 Avi 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 Avi 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 Avi 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 Avi 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.