]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy/checks: Register a keyword to parse external-check rules
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 9 Apr 2020 16:12:08 +0000 (18:12 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Apr 2020 07:39:38 +0000 (09:39 +0200)
The keyword 'external-check' is now parsed in a dedicated callback
function. Thus the code to parse these rules is now located in checks.c.

src/cfgparse-listen.c
src/checks.c

index ddc7ba2d356c3ddef1b64e62a531ca82202705fa..d5d52ae6f5ff390fc94810c753318a753d70a104 100644 (file)
@@ -1150,45 +1150,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                /* Indicate that the email_alert is at least partially configured */
                curproxy->email_alert.set = 1;
        }/* end else if (!strcmp(args[0], "email-alert"))  */
-       else if (!strcmp(args[0], "external-check")) {
-               if (*(args[1]) == 0) {
-                       ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
-                                file, linenum, args[0]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-                }
-
-               if (!strcmp(args[1], "command")) {
-                       if (alertif_too_many_args(2, file, linenum, args, &err_code))
-                               goto out;
-                       if (*(args[2]) == 0) {
-                               ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
-                                        file, linenum, args[1]);
-                               err_code |= ERR_ALERT | ERR_FATAL;
-                               goto out;
-                       }
-                       free(curproxy->check_command);
-                       curproxy->check_command = strdup(args[2]);
-               }
-               else if (!strcmp(args[1], "path")) {
-                       if (alertif_too_many_args(2, file, linenum, args, &err_code))
-                               goto out;
-                       if (*(args[2]) == 0) {
-                               ha_alert("parsing [%s:%d] : missing argument after '%s'.\n",
-                                        file, linenum, args[1]);
-                               err_code |= ERR_ALERT | ERR_FATAL;
-                               goto out;
-                       }
-                       free(curproxy->check_path);
-                       curproxy->check_path = strdup(args[2]);
-               }
-               else {
-                       ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n",
-                                file, linenum, args[1]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-       }/* end else if (!strcmp(args[0], "external-check"))  */
        else if (!strcmp(args[0], "persist")) {  /* persist */
                if (*(args[1]) == 0) {
                        ha_alert("parsing [%s:%d] : missing persist method.\n",
index cfe10f8fa846ddc6ad10e372e1438124e3d1123d..b9af7706ec697229549df7cc8d28befc7668884b 100644 (file)
@@ -5265,6 +5265,51 @@ static int proxy_parse_httpcheck(char **args, int section, struct proxy *curpx,
        return -1;
 }
 
+/* Parses the "external-check" proxy keyword */
+static int proxy_parse_extcheck(char **args, int section, struct proxy *curpx,
+                               struct proxy *defpx, const char *file, int line,
+                               char **errmsg)
+{
+       int cur_arg, ret = 0;
+
+       cur_arg = 1;
+       if (!*(args[cur_arg])) {
+               memprintf(errmsg, "missing argument after '%s'.\n", args[0]);
+               goto error;
+       }
+
+       if (strcmp(args[cur_arg], "command") == 0) {
+               if (too_many_args(2, args, errmsg, NULL))
+                       goto error;
+               if (!*(args[cur_arg+1])) {
+                       memprintf(errmsg, "missing argument after '%s'.", args[cur_arg]);
+                       goto error;
+               }
+               free(curpx->check_command);
+               curpx->check_command = strdup(args[cur_arg+1]);
+       }
+       else if (strcmp(args[cur_arg], "path") == 0) {
+               if (too_many_args(2, args, errmsg, NULL))
+                       goto error;
+               if (!*(args[cur_arg+1])) {
+                       memprintf(errmsg, "missing argument after '%s'.", args[cur_arg]);
+                       goto error;
+               }
+               free(curpx->check_path);
+               curpx->check_path = strdup(args[cur_arg+1]);
+       }
+       else {
+               memprintf(errmsg, "'%s' only supports 'command' and 'path'. but got '%s'.",
+                         args[0], args[1]);
+               goto error;
+       }
+
+       ret = (*errmsg != NULL); /* Handle warning */
+       return ret;
+
+error:
+       return -1;
+}
 
 static struct tcpcheck_ruleset *tcpcheck_ruleset_lookup(const char *name)
 {
@@ -6886,8 +6931,9 @@ static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx,
 }
 
 static struct cfg_kw_list cfg_kws = {ILH, {
-        { CFG_LISTEN, "tcp-check",   proxy_parse_tcpcheck },
-        { CFG_LISTEN, "http-check",  proxy_parse_httpcheck },
+        { CFG_LISTEN, "tcp-check",      proxy_parse_tcpcheck },
+        { CFG_LISTEN, "http-check",     proxy_parse_httpcheck },
+        { CFG_LISTEN, "external-check", proxy_parse_extcheck },
         { 0, NULL, NULL },
 }};