The following group functions are available in DataScripts:

Function

Description

avi.ipgroup.contains( ipgroup, ip-address )

Compare an IP address against IPs within an IP Group.

avi.stringgroup.beginswith( stringgroup, string )

Compare a string against a list of strings within a string group.

avi.stringgroup.contains( stringgroup, string )

Compare a string against a list of strings within a string group.

avi.stringgroup.equals( stringgroup, string )

Compare a string against a list of strings within a string group.

avi.stringgroup.endswith( stringgroup, string )

Compare a string against a list of strings within a string group.

avi.ipgroup.contains

Function

avi.ipgroup.contains ( ipgroup, ipaddress )

Description

An IPv4 or IPv6 address is compared against the list of IP addresses in an IP group. The IP group can be either a list of IP addresses, networks, or countries.

The comparison returns true upon any match.

For example, if the IP group has entries for 10.0.0.0/8, 10.10.0.0/16, and 10.10.10.10 and the evaluated IP address is 10.10.10.10, the function matches successfully.

Events

HTTP_REQ

HTTP_RESP

Parameter

ipgroup is the name of the IP group to make the comparison against. The IP group must be mapped to the DataScript in the DataScript creation of the GUI or API.

ipaddress is an IP address in dotted quad notation (1.2.3.4).

The IP group Datascript accepts IP Group names as variables. For example,

ipgrp_name = "IPGRP1"
avi.ipgroup.contains(ipgrp_name, ip_address)

Returns

match returns true if a match was found, or false for no match.

Related

avi.stringgroup.contains() - Matches a custom string against a string group.

Example

Discard clients matched against an IP blacklist.

var = avi.vs.client_ip()
if avi.ipgroup.contains("IP-Group", var) then
   avi.vs.log("Blacklisted IP" .. var.. "attempting to log in")
   avi.http.close_conn()
end

avi.stringgroup.beginswith

Function

avi.stringgroup.beginswith( stringgroup, string )

Description

String groups are simple lists of string data. This function evaluates a custom string to see if it begins with an entry in the string group that matches. If the string group has been configured as a key-value pair mapping, the string is compared to see if it matches a key, and returns the string from the key's value field.

When there are multiple candidate keys matching the given string, the result is dependent on the setting of the ‘Longest Match’ flag in the string group. When ‘Longest Match’ is enabled, the longest candidate key that matches the given string will be selected; when ‘Longest Match’ is disabled, the shortest candidate key that matches the given string will be selected.

Events

HTTP_REQ

HTTP_RESP

Parameter

stringgroup is the name of the string group to make the comparison against. The string group must be mapped to the DataScript in the DataScript creation of the GUI or API.

string is the custom data to search for within the string group.

CASE is for doing a case-sensitive check. By default, the comparison is performed as case insensitive. To perform the case as sensitive, use the following syntax:

avi.stringgroup.beginswith_CASE( "stringgroup", "string")

The String group Datascript also accepts String Group names as variables.

Example:

client = avi.http.get_header("SessionID")
strgrp_name = "StringGroup"
val, match = avi.stringgroup.beginswith(strgrp_name, client)

Returns

One or two variables can be returned from this function, depending on the type of string group referenced.

value If the string group is configured for key-value pair, the string parameter is compared against the key, and the value is returned in the value variable. If the string group is not configured for key value pair, the value variable will be nil.

match returns true if a match was found, or false if no match.

Related

avi.ipgroup.contains(): Matches an IP address against an IP group.

avi.stringgroup.contains(): Matches if a string group entry contains part of another string.

avi.stringgroup.endswith(): Matches if a string group entry ends with part of another string.

avi.stringgroup.equals(): Matches if a string group entry equals another string.

Example

The following example must be used with a String Group configured with key-value pair enabled.

client = avi.http.get_header("SessionID")
val, match = avi.stringgroup.beginswith("StringGroup", client)
if match then
   avi.vs.log("User " .. val .. "authorized.")
else
   -- Deny users not in the whitelist
   avi.http.response(403)
end
The String group Datascript also accepts String Group names as variables.

Example:

StringGroup="abc" val, match = avi.stringgroup.beginswith("StringGroup", client)

avi.stringgroup.contains

Function

avi.stringgroup.contains ( stringgroup, string )

Description

String groups are simple lists of string data. This functions evaluates a custom string to see if it exists within an entry of a string group. If the string group has been configured as a key-value pair mapping, the string is compared to see if it matches a key, and returns the string from the key's value field.

When there are multiple candidate keys matching the given string, the result is dependent on the setting of the ‘Longest Match’ flag in the string group. When ‘Longest Match’ is enabled, the longest candidate key that matches the given string will be selected; when ‘Longest Match’ is disabled, the shortest candidate key that matches the given string will be selected.

Events

HTTP_REQ

HTTP_RESP

Parameter

stringgroup is the name of the String Group to compare against. The string group must be mapped to the DataScript in the DataScript creation of the GUI or API.

string is the custom data to search for within the string group.

CASE is for doing a case-sensitive check. By default, the comparison is performed as case insensitive. In order to perform the case as sensitive, use the following syntax: avi.stringgroup.contains_CASE( "stringgroup", "string")

The String group Datascript also accepts String Group names as variables.

Example:

strgrp_name = "StringGroup"
val, match = avi.stringgroup.contains(strgrp_name, client)

Returns

One or two variables might be returned from this function, depending on the type of string group referenced.

value: If the string group is configured for key value pair the string parameter is compared against the key, and the value is returned in the value variable. If the string group is not configured for key value pair, the value variable will be nil.

match: returns true if a match was found, or nil for no match.

Related

avi.ipgroup.contains(): Matches an IP address against an IP group.

avi.stringgroup.beginswith(): Matches if a string group entry begins with part of another string.avi.stringgroup.endswith(): Matches if a string group entry ends with part of another string.avi.stringgroup.equals(): Matches if a string group entry equals another string.

Example

The following example must be used with a string group configured with key value pair enabled.

client = avi.http.get_header("Authorization")
val, match = avi.stringgroup.contains("StringGroup", client)
if match then
   avi.vs.log("User " .. val .. "authorized.")
else
   -- Deny users not in the whitelist
   avi.http.response(403)
end

avi.stringgroup.equals

Function

avi.stringgroup.equals( stringgroup, string )

Description

String groups are simple lists of string data. This function evaluates a custom string to see if it exactly matches an entry in the string group. If the string group has been configured as a key-value pair mapping, the string is compared to see if it matches a key, and returns the key's value field.

Events

HTTP_REQ

HTTP_RESP

Parameter

stringgroup is the name of the string group to make the comparison against. The string group must be mapped to the DataScript in the DataScript creation of the GUI or API.

string is the custom data to search for within the string group.

CASE is for doing a case-sensitive check. By default, the comparison is performed as case insensitive. To perform the case as sensitive, use the following syntax:

avi.stringgroup.endswith_CASE( "stringgroup", "string")

The String Group DataScript accepts String Group names as variables also for L7 DataScripts.

Example:

strgrp_name = "StringGroup"
val, match = avi.stringgroup.equals(strgrp_name, avi.http.hostname())

Returns

Two variables are always returned by this function.

value If the string group is configured for key-value pair, the string parameter is compared against the key, and the value is returned in the value variable. If the string group is not configured for key-value pair, the value variable is still be returned, but its value is always nil.

match returns true if a match is found, or false for no match.

Related

avi.ipgroup.contains(): Matches an IP address against an IP group.

avi.stringgroup.contains(): Matches if a string group entry contains part of another string.

avi.stringgroup.beginswith(): Matches if a string group entry begins with part of another string.

avi.stringgroup.endswith(): Matches if a string group entry ends with part of another string.

Example 1

The following example checks if the userID is in an approved list, before allowing access to the site. This is a case where we expect val to always return as nil.

val, match = avi.stringgroup.equals("StringGroup", avi.http.get_userid())
if not match then 
   avi.http.redirect("https://login.site.com") 
end

Example 2

This example redirects clients based on location embedded into the host header, by moving the location into the beginning of the path. The following table illustrates the key-values stored in the string group. In this case, if match is true, val contains the corresponding value.

key

value

us.test.com

/us

eu.test.com

/eu

ap.test.com

/ap

sa.test.com

/sa

val, match = avi.stringgroup.equals("StringGroup", avi.http.hostname())
if match then 
   avi.http.redirect("https://www.test.com" .. val .. avi.http.get_url())
end
sa.test.com/path/index.htm?query=1 will be redirected to www.test.com/sa/path/index.htm?query=1.

avi.stringgroup.endswith

Function

avi.stringgroup.endswith( stringgroup, string )

Description

String groups are simple lists of string data. This function evaluates a custom string to see if it ends with an entry in the string group that matches. If the string group has been configured as a key-value pair mapping, the string is compared to see if it matches a key, and will return the key's value field.

When there are multiple candidate keys matching the given string, the result is dependent on the setting of the ‘Longest Match’ flag in the string group. When ‘Longest Match’ is enabled, the longest candidate key that matches the given string will be selected; when ‘Longest Match’ is disabled, the shortest candidate key that matches the given string will be selected.

Events

HTTP_REQ

HTTP_RESP

Parameter

stringgroup is the name of the string group to make the comparison against. The string group must be mapped to the DataScript in the DataScript creation of the GUI or API.

string is the custom data to search for within the string group.

CASE - By default, the comparison is performed as case insensitive. To perform the case as sensitive, use the following syntax:

avi.stringgroup.endswith_CASE( "stringgroup", "string")

The String group Datascript accepts String Group names as variables too.

For example,

strgrp_name = "StringGroup"
val, match = avi.stringgroup.endswith(strgrp_name, path)

Returns

One or two variables may be returned from this function, depending on the type of string group referenced.

value If the string group is configured for key value pair, the string parameter is compared against the key, and the value is returned in the value variable. If the string group is not configured for key value pair, the value variable will be nil.

match returns true if a match was found, or false if no match.

Related

avi.ipgroup.contains(): Matches an IP address against an IP group.

avi.stringgroup.contains(): Matches if a string group entry contains part of another string.

avi.stringgroup.beginswith(): Matches if a string group entry begins with part of another string.

avi.stringgroup.equals(): Matches if a string group entry equals another string.

Example

The following example checks if the URL's path ends with an approved type, such as, .html, .png or .css. Other file types not in the list are discarded. This example uses the standard string list, instead of the key value pair.

path = avi.http.get_path()
val, match = avi.stringgroup.endswith("StringGroup", path) 
if not match then
   avi.http.response(404) 
end