[hobbit] Problem with TIME in hobbit-alerts.cfg

Henrik Stoerner henrik at hswn.dk
Sun Mar 27 09:14:32 CEST 2005


On Sat, Mar 26, 2005 at 06:23:07PM -0500, Terry Barnes wrote:
> I have the following entry in hobbit-alerts.cfg:
> 
> HOST=myhost SERVICE=myservice TIME=W:0000:2359,6:0000:2130,0:0500:2359
> 
> The bb-display.log shows:
> 
> Bad timespec (missing colon or wrong weekdays): W:0000:2359

It's a bug. Fortunately it's one that has already been fixed, because
I decided the time-handling code was pretty ugly so I rewrote some of
it.

Attached is a patch - goes on top of the "post-rc6" patch that I can
see you have applied.

(It's annoying that this particular piece of code has been so
problematic. It was originally written as a small stand-alone tool for
a BB extension script, then modified to be part of the bbgen
"features" patch, then transplanted into Hobbit. So I guess it was due
for a major overhaul).


Regards,
Henrik
-------------- next part --------------
--- hobbit-4.0-RC6plus/lib/timefunc.c	2005-03-25 09:33:28.000000000 +0100
+++ lib/timefunc.c	2005-03-27 08:56:58.724376339 +0200
@@ -11,7 +11,7 @@
 /*                                                                            */
 /*----------------------------------------------------------------------------*/
 
-static char rcsid[] = "$Id: timefunc.c,v 1.17 2005/03/25 08:33:05 henrik Exp $";
+static char rcsid[] = "$Id: timefunc.c,v 1.18 2005/03/27 06:56:44 henrik Exp $";
 
 #include <time.h>
 #include <sys/time.h>
@@ -140,24 +140,38 @@
 	onesla = timespec;
 	while (!found && onesla) {
 
-		int wdaymatch = 0;
+		char *wday;
+		int validday, wdaymatch = 0;
 		char *endsla, *starttimep, *endtimep;
 		int starttime, endtime;
 
 		endsla = strchr(onesla, ','); if (endsla) *endsla = '\0';
 
-		if (*onesla == '*') {
-			wdaymatch = 1;
-		}
-		else if ((toupper((int)*onesla) == 'W') && (now->tm_wday >= 1) && (now->tm_wday <=5)) {
-			wdaymatch = 1;
-		}
-		else {
-			char *wday;
-			for (wday = onesla; ((*wday >= '0') && (*wday <= '6')); wday++) {
+		for (wday = onesla, validday=1; (validday && !wdaymatch); wday++) {
+			switch (*wday) {
+			  case '*':
+				wdaymatch = 1;
+				break;
+
+			  case 'W':
+			  case 'w':
+				if ((now->tm_wday >= 1) && (now->tm_wday <=5)) wdaymatch = 1;
+				break;
+
+			  case '0': case '1': case '2': case '3': case '4': case '5': case '6':
 				if (*wday == (now->tm_wday+'0')) wdaymatch = 1;
+				break;
+
+			  case ':':
+				/* End of weekday spec. is OK */
+				validday = 0;
+				break;
+
+			  default:
+				errprintf("Bad timespec (missing colon or wrong weekdays): %s\n", onesla);
+				validday = 0;
+				break;
 			}
-			if (*wday != ':') errprintf("Bad timespec (missing colon or wrong weekdays): %s\n", onesla);
 		}
 
 		if (wdaymatch) {


More information about the Xymon mailing list