Use global variable in condition

Hi,

I’m trying to set up this type of a check:

global
...
    set-var proc.max_conn_cur int(300)

frontend lb-useast
...
  tcp-request connection track-sc0 src
  stick-table type ip size 500k expire 30s store conn_cur,conn_rate(10s),http_req_rate(10s),http_err_rate(10s)

  http-request add-header X-Haproxy-ACL %[req.fhdr(X-Haproxy-ACL,-1)]over-%[var(proc.max_conn_cur,300)]-active-connections, if { sc0_conn_cur gt var(proc.max_conn_cur) }

and this does not work, the error comes up:

error detected while parsing an 'http-request add-header' condition : 'var(proc.max_conn_cur)' is neither a number nor a supported operator.

Is it ever possible to make such a comparison?

It appears that if statements don’t like comparing two different fetches. I found this to work:

http-response add-header value %[var(proc.max_conn_cur)] if { sc0_conn_cur,sub(proc.max_conn_cur) ge 0 }

Replace the first part with your own stuff of course. Basically it just says if sc0_conn_cur - (sub/subtract) proc.max_conn_cur is greater than or equal to 0 then true. So for this as long as sc0_conn_cur is less than 300 this remains true and should be same logic as what you had.

1 Like

Works like a charm, thank you so much!