From: Christopher Faulet Date: Mon, 1 Feb 2021 12:11:50 +0000 (+0100) Subject: MINOR: checks: Add function to get the result code corresponding to a status X-Git-Tag: v2.4-dev7~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7aa327143968ff248792dbc2ceba18101fd7ab4a;p=thirdparty%2Fhaproxy.git MINOR: checks: Add function to get the result code corresponding to a status The function get_check_status_result() can now be used to get the result code (CHK_RES_*) corresponding to a check status (HCHK_STATUS_*). It will be used by the Prometheus exporter when reporting the check status of a server. --- diff --git a/include/haproxy/check.h b/include/haproxy/check.h index 2e697ee782..8d70040a3e 100644 --- a/include/haproxy/check.h +++ b/include/haproxy/check.h @@ -29,6 +29,7 @@ extern struct data_cb check_conn_cb; extern struct proxy checks_fe; +short get_check_status_result(short check_status); const char *get_check_status_description(short check_status); const char *get_check_status_info(short check_status); int httpchk_build_status_header(struct server *s, struct buffer *buf); diff --git a/src/check.c b/src/check.c index 0528372d28..879fe84ce2 100644 --- a/src/check.c +++ b/src/check.c @@ -152,6 +152,15 @@ static inline int unclean_errno(int err) return err; } +/* Converts check_status code to result code */ +short get_check_status_result(short check_status) +{ + if (check_status < HCHK_STATUS_SIZE) + return check_statuses[check_status].result; + else + return check_statuses[HCHK_STATUS_UNKNOWN].result; +} + /* Converts check_status code to description */ const char *get_check_status_description(short check_status) {