Hi Valerio, On Fri, May 06, 2022 at 04:25:23PM +0200, Valerio Pachera wrote: > Hi, I have several backend configuration that make use of a custom script: > > external-check command 'custom-script.sh' > > The script read uses the environment variables such as $HAPROXY_PROXY_NAME. > I would like to be able to set and environment variable in the backend > declaration, before running the external check. > This environment variable will change the behavior of custom-script.sh. > > Is it possible to declare environment variables in haproxy 1.9 or later? > > What I need is to make custom-script.sh aware if SSL is used or not. > If there's another way to achieve that, please tell me.
You can only set variables in the global section using "setenv" and "presetenv", and they are in effect at the moment they're parsed (thus they're even usable later in the config file). But there's nothing to set per-backend variables that would be used by the external-check commands. If you know that your whole haproxy process is either with or without SSL, that might still work for you. Otherwise maybe you should use two different scripts for SSL a clear servers. You could possibly also rely on the server's name and/or port as a hint to your script. With that said, I admit that it could be useful to have another variable such as HAPROXY_SERVER_SSL to indicate if SSL is being used, and possibly another one such as HAPROXY_SERVER_PROTO to indicate when a protocol is being forced (e.g. h2). If you think your only solution would be to have such variables, feel free to have a look at the code to see how to add them. That should be simple enough for a first contribution. That's something we can merge late in the cycle, and possibly even backport to 2.5. Willy