[xymon] Bug in downtime display on info-page

Henrik Størner henrik at hswn.dk
Fri Oct 29 12:47:30 CEST 2010


In <B08F3F3D67451844A7A8A029FCC71E4C164233112E at WIN01.ad.deltamanagement.se> =?iso-8859-1?Q?Johan_Sj=F6berg?= <johan.sjoberg at deltamanagement.se> writes:

>This might already be fixed in 4.3, but I'll report it anyway.
>The info page in 4.2.3 shows the downtime information in the wrong order. 
>In bb-host I added "DOWNTIME=*:5:0445:0555:reboot" to schedule a downtime
>each Friday morning for a reboot of a server. I know this downtime works
>as intended, and the field order is according to the man-page.
>But on the info-page, the downtime is shown as 
>"Planned downtime:All days:5:0445:0555:reboot", so the "day" and "service" 
>fields are mixed up.

Thanks for reporting this - the routine handling the time-display had
not been updated to support the extended format. Fixed now. The patch
below can be applied to 4.2.3 also, if you want to.


Regards,
Henrik

Index: lib/timefunc.c
===================================================================
--- lib/timefunc.c	(revision 6532)
+++ lib/timefunc.c	(working copy)
@@ -97,6 +97,7 @@
 	static strbuffer_t *result = NULL;
 	char *sCopy;
 	char *sItem;
+	char *itmstbuf;
 
 	if (result == NULL) result = newstrbuffer(0);
 	clearstrbuffer(result);
@@ -120,12 +121,36 @@
 	}
 
 	sCopy = strdup(spec);
-	sItem = strtok(sCopy, ",");
+	sItem = strtok_r(sCopy, ",", &itmstbuf);
 	while (sItem) {
+		char *tok, *onebuf, *e1, *e2, *e3, *e4, *e5;
+		char *days, *starttime, *endtime, *columns, *cause;
 		char *oneday, *dtext;
-		int daysdone = 0, firstday = 1;
-		oneday = sItem;
+		int daysdone = 0, firstday = 1, ecount;
 
+		e1 = e2 = e3 = e4 = e5 = NULL; ecount = 0;
+		e1 = strtok_r(sItem, ":", &onebuf);
+		if (e1) { ecount++; e2 = strtok_r(NULL, ":", &onebuf); }
+		if (e2) { ecount++; e3 = strtok_r(NULL, ":", &onebuf); }
+		if (e3) { ecount++; e4 = strtok_r(NULL, ":", &onebuf); }
+		if (e4) { ecount++; e5 = strtok_r(NULL, ":", &onebuf); }
+ 		if (e5) { ecount++; }
+
+		if (ecount == 3) {
+			/* Old format: e1=day, e2 = starttime, e3 = endtime */
+			days = e1; starttime = e2; endtime = e3; columns = NULL; cause = NULL;
+		}
+		else if (ecount == 5) {
+			columns = e1; days = e2; starttime = e3; endtime = e4; cause = e5;
+		}
+		else {
+			addtobuffer(result, "[Malformed timespec]");
+			sItem = NULL;
+			continue;
+		}
+
+		oneday = days;
+
 		while (!daysdone) {
 			switch (*oneday) {
 			  case '*': dtext = "All days"; break;
@@ -141,12 +166,25 @@
 			}
 
 			if (!firstday) addtobuffer(result, "/");
+
 			addtobuffer(result, dtext);
 			oneday++;
 			firstday = 0;
 		}
 
-		sItem = strtok(NULL, ",");
+		addtobuffer(result, ":"); addtobuffer(result, starttime);
+		addtobuffer(result, ":"); addtobuffer(result, endtime);
+		if (columns) { 
+			addtobuffer(result, " (status:"); 
+			if (strcmp(columns, "*") == 0)
+				addtobuffer(result, "All");
+			else
+				addtobuffer(result, columns); 
+			addtobuffer(result, ")");
+		}
+		if (cause) { addtobuffer(result, " (cause:"); addtobuffer(result, cause); addtobuffer(result, ")"); }
+
+		sItem = strtok_r(NULL, ",", &itmstbuf);
 		if (sItem) addtobuffer(result, ", ");
 	}
 	xfree(sCopy);



More information about the Xymon mailing list