Fortinet black logo

Persistence commands

Persistence commands

HTTP:persist(save_tbl) — Saves the entry to the stick table.

HTTP:persist(read_tbl) — Reads the stick table content according to the hash_value.

HTTP:persist(dump_tbl) — Dumps the stick table content.

HTTP:persist(get_valid_server) — Gets the list of usable real servers and statuses.

HTTP:persist(cal_server_from_hash) — Calculates the real server from the hash.

HTTP:lookup_tbl(t) — Use this hash value to lookup the stick table, and then persist the session.

HTTP:persist(get_current_assigned_server) — Gets the real server currently assigned to this session.

PROXY:init_stick_tbl_timeout(int) — Sets the timeout of the stick table.

HTTP:persist(save_tbl)

Saves the entry to the stick table.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation, hash value, and server_name.

Example
when PERSISTENCE{
    cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)

    debug("-----save_tbl-----\n")
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-2"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end

	t={};
	t["operation"] = "save_tbl";
	t["hash_value"] = "246810";
	t["srv_name"] = "pool1-3";
	ret = HTTP: persist(t);
	if ret then
	    debug("===server add success\n");
    else
        debug("===server add fail\n");
    end
}
Output:
true: success, false: failed

Note:

Due to limitations in the stick table, it only supports 16 characters in the hash value. Otherwise, we will hash it to obtain 16 bytes as index.

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / POST_PERSIST / HTTP_REQUEST

HTTP:persist(read_tbl)

Reads the stick table content according to the hash_value.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation and hash value.

Example
when PERSISTENCE{
  	t={};
	t["operation"] = "save_tbl";
	t["hash_value"] = "246810";
	t["srv_name"] = "pool1-3";
	ret = HTTP: persist(t);
	if ret then
	    debug("===server add success\n");
    else
        debug("===server add fail\n");
    end

    t={}
    t["operation"] = "read_tbl"
    t["hash_value"] = "246810"
    ret_tbl = HTTP:persist(t)
    if ret_tbl then
        debug("246810-server: %s\n",ret_tbl)
    else
        debug("246810-server read fail\n")
end 
}
Output:
	Return server name of the entry, or false if no entry found

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:persist(dump_tbl)

Dumps the stick table content.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation.

Example
when PERSISTENCE{
	t={};
	t["operation"] = "save_tbl";
	t["hash_value"] = "246810";
	t["srv_name"] = "pool1-3";
	ret = HTTP: persist(t);
	if ret then
	    debug("===server add success\n");
    else
        debug("===server add fail\n");
    end

    t={}
    t["operation"] = "dump_tbl"
    t[“index”] = 1
    t[“count”] = 15
    ret_tbl = HTTP:persist(t)
    if ret_tbl then
        for hash, srv in pairs(ret_tbl) do
            debug("tbl hash %s srv %s\n",hash,srv)
        end
    end
}
       “index”: 
      “count”: 
Output:
	Return A table include hash and server name

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:persist(get_valid_server)

Gets the list of usable real servers and statuses.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation.

Example
when PERSISTENCE{
    debug("-----get valid server-----\n")
    t={}
    t["operation"] = "get_valid_server"
    ret = HTTP:persist(t)
    if ret then
        for srv,stat in pairs(ret) do
            debug("server %s, status %s\n",srv,stat)
        end
    end
}
Output:
	Return the table of usable real server and server state(enable, backup)

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:persist(cal_server_from_hash)

Calculates the real server from the hash.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation and hash value.

Example
when PERSISTENCE{
    debug("-----cal_server_from_hash-----\n")
    t={}
    t["operation"] = "cal_server_from_hash"
    t["hash_value"] = "246810"
    ret = HTTP:persist(t)
    if ret then
        debug("hash 246810, server %s\n",ret)
    end 
}
Output:
	Return the real server name according to the hash value using our algorithm or False if failed 

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:lookup_tbl(t)

Use this hash value to lookup the stick table, and then persist the session.

Syntax

HTTP:lookup_tbl(t);

Arguments
Name Description

t

A table specifies the operation and hash value.

Example
when PERSISTENCE{
        cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)
   
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-3"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end
 
    t={}
    t["hash_value"]=hash_str_cip
    ret = HTTP:lookup_tbl(t)
    if ret then 
        debug("hash LOOKUP success\n")
    else
        debug("hash lookup failed\n")
    end
} 
Output:
	Return True: lookup success, False, lookup failed and use the org. LB method 

FortiADC version: V5.4

Used in events: PERSISTENCE

HTTP:persist(get_current_assigned_server)

Gets the real server currently assigned to this session.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation.

Example
when PERSISTENCE{
        cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)
   
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-3"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end
 
    t={}
    t["hash_value"]=hash_str_cip
    ret = HTTP:lookup_tbl(t)
    if ret then 
        debug("hash LOOKUP success\n")
    else
        debug("hash lookup failed\n")
    end
}
when POST_PERSIST{
debug("-----event POST_PERSIST-----\n")

    debug("-----get current assigned server-----\n")
    t={}
    t["operation"]="get_current_assigned_server"
    ret=HTTP:persist(t)
    debug("current assigned server: %s\n",ret)
}
Output:
	Return the real server name which is assigned to current session or False if no server is assigned right now 

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: POST_PERSIST / HTTP_REQUEST

PROXY:init_stick_tbl_timeout(int)

Sets the timeout of the stick table.

Syntax

PROXY:init_stick_tbl_timeout(init);

Arguments
Name Description

int

A positive integer that specifies the timeout.

Example
when RULE_INIT{
    env={}
    PROXY:init_stick_tbl_timeout(500)
}
when PERSISTENCE{
    cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)
    
  debug("-----save_tbl-----\n")
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-3"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end
}
Output:
	Return True: success, False: failed

FortiADC version: V5.4

Used in events: RULE_INIT

Persistence commands

HTTP:persist(save_tbl) — Saves the entry to the stick table.

HTTP:persist(read_tbl) — Reads the stick table content according to the hash_value.

HTTP:persist(dump_tbl) — Dumps the stick table content.

HTTP:persist(get_valid_server) — Gets the list of usable real servers and statuses.

HTTP:persist(cal_server_from_hash) — Calculates the real server from the hash.

HTTP:lookup_tbl(t) — Use this hash value to lookup the stick table, and then persist the session.

HTTP:persist(get_current_assigned_server) — Gets the real server currently assigned to this session.

PROXY:init_stick_tbl_timeout(int) — Sets the timeout of the stick table.

HTTP:persist(save_tbl)

Saves the entry to the stick table.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation, hash value, and server_name.

Example
when PERSISTENCE{
    cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)

    debug("-----save_tbl-----\n")
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-2"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end

	t={};
	t["operation"] = "save_tbl";
	t["hash_value"] = "246810";
	t["srv_name"] = "pool1-3";
	ret = HTTP: persist(t);
	if ret then
	    debug("===server add success\n");
    else
        debug("===server add fail\n");
    end
}
Output:
true: success, false: failed

Note:

Due to limitations in the stick table, it only supports 16 characters in the hash value. Otherwise, we will hash it to obtain 16 bytes as index.

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / POST_PERSIST / HTTP_REQUEST

HTTP:persist(read_tbl)

Reads the stick table content according to the hash_value.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation and hash value.

Example
when PERSISTENCE{
  	t={};
	t["operation"] = "save_tbl";
	t["hash_value"] = "246810";
	t["srv_name"] = "pool1-3";
	ret = HTTP: persist(t);
	if ret then
	    debug("===server add success\n");
    else
        debug("===server add fail\n");
    end

    t={}
    t["operation"] = "read_tbl"
    t["hash_value"] = "246810"
    ret_tbl = HTTP:persist(t)
    if ret_tbl then
        debug("246810-server: %s\n",ret_tbl)
    else
        debug("246810-server read fail\n")
end 
}
Output:
	Return server name of the entry, or false if no entry found

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:persist(dump_tbl)

Dumps the stick table content.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation.

Example
when PERSISTENCE{
	t={};
	t["operation"] = "save_tbl";
	t["hash_value"] = "246810";
	t["srv_name"] = "pool1-3";
	ret = HTTP: persist(t);
	if ret then
	    debug("===server add success\n");
    else
        debug("===server add fail\n");
    end

    t={}
    t["operation"] = "dump_tbl"
    t[“index”] = 1
    t[“count”] = 15
    ret_tbl = HTTP:persist(t)
    if ret_tbl then
        for hash, srv in pairs(ret_tbl) do
            debug("tbl hash %s srv %s\n",hash,srv)
        end
    end
}
       “index”: 
      “count”: 
Output:
	Return A table include hash and server name

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:persist(get_valid_server)

Gets the list of usable real servers and statuses.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation.

Example
when PERSISTENCE{
    debug("-----get valid server-----\n")
    t={}
    t["operation"] = "get_valid_server"
    ret = HTTP:persist(t)
    if ret then
        for srv,stat in pairs(ret) do
            debug("server %s, status %s\n",srv,stat)
        end
    end
}
Output:
	Return the table of usable real server and server state(enable, backup)

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:persist(cal_server_from_hash)

Calculates the real server from the hash.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation and hash value.

Example
when PERSISTENCE{
    debug("-----cal_server_from_hash-----\n")
    t={}
    t["operation"] = "cal_server_from_hash"
    t["hash_value"] = "246810"
    ret = HTTP:persist(t)
    if ret then
        debug("hash 246810, server %s\n",ret)
    end 
}
Output:
	Return the real server name according to the hash value using our algorithm or False if failed 

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: PERSISTENCE / HTTP_REQUEST

HTTP:lookup_tbl(t)

Use this hash value to lookup the stick table, and then persist the session.

Syntax

HTTP:lookup_tbl(t);

Arguments
Name Description

t

A table specifies the operation and hash value.

Example
when PERSISTENCE{
        cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)
   
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-3"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end
 
    t={}
    t["hash_value"]=hash_str_cip
    ret = HTTP:lookup_tbl(t)
    if ret then 
        debug("hash LOOKUP success\n")
    else
        debug("hash lookup failed\n")
    end
} 
Output:
	Return True: lookup success, False, lookup failed and use the org. LB method 

FortiADC version: V5.4

Used in events: PERSISTENCE

HTTP:persist(get_current_assigned_server)

Gets the real server currently assigned to this session.

Syntax

HTTP:persist(t);

Arguments
Name Description

t

A table specifies the operation.

Example
when PERSISTENCE{
        cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)
   
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-3"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end
 
    t={}
    t["hash_value"]=hash_str_cip
    ret = HTTP:lookup_tbl(t)
    if ret then 
        debug("hash LOOKUP success\n")
    else
        debug("hash lookup failed\n")
    end
}
when POST_PERSIST{
debug("-----event POST_PERSIST-----\n")

    debug("-----get current assigned server-----\n")
    t={}
    t["operation"]="get_current_assigned_server"
    ret=HTTP:persist(t)
    debug("current assigned server: %s\n",ret)
}
Output:
	Return the real server name which is assigned to current session or False if no server is assigned right now 

FortiADC version: V5.4, V7.2 (extended function to HTTP_REQUEST events)

Used in events: POST_PERSIST / HTTP_REQUEST

PROXY:init_stick_tbl_timeout(int)

Sets the timeout of the stick table.

Syntax

PROXY:init_stick_tbl_timeout(init);

Arguments
Name Description

int

A positive integer that specifies the timeout.

Example
when RULE_INIT{
    env={}
    PROXY:init_stick_tbl_timeout(500)
}
when PERSISTENCE{
    cip = HTTP:client_addr()
    hash_str_cip = sha512_hex(cip)
    
  debug("-----save_tbl-----\n")
    t={}
    t["operation"] = "save_tbl"
    t["hash_value"] = hash_str_cip
    t["srv_name"] = "pool1-3"
    ret = HTTP:persist(t)
    if ret then
	    debug("hash save table success\n");
	else
	    debug("save table failed\n");
	end
}
Output:
	Return True: success, False: failed

FortiADC version: V5.4

Used in events: RULE_INIT