]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: checks: Add function to get the result code corresponding to a status
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 1 Feb 2021 12:11:50 +0000 (13:11 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 1 Feb 2021 14:16:33 +0000 (15:16 +0100)
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
src/check.c

index 2e697ee782a7d3ef14a5e0b94c95f4f4989104d6..8d70040a3e9b21bed4d73b8e366c304debc90a86 100644 (file)
@@ -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);
index 0528372d28cb4dc9067ad05fa75e84bd347ae592..879fe84ce2fa2d9c31442357f908929e775f8ad5 100644 (file)
@@ -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) {