From 7aa327143968ff248792dbc2ceba18101fd7ab4a Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 1 Feb 2021 13:11:50 +0100 Subject: [PATCH] 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. --- include/haproxy/check.h | 1 + src/check.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/include/haproxy/check.h b/include/haproxy/check.h index 2e697ee78..8d70040a3 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 0528372d2..879fe84ce 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) {