Fortinet black logo

LB commands

LB commands

LB commands contain load balancing manipulating functions, with the most important function being LB:routing which allows you to select the backend:

LB:routing(value) — Routes the request to the content routing server.

LB:get_valid_routing() — Returns a list of backend names configured on the current Virtual Server in the form of a Lua table (number as key, string as value).

LB:get_current_routing() — Returns the currently allocated backend for this request.

LB:method_assign_server() — Returns the server through the current load balance method configured on current the Virtual Server.

LB:routing(value)

Routes the request to the content routing server.

Syntax

LB:routing(value);

Arguments
Name Description

value

A string which specifies the content routing to route.

Example

when HTTP_REQUEST {

LB:routing(“content_routing1”);

}

--supports multiple routing

LB:routing(“cr1”)

LB:routing(“cr2”)

--It will be routed to cr2; the final one prevails.

Note:

When a VS enables both content-routing and scripting, then this function will perform a cross-check to check the content-routing used in scripting is applied to the VS.

FortiADC version: V4.3

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST

LB:get_valid_routing()

Returns a list of backend names configured on the current Virtual Server in the form of a Lua table (number as key, string as value).

Since there must be at least one backend, the returned value cannot be nil or empty. In case of a single routing with zero or one content routing configured, the pool name will be returned.

Syntax

LB:get_valid_routing();

Arguments

N/A

Example
when HTTP_REQUEST {
t=LB:get_valid_routing()
for k, v in pairs(t) do
debug("Key: %d Value: %s\n", k, v)
end
}

FortiADC version: V7.2

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST / AUTH_RESULT

LB:get_current_routing()

Returns the currently allocated backend for this request.

If there is only one backend configured, this function returns the backend name in a string format. If there are multiple backends available, and they are already set via LB:routing(), then this function returns the backend name as a string. Otherwise, this returns an empty string if no backend is configured.

In case of a single routing with zero or one content routing configured, the pool name will be returned.

Syntax

LB:get_current_routing();

Arguments

N/A

Example
when HTTP_REQUEST {
t=LB:get_current_routing()
if (s == nil or s == '') then
       s = "No backend returned."
       end
      debug("current routing: %s\n", s).
}

FortiADC version: V7.2

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST / AUTH_RESULT

LB:method_assign_server()

Returns the server through the current load balance method configured on current the Virtual Server.

The implementation will first check whether the backend is already set. If the backend is set, then it runs the load balance algorithm to assign a server and returns the server name as a string. If the backend is not set, the function returns an empty string, and then FortiADC will set the backend only if there is only one backend available. If there is no server available in the corresponding pool or all the servers are down in the pool, an empty string will also be returned.

Syntax

LB:method_assign_server();

Arguments

N/A

Example
when HTTP_REQUEST {
    s=LB:method_assign_server()
    if (s == nil or s == '') then
    s = "No Server returned."
    end
   debug("assign server: '%s'\n", s)
}

Note:

The result may be overwritten by functions in PERSISTENCE events, which happen after HTTP_REQUEST. For example, this function returns server01. But the PERSISTENCE event specifies to use server02. The result from the PERSISTENCE event (server02) will always supercede results from non-PERSISTENCE events (server01).

FortiADC version: V7.2

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST / AUTH_RESULT

LB commands

LB commands contain load balancing manipulating functions, with the most important function being LB:routing which allows you to select the backend:

LB:routing(value) — Routes the request to the content routing server.

LB:get_valid_routing() — Returns a list of backend names configured on the current Virtual Server in the form of a Lua table (number as key, string as value).

LB:get_current_routing() — Returns the currently allocated backend for this request.

LB:method_assign_server() — Returns the server through the current load balance method configured on current the Virtual Server.

LB:routing(value)

Routes the request to the content routing server.

Syntax

LB:routing(value);

Arguments
Name Description

value

A string which specifies the content routing to route.

Example

when HTTP_REQUEST {

LB:routing(“content_routing1”);

}

--supports multiple routing

LB:routing(“cr1”)

LB:routing(“cr2”)

--It will be routed to cr2; the final one prevails.

Note:

When a VS enables both content-routing and scripting, then this function will perform a cross-check to check the content-routing used in scripting is applied to the VS.

FortiADC version: V4.3

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST

LB:get_valid_routing()

Returns a list of backend names configured on the current Virtual Server in the form of a Lua table (number as key, string as value).

Since there must be at least one backend, the returned value cannot be nil or empty. In case of a single routing with zero or one content routing configured, the pool name will be returned.

Syntax

LB:get_valid_routing();

Arguments

N/A

Example
when HTTP_REQUEST {
t=LB:get_valid_routing()
for k, v in pairs(t) do
debug("Key: %d Value: %s\n", k, v)
end
}

FortiADC version: V7.2

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST / AUTH_RESULT

LB:get_current_routing()

Returns the currently allocated backend for this request.

If there is only one backend configured, this function returns the backend name in a string format. If there are multiple backends available, and they are already set via LB:routing(), then this function returns the backend name as a string. Otherwise, this returns an empty string if no backend is configured.

In case of a single routing with zero or one content routing configured, the pool name will be returned.

Syntax

LB:get_current_routing();

Arguments

N/A

Example
when HTTP_REQUEST {
t=LB:get_current_routing()
if (s == nil or s == '') then
       s = "No backend returned."
       end
      debug("current routing: %s\n", s).
}

FortiADC version: V7.2

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST / AUTH_RESULT

LB:method_assign_server()

Returns the server through the current load balance method configured on current the Virtual Server.

The implementation will first check whether the backend is already set. If the backend is set, then it runs the load balance algorithm to assign a server and returns the server name as a string. If the backend is not set, the function returns an empty string, and then FortiADC will set the backend only if there is only one backend available. If there is no server available in the corresponding pool or all the servers are down in the pool, an empty string will also be returned.

Syntax

LB:method_assign_server();

Arguments

N/A

Example
when HTTP_REQUEST {
    s=LB:method_assign_server()
    if (s == nil or s == '') then
    s = "No Server returned."
    end
   debug("assign server: '%s'\n", s)
}

Note:

The result may be overwritten by functions in PERSISTENCE events, which happen after HTTP_REQUEST. For example, this function returns server01. But the PERSISTENCE event specifies to use server02. The result from the PERSISTENCE event (server02) will always supercede results from non-PERSISTENCE events (server01).

FortiADC version: V7.2

Used in events: HTTP_REQUEST / HTTP_DATA_REQUEST / AUTH_RESULT