[hobbit] Help with DOWNTIME tag
Henrik Stoerner
henrik at hswn.dk
Fri Mar 25 09:36:39 CET 2005
On Thu, Mar 24, 2005 at 11:43:59PM -0500, Terry Barnes wrote:
> Just took the plunge to HOBBIT today and overall it is working very
> nice. Big Brother has been great - this is going to be a winner!
>
> Reading through the bb-hosts manpage i discovered the DOWNTIME tag.
[snip description of it not working]
I think you're right - there is a bug in how this is handled. Glad you
spotted it.
Attached is a patch for this. To apply it, save the attachment to
/tmp/postrc6-downtime.patch, and:
cd hobbit-4.0-RC6
patch -p0 </tmp/postrc6-downtime.patch
make
Stop Hobbit, su to root and run "make install", then start Hobbit
again.
Regards,
Henrik
-------------- next part --------------
--- bbdisplay/loadbbhosts.c 2005/01/20 10:45:44 1.18
+++ bbdisplay/loadbbhosts.c 2005/03/25 07:41:56
@@ -1,22 +1,16 @@
/*----------------------------------------------------------------------------*/
-/* Big Brother webpage generator tool. */
+/* Hobbit overview webpage generator tool. */
/* */
-/* This is a replacement for the "mkbb.sh" and "mkbb2.sh" scripts from the */
-/* "Big Brother" monitoring tool from BB4 Technologies. */
+/* This file contains code to load the page-structure from the bb-hosts file. */
/* */
-/* Primary reason for doing this: Shell scripts perform badly, and with a */
-/* medium-sized installation (~150 hosts) it takes several minutes to */
-/* generate the webpages. This is a problem, when the pages are used for */
-/* 24x7 monitoring of the system status. */
-/* */
-/* Copyright (C) 2002 Henrik Storner <henrik at storner.dk> */
+/* Copyright (C) 2002-2005 Henrik Storner <henrik at storner.dk> */
/* */
/* This program is released under the GNU General Public License (GPL), */
/* version 2. See the file "COPYING" for details. */
/* */
/*----------------------------------------------------------------------------*/
-static char rcsid[] = "$Id: loadbbhosts.c,v 1.18 2005/01/20 10:45:44 henrik Exp $";
+static char rcsid[] = "$Id: loadbbhosts.c,v 1.20 2005/03/25 07:40:15 henrik Exp $";
#include <limits.h>
#include <stdio.h>
@@ -616,7 +610,7 @@
dialup = (bbh_item(bbhost, BBH_FLAG_DIALUP) != NULL);
nobb2 = (bbh_item(bbhost, BBH_FLAG_NOBB2) != NULL);
alertlist = bbh_item(bbhost, BBH_NK);
- bbval = bbh_item(bbhost, BBH_NKTIME); if (bbval) nktime = within_sla(bbval, "", 0);
+ bbval = bbh_item(bbhost, BBH_NKTIME); if (bbval) nktime = within_sla(bbval, 0);
onwaplist = bbh_item(bbhost, BBH_WML);
nopropyellowlist = bbh_item(bbhost, BBH_NOPROPYELLOW);
if (nopropyellowlist == NULL) nopropyellowlist = bbh_item(bbhost, BBH_NOPROP);
--- bbnet/bbtest-net.c 2005/03/05 06:54:29 1.203
+++ bbnet/bbtest-net.c 2005/03/25 07:41:54
@@ -8,7 +8,7 @@
/* */
/*----------------------------------------------------------------------------*/
-static char rcsid[] = "$Id: bbtest-net.c,v 1.203 2005/03/05 06:54:29 henrik Exp $";
+static char rcsid[] = "$Id: bbtest-net.c,v 1.207 2005/03/25 07:40:15 henrik Exp $";
#include <limits.h>
#include <stdio.h>
@@ -459,7 +459,7 @@
p = bbh_item(hwalk, BBH_DOWNTIME);
- if (p) okexpected = (!within_sla(p, "", 0));
+ if (p) okexpected = (!within_sla(p, 0));
h = init_testedhost(hwalk->bbhostname, okexpected);
p = bbh_custom_item(hwalk, "badconn:");
--- common/bbhostgrep.c 2005/01/31 22:30:23 1.24
+++ common/bbhostgrep.c 2005/03/25 07:41:54
@@ -13,7 +13,7 @@
/* */
/*----------------------------------------------------------------------------*/
-static char rcsid[] = "$Id: bbhostgrep.c,v 1.24 2005/01/31 22:30:23 henrik Exp $";
+static char rcsid[] = "$Id: bbhostgrep.c,v 1.25 2005/03/25 07:40:15 henrik Exp $";
#include <stdio.h>
#include <string.h>
@@ -130,7 +130,7 @@
if (bbh_item(hwalk, BBH_FLAG_DIALUP)) strcat(wantedtags, " dialup");
if (bbh_item(hwalk, BBH_FLAG_TESTIP)) strcat(wantedtags, " testip");
if ((item = bbh_item(hwalk, BBH_DOWNTIME)) != NULL) {
- if (within_sla(item, "", 0))
+ if (within_sla(item, 0))
strcat(wantedtags, " OUTSIDESLA");
else
strcat(wantedtags, " INSIDESLA");
--- hobbitd/do_alert.c 2005/03/20 13:52:05 1.57
+++ hobbitd/do_alert.c 2005/03/25 07:41:53
@@ -13,7 +13,7 @@
/* */
/*----------------------------------------------------------------------------*/
-static char rcsid[] = "$Id: do_alert.c,v 1.57 2005/03/20 13:52:05 henrik Exp $";
+static char rcsid[] = "$Id: do_alert.c,v 1.58 2005/03/25 07:40:15 henrik Exp $";
/*
* The alert API defines three functions that must be implemented:
@@ -860,7 +860,7 @@
{
int result;
- result = within_sla(tspec, "", 0);
+ result = within_sla(tspec, 0);
return result;
}
--- lib/loadhosts.c 2005/01/31 11:39:16 1.24
+++ lib/loadhosts.c 2005/03/25 07:41:52
@@ -1,11 +1,11 @@
/*----------------------------------------------------------------------------*/
-/* Hobbit monitor. */
+/* Hobbit monitor library. */
/* */
/* This is a library module for Hobbit, responsible for loading the bb-hosts */
/* file and keeping track of what hosts are known, their aliases and planned */
/* downtime settings etc. */
/* */
-/* Copyright (C) 2004 Henrik Storner <henrik at hswn.dk> */
+/* Copyright (C) 2004-2005 Henrik Storner <henrik at hswn.dk> */
/* */
/* This program is released under the GNU General Public License (GPL), */
/* version 2. See the file "COPYING" for details. */
@@ -13,7 +13,7 @@
/*----------------------------------------------------------------------------*/
-static char rcsid[] = "$Id: loadhosts.c,v 1.24 2005/01/31 11:39:16 henrik Exp $";
+static char rcsid[] = "$Id: loadhosts.c,v 1.26 2005/03/25 07:40:15 henrik Exp $";
#include <stdio.h>
#include <string.h>
@@ -151,7 +151,7 @@
*/
strcpy(hostip, walk->ip);
strcpy(result, walk->bbhostname);
- if (walk->downtime) *maybedown = within_sla(walk->downtime, "DOWNTIME", 0);
+ if (walk->downtime) *maybedown = within_sla(walk->downtime, 0);
}
else {
strcpy(result, hostname);
--- lib/timefunc.c 2005/02/20 09:03:48 1.14
+++ lib/timefunc.c 2005/03/25 08:33:28
@@ -1,17 +1,17 @@
/*----------------------------------------------------------------------------*/
-/* bbgen toolkit */
+/* Hobbit monitor library. */
/* */
/* This is a library module, part of libbbgen. */
/* It contains routines for timehandling. */
/* */
-/* Copyright (C) 2002-2004 Henrik Storner <henrik at storner.dk> */
+/* Copyright (C) 2002-2005 Henrik Storner <henrik at storner.dk> */
/* */
/* This program is released under the GNU General Public License (GPL), */
/* version 2. See the file "COPYING" for details. */
/* */
/*----------------------------------------------------------------------------*/
-static char rcsid[] = "$Id: timefunc.c,v 1.14 2005/02/20 09:03:48 henrik Exp $";
+static char rcsid[] = "$Id: timefunc.c,v 1.17 2005/03/25 08:33:05 henrik Exp $";
#include <time.h>
#include <sys/time.h>
@@ -109,91 +109,90 @@
static int minutes(char *p)
{
/* Converts string HHMM to number indicating minutes since midnight (0-1440) */
- return (10*(*(p+0)-'0')+(*(p+1)-'0'))*60 + (10*(*(p+2)-'0')+(*(p+3)-'0'));
+ if (isdigit((int)*(p+0)) && isdigit((int)*(p+1)) && isdigit((int)*(p+2)) && isdigit((int)*(p+3))) {
+ return (10*(*(p+0)-'0')+(*(p+1)-'0'))*60 + (10*(*(p+2)-'0')+(*(p+3)-'0'));
+ }
+ else {
+ errprintf("Invalid timespec - expected 4 digits, got: '%s'\n", p);
+ return 0;
+ }
}
-int within_sla(char *l, char *tag, int defresult)
+int within_sla(char *timespec, int defresult)
{
/*
- * Usage: slatime hostline
- * SLASPEC is of the form SLA=W:HHMM:HHMM[,WXHHMM:HHMM]*
+ * timespec is of the form W:HHMM:HHMM[,W:HHMM:HHMM]*
* "W" = weekday : '*' = all, 'W' = Monday-Friday, '0'..'6' = Sunday ..Saturday
*/
- char *p;
- char *slaspec = NULL;
- char *endofslaspec = NULL;
- char *tagspec;
-
+ int found = 0;
time_t tnow;
struct tm *now;
+ int curtime;
+ char *onesla;
- int result = 0;
- int found = 0;
- int starttime,endtime,curtime;
+ if (!timespec) return defresult;
- if (strlen(tag)) {
- tagspec = (char *) malloc(strlen(tag)+2);
- sprintf(tagspec, "%s=", tag);
- p = strstr(l, tagspec);
- }
- else {
- tagspec = strdup("");
- p = l;
- }
+ tnow = time(NULL);
+ now = localtime(&tnow);
+ curtime = now->tm_hour*60+now->tm_min;
- if (p) {
- slaspec = p + strlen(tagspec);
- endofslaspec = slaspec + strcspn(slaspec, " \t\r\n");
- tnow = time(NULL);
- now = localtime(&tnow);
-
- /*
- * Now find the appropriate SLA definition.
- * We take advantage of the fixed (11 bytes + delimiter) length of each entry.
- */
- while ( (!found) && slaspec && (slaspec < endofslaspec) )
- {
- dprintf("Now checking slaspec='%s'\n", slaspec);
-
- if ( (*slaspec == '*') || /* Any day */
- (*slaspec == now->tm_wday+'0') || /* This day */
- ((toupper((int)*slaspec) == 'W') && (now->tm_wday >= 1) && (now->tm_wday <=5)) ) /* Monday thru Friday */
- {
- /* Weekday matches */
- starttime = minutes(slaspec+2);
- endtime = minutes(slaspec+7);
- curtime = now->tm_hour*60+now->tm_min;
- if (endtime > starttime) {
- /* *:0200:0400 */
- found = ((curtime >= starttime) && (curtime <= endtime));
- }
- else {
- /* The period crosses over midnight: *:2330:0400 */
- found = ((curtime >= starttime) || (curtime <= endtime));
- }
+ onesla = timespec;
+ while (!found && onesla) {
- dprintf("\tstart,end,current time = %d, %d, %d - found=%d\n",
- starttime,endtime,curtime,found);
- }
- else {
- dprintf("\tWeekday does not match\n");
+ int 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++) {
+ if (*wday == (now->tm_wday+'0')) wdaymatch = 1;
}
+ if (*wday != ':') errprintf("Bad timespec (missing colon or wrong weekdays): %s\n", onesla);
+ }
- if (!found) {
- slaspec = strchr(slaspec, ',');
- if (slaspec) slaspec++;
- };
+ if (wdaymatch) {
+ /* Weekday matches */
+ starttimep = strchr(onesla, ':');
+ if (starttimep) {
+ starttime = minutes(starttimep+1);
+ endtimep = strchr(starttimep+1, ':');
+ if (endtimep) {
+ endtime = minutes(endtimep+1);
+ if (endtime > starttime) {
+ /* *:0200:0400 */
+ found = ((curtime >= starttime) && (curtime <= endtime));
+ }
+ else {
+ /* The period crosses over midnight: *:2330:0400 */
+ found = ((curtime >= starttime) || (curtime <= endtime));
+ }
+ dprintf("\tstart,end,current time = %d, %d, %d - found=%d\n",
+ starttime,endtime,curtime,found);
+ }
+ else errprintf("Bad timespec (missing colon or no endtime): %s\n", onesla);
+ }
+ else errprintf("Bad timespec (missing colon or no starttime): %s\n", onesla);
}
- result = found;
- }
- else {
- /* No SLA -> use the default */
- result = defresult;
+ else {
+ dprintf("\tWeekday does not match\n");
+ }
+
+ /* Go to next SLA spec. */
+ if (endsla) *endsla = ',';
+ onesla = (endsla ? (endsla + 1) : NULL);
}
- xfree(tagspec);
- return result;
+ return found;
}
--- lib/timefunc.h 2005/02/20 08:19:11 1.5
+++ lib/timefunc.h 2005/03/25 07:20:59
@@ -1,7 +1,7 @@
/*----------------------------------------------------------------------------*/
-/* bbgen toolkit */
+/* Hobbit monitor library. */
/* */
-/* Copyright (C) 2002-2004 Henrik Storner <henrik at storner.dk> */
+/* Copyright (C) 2002-2005 Henrik Storner <henrik at storner.dk> */
/* */
/* This program is released under the GNU General Public License (GPL), */
/* version 2. See the file "COPYING" for details. */
@@ -17,7 +17,7 @@
extern char *weekday_text(char *dayspec);
extern char *time_text(char *timespec);
extern struct timeval *tvdiff(struct timeval *tstart, struct timeval *tend, struct timeval *result);
-extern int within_sla(char *l, char *tag, int defresult);
+extern int within_sla(char *l, int defresult);
extern int periodcoversnow(char *tag);
extern char *histlogtime(time_t histtime);
extern int durationvalue(char *dur);
More information about the Xymon
mailing list