]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: contrib/spoa_server: Add random IP score
authorDaniel Corbett <dcorbett@haproxy.com>
Tue, 11 Jun 2019 14:04:15 +0000 (10:04 -0400)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Jun 2019 17:27:42 +0000 (19:27 +0200)
The example configuration uses sess.ip_score however this variable
is not referenced within the example scripts.  This patch adds support
for sess.ip_score to the python + lua scripts and generates a
random number between 1 and 100.

contrib/spoa_server/ps_lua.lua
contrib/spoa_server/ps_python.py

index 2662045996456033d0efab9901e967bb7c9ff1a1..4d1fc522759347b2977e9d9b983ab8b894a80904 100644 (file)
@@ -1,4 +1,5 @@
 require("print_r")
+require("math")
 
 print_r("Load lua message processors")
 
@@ -14,4 +15,5 @@ spoa.register_message("check-client-ip", function(args)
        spoa.set_var_ipv6("ipv6", spoa.scope.txn, "1::f")
        spoa.set_var_str("str", spoa.scope.txn, "1::f")
        spoa.set_var_bin("bin", spoa.scope.txn, "1::f")
+       spoa.set_var_int32("ip_score", spoa.scope.sess, math.random(100))
 end)
index 108eb48a67cded2a60bf3917d9ba52db2cfd0d3e..37bda5e3320d8aec3db56664e5edfe8abdf8d282 100644 (file)
@@ -1,6 +1,7 @@
 from pprint import pprint
 import spoa
 import ipaddress
+import random
 
 def check_client_ip(args):
        pprint(args)
@@ -14,6 +15,7 @@ def check_client_ip(args):
        spoa.set_var_ipv6("ipv6", spoa.scope_txn, ipaddress.IPv6Address(u"1::f"))
        spoa.set_var_str("str", spoa.scope_txn, "1::f")
        spoa.set_var_bin("bin", spoa.scope_txn, "1:\x01:\x02f\x00\x00")
+       spoa.set_var_int32("ip_score", spoa.scope_sess, random.randint(1,100))
        return