MINOR: contrib/prometheus-exporter: Report DRAIN/MAINT/NOLB status for servers

Now, following status are reported for servers:0=DOWN, 1=UP, 2=MAINT, 3=DRAIN,
4=NOLB.

It is linked to the github issue #255. Thanks to Mickaƫl Martin. If needed, this
patch may be backported to 2.0.

(cherry picked from commit d45d10542875e3271e6eebe941a86021af43c0c9)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c
index 0c640c4..1453836 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -659,7 +659,7 @@
 	[ST_F_ERESP]          = IST("Total number of response errors."),
 	[ST_F_WRETR]          = IST("Total number of retry warnings."),
 	[ST_F_WREDIS]         = IST("Total number of redispatch warnings."),
-	[ST_F_STATUS]         = IST("Current status of the service (frontend: 0=STOP, 1=UP, 2=FULL - backend/server: 0=DOWN, 1=UP)."),
+	[ST_F_STATUS]         = IST("Current status of the service (frontend: 0=STOP, 1=UP, 2=FULL - backend: 0=DOWN, 1=UP - server: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB)."),
 	[ST_F_WEIGHT]         = IST("Service weight."),
 	[ST_F_ACT]            = IST("Current number of active servers."),
 	[ST_F_BCK]            = IST("Current number of backup servers."),
@@ -1044,25 +1044,21 @@
 	[ST_F_CACHE_HITS]     = IST("counter"),
 };
 
-/* Return the server status: 1=UP and 0=DOWN. */
+/* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
 static int promex_srv_status(struct server *sv)
 {
-	struct server *via, *ref;
 	int state = 0;
 
-	/* we have "via" which is the tracked server as described in the configuration,
-	 * and "ref" which is the checked server and the end of the chain.
-	 */
-	via = sv->track ? sv->track : sv;
-	ref = via;
-	while (ref->track)
-		ref = ref->track;
-
 	if (sv->cur_state == SRV_ST_RUNNING || sv->cur_state == SRV_ST_STARTING) {
 		state = 1;
 		if (sv->cur_admin & SRV_ADMF_DRAIN)
-			state = 0;
+			state = 3;
 	}
+	else if (sv->cur_state == SRV_ST_STOPPING)
+		state = 4;
+
+	if (sv->cur_admin & SRV_ADMF_MAINT)
+		state = 2;
 
 	return state;
 }