]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: check: add agent-send server parameter
authorJames Brown <jbrown@easypost.com>
Thu, 22 Oct 2015 01:19:05 +0000 (18:19 -0700)
committerWilly Tarreau <w@1wt.eu>
Wed, 4 Nov 2015 06:26:51 +0000 (07:26 +0100)
Causes HAProxy to emit a static string to the agent on every check,
so that you can independently control multiple services running
behind a single agent port.

doc/configuration.txt
include/types/checks.h
src/checks.c
src/haproxy.c
src/server.c

index 7dea0f6c4a06a4a65d15ffcbc452191a29ff33f7..c3966d709bb6fe67b35a7ea12cc4dee9dc4c708e 100644 (file)
@@ -10058,6 +10058,13 @@ agent-check
 
   Supported in default-server: No
 
+agent-send <string>
+  If this option is specified, haproxy will send the given string (verbatim)
+  to the agent server upon connection. You could, for example, encode
+  the backend name into this string, which would enable your agent to send
+  different responses based on the backend. Make sure to include a '\n' if
+  you want to terminate your request with a newline.
+
 agent-inter <delay>
   The "agent-inter" parameter sets the interval between two agent checks
   to <delay> milliseconds. If left unspecified, the delay defaults to 2000 ms.
index 02fc743751b7a14b3f0becb842320233452c3a49..dd2018400a178bd4d6a89d93eebe2552acd0691d 100644 (file)
@@ -176,6 +176,8 @@ struct check {
                                                 * rise to rise+fall-1 = good */
        int rise, fall;                         /* time in iterations */
        int type;                               /* Check type, one of PR_O2_*_CHK */
+       char *send_string;                      /* optionally send a string when connecting to the agent */
+       int send_string_len;                    /* length of agent command string */
        struct server *server;                  /* back-pointer to server */
        char **argv;                            /* the arguments to use if running a process-based check */
        char **envp;                            /* the environment to use if running a process-based check */
index 997cf81202840cdc51401de548f319400f5329e7..e77926ac3df7104b4649d0ce54c3711720b3b64f 100644 (file)
@@ -1459,6 +1459,10 @@ static int connect_conn_chk(struct task *t)
                }
        }
 
+       if ((check->type & PR_O2_LB_AGENT_CHK) && check->send_string_len) {
+               bo_putblk(check->bo, check->send_string, check->send_string_len);
+       }
+
        /* prepare a new connection */
        conn_init(conn);
 
index 93423a9b0971f37c34eb7b0023cd1c3f78db235f..973af29182265b1ccfafe57d1a5a616185770e31 100644 (file)
@@ -1412,6 +1412,7 @@ void deinit(void)
                        free(s->check.bo);
                        free(s->agent.bi);
                        free(s->agent.bo);
+                       free(s->agent.send_string);
                        free((char*)s->conf.file);
 #ifdef USE_OPENSSL
                        if (s->use_ssl || s->check.use_ssl)
index c92623d481e9c4d59ef66af12bcc75c5a5acc195..224d536f1973e704c301e2184616792ddf1fc296 100644 (file)
@@ -984,6 +984,9 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                        newsrv->check.downinter = curproxy->defsrv.check.downinter;
                        newsrv->agent.use_ssl   = curproxy->defsrv.agent.use_ssl;
                        newsrv->agent.port      = curproxy->defsrv.agent.port;
+                       if (curproxy->defsrv.agent.send_string != NULL)
+                               newsrv->agent.send_string = strdup(curproxy->defsrv.agent.send_string);
+                       newsrv->agent.send_string_len = curproxy->defsrv.agent.send_string_len;
                        newsrv->agent.inter     = curproxy->defsrv.agent.inter;
                        newsrv->agent.fastinter = curproxy->defsrv.agent.fastinter;
                        newsrv->agent.downinter = curproxy->defsrv.agent.downinter;
@@ -1052,6 +1055,14 @@ int parse_server(const char *file, int linenum, char **args, struct proxy *curpr
                                newsrv->agent.port = atol(args[cur_arg + 1]);
                                cur_arg += 2;
                        }
+                       else if (!strcmp(args[cur_arg], "agent-send")) {
+                               global.maxsock++;
+                               free(newsrv->agent.send_string);
+                               newsrv->agent.send_string_len = strlen(args[cur_arg + 1]);
+                               newsrv->agent.send_string = calloc(1, newsrv->agent.send_string_len + 1);
+                               memcpy(newsrv->agent.send_string, args[cur_arg + 1], newsrv->agent.send_string_len);
+                               cur_arg += 2;
+                       }
                        else if (!defsrv && !strcmp(args[cur_arg], "cookie")) {
                                newsrv->cookie = strdup(args[cur_arg + 1]);
                                newsrv->cklen = strlen(args[cur_arg + 1]);