diff --git a/doc/configuration.txt b/doc/configuration.txt index 36a904e25..208c11e51 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -5255,12 +5255,14 @@ monitor-uri version and all headers are ignored, but the request must at least be valid at the HTTP level. This keyword may only be used with an HTTP-mode frontend. - Monitor requests are processed very early. It is not possible to block nor - divert them using ACLs. They cannot be logged either, and it is the intended - purpose. They are only used to report HAProxy's health to an upper component, - nothing more. However, it is possible to add any number of conditions using - "monitor fail" and ACLs so that the result can be adjusted to whatever check - can be imagined (most often the number of available servers in a backend). + Monitor requests are processed very early, just after the request is parsed + and even before any "http-request" or "block" rulesets. The only rulesets + applied before are the tcp-request ones. They cannot be logged either, and it + is the intended purpose. They are only used to report HAProxy's health to an + upper component, nothing more. However, it is possible to add any number of + conditions using "monitor fail" and ACLs so that the result can be adjusted + to whatever check can be imagined (most often the number of available servers + in a backend). Example : # Use /haproxy_test to report haproxy's status diff --git a/src/cfgparse.c b/src/cfgparse.c index b3202a68c..8486f0faa 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -406,6 +406,19 @@ int warnif_rule_after_tcp_cont(struct proxy *proxy, const char *file, int line, return 0; } +/* Report a warning if a rule is placed after a 'monitor fail' rule. + * Return 1 if the warning has been emitted, otherwise 0. + */ +int warnif_rule_after_monitor(struct proxy *proxy, const char *file, int line, const char *arg) +{ + if (!LIST_ISEMPTY(&proxy->mon_fail_cond)) { + ha_warning("parsing [%s:%d] : a '%s' rule placed after a 'monitor fail' rule will still be processed before.\n", + file, line, arg); + return 1; + } + return 0; +} + /* Report a warning if a rule is placed after a 'block' rule. * Return 1 if the warning has been emitted, otherwise 0. */ @@ -532,13 +545,20 @@ int warnif_misplaced_block(struct proxy *proxy, const char *file, int line, cons warnif_misplaced_http_req(proxy, file, line, arg); } -/* report a warning if a "tcp request content" rule is dangerously placed */ -int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) +/* report a warning if a block rule is dangerously placed */ +int warnif_misplaced_monitor(struct proxy *proxy, const char *file, int line, const char *arg) { return warnif_rule_after_block(proxy, file, line, arg) || warnif_misplaced_block(proxy, file, line, arg); } +/* report a warning if a "tcp request content" rule is dangerously placed */ +int warnif_misplaced_tcp_cont(struct proxy *proxy, const char *file, int line, const char *arg) +{ + return warnif_rule_after_monitor(proxy, file, line, arg) || + warnif_misplaced_monitor(proxy, file, line, arg); +} + /* report a warning if a "tcp request session" rule is dangerously placed */ int warnif_misplaced_tcp_sess(struct proxy *proxy, const char *file, int line, const char *arg) { @@ -5807,6 +5827,7 @@ stats_error_parsing: goto out; } + err_code |= warnif_misplaced_monitor(curproxy, file, linenum, "monitor fail"); if ((cond = build_acl_cond(file, linenum, &curproxy->acl, curproxy, (const char **)args + 2, &errmsg)) == NULL) { ha_alert("parsing [%s:%d] : error detected while parsing a '%s %s' condition : %s.\n", file, linenum, args[0], args[1], errmsg);