MINOR: ext-check: indicate the transport and protocol of a server

Valerio Pachera explained [1] that external checks would benefit from
having a variable indicating if SSL is being used or not on the server
being checked, and the discussion derived to also indicating the protocol
in use.

This patch adds two environment variables for external checks:
  - HAPROXY_SERVER_SSL: equals "0" when SSL is not used, "1" when it is
  - HAPROXY_SERVER_PROTO: contains one of the following words to describe
    the protocol used with this server:
      - "cli": the haproxy CLI. Normally not seen
      - "syslog": this is a syslog TCP server
      - "peers": this is a peers TCP server
      - "h1": this is an HTTP/1.x server
      - "h2": this is an HTTP/2 server
      - "tcp": this is any other TCP server

The patch is very simple, and may be backported to recent versions if
needed. This closes github issue #1692.

[1] https://www.mail-archive.com/haproxy@formilux.org/msg42233.html
This commit is contained in:
Willy Tarreau 2022-05-13 15:58:35 +02:00
parent 6796a06278
commit 973cf90714
2 changed files with 25 additions and 0 deletions

View File

@ -10085,6 +10085,14 @@ external-check command <command>
HAPROXY_SERVER_PORT The server port if available (or empty for a UNIX
socket).
HAPROXY_SERVER_SSL "0" when SSL is not used, "1" when it is used
HAPROXY_SERVER_PROTO The protocol used by this server, which can be one
of "cli" (the haproxy CLI), "syslog" (syslog TCP
server), "peers" (peers TCP server), "h1" (HTTP/1.x
server), "h2" (HTTP/2 server), or "tcp" (any other
TCP server).
PATH The PATH environment variable used when executing
the command may be set using "external-check path".

View File

@ -74,6 +74,8 @@ enum {
EXTCHK_HAPROXY_SERVER_PORT, /* the server port if available (or empty) */
EXTCHK_HAPROXY_SERVER_MAXCONN, /* the server max connections */
EXTCHK_HAPROXY_SERVER_CURCONN, /* the current number of connections on the server */
EXTCHK_HAPROXY_SERVER_SSL, /* "1" if the server supports SSL, otherwise zero */
EXTCHK_HAPROXY_SERVER_PROTO, /* the server's configured proto, if any */
EXTCHK_SIZE
};
@ -90,6 +92,8 @@ const struct extcheck_env extcheck_envs[EXTCHK_SIZE] = {
[EXTCHK_HAPROXY_SERVER_PORT] = { "HAPROXY_SERVER_PORT", EXTCHK_SIZE_UINT },
[EXTCHK_HAPROXY_SERVER_MAXCONN] = { "HAPROXY_SERVER_MAXCONN", EXTCHK_SIZE_EVAL_INIT },
[EXTCHK_HAPROXY_SERVER_CURCONN] = { "HAPROXY_SERVER_CURCONN", EXTCHK_SIZE_ULONG },
[EXTCHK_HAPROXY_SERVER_SSL] = { "HAPROXY_SERVER_SSL", EXTCHK_SIZE_UINT },
[EXTCHK_HAPROXY_SERVER_PROTO] = { "HAPROXY_SERVER_PROTO", EXTCHK_SIZE_EVAL_INIT },
};
void block_sigchld(void)
@ -262,6 +266,7 @@ int prepare_external_check(struct check *check)
int i;
const char *path = px->check_path ? px->check_path : DEF_CHECK_PATH;
char buf[256];
const char *svmode = NULL;
list_for_each_entry(l, &px->conf.listeners, by_fe)
/* Use the first INET, INET6 or UNIX listener */
@ -334,6 +339,18 @@ int prepare_external_check(struct check *check)
EXTCHK_SETENV(check, EXTCHK_HAPROXY_SERVER_PORT, check->argv[4], err);
EXTCHK_SETENV(check, EXTCHK_HAPROXY_SERVER_MAXCONN, ultoa_r(s->maxconn, buf, sizeof(buf)), err);
EXTCHK_SETENV(check, EXTCHK_HAPROXY_SERVER_CURCONN, ultoa_r(s->cur_sess, buf, sizeof(buf)), err);
EXTCHK_SETENV(check, EXTCHK_HAPROXY_SERVER_SSL, s->use_ssl ? "1" : "0", err);
switch (px->mode) {
case PR_MODE_CLI: svmode = "cli"; break;
case PR_MODE_SYSLOG: svmode = "syslog"; break;
case PR_MODE_PEERS: svmode = "peers"; break;
case PR_MODE_HTTP: svmode = (s->mux_proto) ? s->mux_proto->token.ptr : "h1"; break;
case PR_MODE_TCP: svmode = "tcp"; break;
/* all valid cases must be enumerated above, below is to avoid a warning */
case PR_MODES: svmode = "?"; break;
}
EXTCHK_SETENV(check, EXTCHK_HAPROXY_SERVER_PROTO, svmode, err);
/* Ensure that we don't leave any hole in check->envp */
for (i = 0; i < EXTCHK_SIZE; i++)