MINOR: proxy/checks: Register a keyword to parse external-check rules
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.
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index ddc7ba2..d5d52ae 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -1150,45 +1150,6 @@
/* 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",
diff --git a/src/checks.c b/src/checks.c
index cfe10f8..b9af770 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -5265,6 +5265,51 @@
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 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 },
}};