BUG/MINOR: checks: Properly handle email alerts in trace messages

There is no server for email alerts. So the trace messages must be adapted
to handle this case. Information related to the server are now skipped for
email alerts and "[EMAIL]" prefix is used.

This patch must be backported as far as 2.4.

(cherry picked from commit 4f1825c5dba44f1c0df5aa22dd96b937a70b4d29)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit dae99f7c8f392647c744b3fa93217c8fa3d29e27)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 84d8f70d344b968d2fdabfb9b2de2df0fefcfde2)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/src/check.c b/src/check.c
index a6f3bbe..1a40b6f 100644
--- a/src/check.c
+++ b/src/check.c
@@ -198,14 +198,18 @@
 	if (!check || src->verbosity < CHK_VERB_CLEAN)
 		return;
 
-	chunk_appendf(&trace_buf, " : [%c] SRV=%s",
-		      ((check->type == PR_O2_EXT_CHK) ? 'E' : (check->state & CHK_ST_AGENT ? 'A' : 'H')),
-		      srv->id);
+	if (srv) {
+		chunk_appendf(&trace_buf, " : [%c] SRV=%s",
+			      ((check->type == PR_O2_EXT_CHK) ? 'E' : (check->state & CHK_ST_AGENT ? 'A' : 'H')),
+			      srv->id);
 
-	chunk_appendf(&trace_buf, " status=%d/%d %s",
-		      (check->health >= check->rise) ? check->health - check->rise + 1 : check->health,
-		      (check->health >= check->rise) ? check->fall : check->rise,
-		      (check->health >= check->rise) ? (srv->uweight ? "UP" : "DRAIN") : "DOWN");
+		chunk_appendf(&trace_buf, " status=%d/%d %s",
+			      (check->health >= check->rise) ? check->health - check->rise + 1 : check->health,
+			      (check->health >= check->rise) ? check->fall : check->rise,
+			      (check->health >= check->rise) ? (srv->uweight ? "UP" : "DRAIN") : "DOWN");
+	}
+	else
+		chunk_appendf(&trace_buf, " : [EMAIL]");
 
 	switch (check->result) {
 	case CHK_RES_NEUTRAL: res = "-";     break;