Xymon Mailing List Archive search

longer ack alerts

list Henrik Størner
Fri, 29 Sep 2006 12:32:28 +0200
Message-Id: <user-96100b179b16@xymon.invalid>

On Fri, Sep 29, 2006 at 10:02:00AM +0100, Jones, Jason (Altrincham) wrote:
I know I've asked this before and I'm sorry to repeat but could someone
tell me the steps to add a hour and days input field to the ack alert
form?  (this is the first time I've altered anything on the hobbit
webpage side of things), 
It's not quite what you want, but the attached patch lets you enter the
time as "6h" (6 hours) or "2d8h" (2 days + 8 hours).

also would it be possible to not allow acks longer than 1 week?
That would need some more code in the bb-ack CGI to reject the too-long
acks. Some sort of configuration mechanism would also be needed to set
the maximum time - either globally, or per-host.


Regards,
Henrik

-------------- next part --------------
--- lib/timefunc.c	2006/07/20 16:06:41	1.31
+++ lib/timefunc.c	2006/09/29 10:21:23
@@ -245,6 +245,7 @@
 	return found;
 }
 
+#ifndef CLIENTONLY
 char *check_downtime(char *hostname, char *testname)
 {
 	namelist_t *hinfo = hostinfo(hostname);
@@ -300,6 +301,7 @@
 
 	return NULL;
 }
+#endif
 
 int periodcoversnow(char *tag)
 {
@@ -415,20 +417,30 @@
 	 */
 
 	int result = 0;
-	char *p;
-	char modifier;
+	char *startofval;
 
-	p = dur + strspn(dur, "0123456789");
-	modifier = *p;
-	*p = '\0';
-	result = atoi(dur);
-	*p = modifier;
+	startofval = dur;
• +	while (startofval && (isdigit((int)*startofval))) {
+		char *p;
+		char modifier;
+		int oneval = 0;
• +		p = startofval + strspn(startofval, "0123456789");
+		modifier = *p;
+		*p = '\0';
+		oneval = atoi(startofval);
+		*p = modifier;
• +		switch (modifier) {
+		  case 'm': break;			/* minutes */
+		  case 'h': oneval *= 60; break;	/* hours */
+		  case 'd': oneval *= 1440; break;	/* days */
+		  case 'w': oneval *= 10080; break;	/* weeks */
+		}
 
-	switch (modifier) {
-	  case 'm': break;			/* minutes */
-	  case 'h': result *= 60; break;	/* hours */
-	  case 'd': result *= 1440; break;	/* days */
-	  case 'w': result *= 10080; break;	/* weeks */
+		result += oneval;
+		if (*p) startofval = p+1;
 	}
 
 	return result;
--- web/bb-ack.c	2006/08/11 21:04:17	1.33
+++ web/bb-ack.c	2006/09/29 10:22:07
@@ -133,7 +133,7 @@
 				}
 
 				if (acknum) awalk->acknum = atoi(acknum);
-				if (validity) awalk->validity = atoi(validity);
+				if (validity) awalk->validity = durationvalue(validity);
 				if (ackmsg) awalk->ackmsg = strdup(ackmsg);
 				if (hostname) awalk->hostname = strdup(hostname);
 				if (testname) awalk->testname = strdup(testname);
@@ -161,7 +161,7 @@
 
 	fprintf(output, "    <td>%s</td>\n", (hname ? hname : "&nbsp;"));
 	fprintf(output, "    <td>%s</td>\n", (tname ? tname : "&nbsp;"));
-	fprintf(output, "    <TD><INPUT TYPE=TEXT NAME=\"DELAY_%s\" SIZE=4 MAXLENGTH=4></TD>\n", numstr);
+	fprintf(output, "    <TD><INPUT TYPE=TEXT NAME=\"DELAY_%s\" SIZE=8 MAXLENGTH=20></TD>\n", numstr);
 	fprintf(output, "    <TD><INPUT TYPE=TEXT NAME=\"MESSAGE_%s\" SIZE=60 MAXLENGTH=80></TD>\n", numstr);
 
 	fprintf(output, "    <TD>\n");
@@ -316,7 +316,7 @@
 
 			if (reqtype == ACK_MANY) {
 				if (!awalk->ackmsg) awalk->ackmsg = ackmsgall;
-				if (!awalk->validity && validityall) awalk->validity = atoi(validityall);
+				if (!awalk->validity && validityall) awalk->validity = durationvalue(validityall);
 			}
 
 			count++;