예제 #1
0
파일: process.c 프로젝트: osvaldsson/xymon
void calc_hostcolors(char *nongreenignores)
{
	int		color, nongreencolor, criticalcolor, oldage;
	hostlist_t 	*h, *cwalk;
	entry_t		*e;

	for (h = hostlistBegin(); (h); h = hostlistNext()) {
		color = nongreencolor = criticalcolor = 0; oldage = 1;

		for (e = h->hostentry->entries; (e); e = e->next) {
			if (e->propagate && (e->color > color)) color = e->color;
			oldage &= e->oldage;

			if (e->propagate && (e->color > nongreencolor) && (strstr(nongreenignores, e->column->listname) == NULL)) {
				nongreencolor = e->color;
			}

			if (e->propagate && e->alert && (e->color > criticalcolor)) {
				criticalcolor = e->color;
			}
		}

		/* Blue and clear is not propagated upwards */
		if ((color == COL_CLEAR) || (color == COL_BLUE)) color = COL_GREEN;

		h->hostentry->color = color;
		h->hostentry->nongreencolor = nongreencolor;
		h->hostentry->criticalcolor = criticalcolor;
		h->hostentry->oldage = oldage;

		/* Need to update the clones also */
		for (cwalk = h->clones; (cwalk); cwalk = cwalk->clones) {
			cwalk->hostentry->color = color;
			cwalk->hostentry->nongreencolor = nongreencolor;
			cwalk->hostentry->criticalcolor = criticalcolor;
			cwalk->hostentry->oldage = oldage;
		}
	}
}
예제 #2
0
파일: loaddata.c 프로젝트: tjyang/abmon
void generate_compactitems(state_t **topstate)
{
	void *bbh;
	compact_t **complist = NULL;
	int complistsz = 0;
	hostlist_t 	*h;
	entry_t		*e;
	char *compacted;
	char *tok1, *tok2, *savep1, *savep2;
	compact_t *itm;
	int i;
	state_t *newstate;
	time_t now = getcurrenttime(NULL);

	for (h = hostlistBegin(); (h); h = hostlistNext()) {
		bbh = hostinfo(h->hostentry->hostname);
		compacted = bbh_item(bbh, BBH_COMPACT);
		if (!compacted) continue;

		tok1 = strtok_r(compacted, ",", &savep1);
		while (tok1) {
			char *members;

			itm = (compact_t *)calloc(1, sizeof(compact_t));
			itm->compactname = strdup(strtok_r(tok1, "=", &savep2));
			members = strtok_r(NULL, "\n", &savep2);
			itm->members = (char *)malloc(3 + strlen(members));
			sprintf(itm->members, "|%s|", members);

			if (complistsz == 0) {
				complist = (compact_t **)calloc(2, sizeof(compact_t *));
			}
			else {
				complist = (compact_t **)realloc(complist, (complistsz+2)*sizeof(compact_t *));
			}

			complist[complistsz++] = itm;
			complist[complistsz] = NULL;

			tok1 = strtok_r(NULL, ",", &savep1);
		}

		for (e = h->hostentry->entries; (e); e = e->next) {
			for (i = 0; (i < complistsz); i++) {
				if (wantedcolumn(e->column->name, complist[i]->members)) {
					e->compacted = 1;
					if (e->color > complist[i]->color) complist[i]->color = e->color;
					if (e->fileage > complist[i]->fileage) complist[i]->fileage = e->fileage;
				}
			}
		}

		for (i = 0; (i < complistsz); i++) {
			logdata_t log;
			char fn[PATH_MAX];

			memset(&log, 0, sizeof(log));
			sprintf(fn, "%s.%s", commafy(h->hostentry->hostname), complist[i]->compactname);
			log.hostname = h->hostentry->hostname;
			log.testname = complist[i]->compactname;
			log.color = complist[i]->color;
			log.testflags = "";
			log.lastchange = now - complist[i]->fileage;
			log.logtime = getcurrenttime(NULL);
			log.validtime = log.logtime + 300;
			log.sender = "";
			log.msg = "";
			newstate = init_state(fn, &log);
			if (newstate) {
				newstate->next = *topstate;
				*topstate = newstate;
			}
		}
	}
}
예제 #3
0
파일: wmlgen.c 프로젝트: Kotty666/xymon
void do_wml_cards(char *webdir)
{
	FILE		*nongreenfd, *hostfd;
	char		nongreenfn[PATH_MAX], hostfn[PATH_MAX];
	hostlist_t	*h;
	entry_t		*t;
	int		nongreenwapcolor;
	long		wmlmaxchars = 1500;
	int		nongreenpart = 1;

	/* Determine where the WML files go */
	sprintf(wmldir, "%s/wml", webdir);

	/* Make sure the WML directory exists */
	if (chdir(wmldir) != 0) mkdir(wmldir, 0755);
	if (chdir(wmldir) != 0) {
		errprintf("Cannot access or create the WML output directory %s\n", wmldir);
		return;
	}

	/* Make sure this is set sensibly */
	if (xgetenv("WMLMAXCHARS")) {
		wmlmaxchars = atol(xgetenv("WMLMAXCHARS"));
	}

	/*
	 * Cleanup cards that are too old.
	 */
	delete_old_cards(wmldir);

	/* 
	 * Find all the test entries that belong on the WAP page,
	 * and calculate the color for the nongreen wap page.
	 *
	 * We want only tests that have the "onwap" flag set, i.e.
	 * tests given in the "WAP:test,..." for this host (of the
	 * "NK:test,..." if no WAP list).
	 *
	 * At the same time, generate the WML card for the tests,
	 * corresponding to the HTML file for the test logfile.
	 */
	nongreenwapcolor = COL_GREEN;
	for (h = hostlistBegin(); (h); h = hostlistNext()) {
		h->hostentry->wapcolor = COL_GREEN;
		for (t = h->hostentry->entries; (t); t = t->next) {
			if (t->onwap && ((t->color == COL_RED) || (t->color == COL_YELLOW))) {
				generate_wml_statuscard(h->hostentry, t);
				h->hostentry->anywaps = 1;
			}
			else {
				/* Clear the onwap flag - makes testing later a bit simpler */
				t->onwap = 0;
			}

			if (t->onwap && (t->color > h->hostentry->wapcolor)) h->hostentry->wapcolor = t->color;
		}

		/* Update the nongreenwapcolor */
		if ( (h->hostentry->wapcolor == COL_RED) || (h->hostentry->wapcolor == COL_YELLOW) ) {
			if (h->hostentry->wapcolor > nongreenwapcolor) nongreenwapcolor = h->hostentry->wapcolor;
		}
	}

	/* Start the non-green WML card */
	sprintf(nongreenfn, "%s/nongreen.wml.tmp", wmldir);
	nongreenfd = fopen(nongreenfn, "w");
	if (nongreenfd == NULL) {
		errprintf("Cannot open non-green WML file %s\n", nongreenfn);
		return;
	}

	/* Standard non-green wap header */
	wml_header(nongreenfd, "card", nongreenpart);
	fprintf(nongreenfd, "<p align=\"center\" mode=\"nowrap\">\n");
	fprintf(nongreenfd, "%s</p>\n", timestamp);
	fprintf(nongreenfd, "<p align=\"center\" mode=\"nowrap\">\n");
	fprintf(nongreenfd, "Summary Status<br/><b>%s</b><br/><br/>\n", colorname(nongreenwapcolor));

	/* All green ? Just say so */
	if (nongreenwapcolor == COL_GREEN) {
		fprintf(nongreenfd, "All is OK<br/>\n");
	}

	/* Now loop through the hostlist again, and generate the nongreen WAP links and host pages */
	for (h = hostlistBegin(); (h); h = hostlistNext()) {
		if (h->hostentry->anywaps) {

			/* Create the host WAP card, with links to individual test results */
			sprintf(hostfn, "%s/%s.wml", wmldir, h->hostentry->hostname);
			hostfd = fopen(hostfn, "w");
			if (hostfd == NULL) {
				errprintf("Cannot create file %s\n", hostfn);
				return;
			}

			wml_header(hostfd, "name", 1);
			fprintf(hostfd, "<p align=\"center\">\n");
			fprintf(hostfd, "<anchor title=\"XYMON\">Overall<go href=\"nongreen.wml\"/></anchor><br/>\n");
			fprintf(hostfd, "%s</p>\n", timestamp);
			fprintf(hostfd, "<p align=\"left\" mode=\"nowrap\">\n");
			fprintf(hostfd, "<b>%s</b><br/><br/>\n", h->hostentry->hostname);

			for (t = h->hostentry->entries; (t); t = t->next) {
				if (t->onwap) {
					fprintf(hostfd, "<b><anchor title=\"%s\">%s%s<go href=\"%s.%s.wml\"/></anchor></b> %s<br/>\n", 
						t->column->name, 
						wml_colorname(t->color),
						(t->acked ? "x" : ""),
						h->hostentry->hostname, t->column->name,
						t->column->name);
				}
			}
			fprintf(hostfd, "\n</p> </card> </wml>\n");
			fclose(hostfd);

			/* Create the link from the nongreen wap card to the host card */
			fprintf(nongreenfd, "<b><anchor title=\"%s\">%s<go href=\"%s.wml\"/></anchor></b> %s<br/>\n", 
				h->hostentry->hostname, wml_colorname(h->hostentry->wapcolor), 
				h->hostentry->hostname, h->hostentry->hostname);

			/* 
			 * Gross hack. Some WAP phones cannot handle large cards. 
			 * So if the card grows larger than WMLMAXCHARS, split it into 
			 * multiple files and link from one file to the next.
			 */
			if (ftello(nongreenfd) >= wmlmaxchars) {
				char oldnongreenfn[PATH_MAX];

				/* WML link is from the nongreenfd except leading wmldir+'/' */
				strcpy(oldnongreenfn, nongreenfn+strlen(wmldir)+1);

				nongreenpart++;

				fprintf(nongreenfd, "<br /><b><anchor title=\"Next\">Next<go href=\"nongreen-%d.wml\"/></anchor></b>\n", nongreenpart);
				fprintf(nongreenfd, "</p> </card> </wml>\n");
				fclose(nongreenfd);

				/* Start a new Nongreen WML card */
				sprintf(nongreenfn, "%s/nongreen-%d.wml", wmldir, nongreenpart);
				nongreenfd = fopen(nongreenfn, "w");
				if (nongreenfd == NULL) {
					errprintf("Cannot open Nongreen WML file %s\n", nongreenfd);
					return;
				}
				wml_header(nongreenfd, "card", nongreenpart);
				fprintf(nongreenfd, "<p align=\"center\">\n");
				fprintf(nongreenfd, "<anchor title=\"Prev\">Previous<go href=\"%s\"/></anchor><br/>\n", oldnongreenfn);
				fprintf(nongreenfd, "%s</p>\n", timestamp);
				fprintf(nongreenfd, "<p align=\"center\" mode=\"nowrap\">\n");
				fprintf(nongreenfd, "Summary Status<br/><b>%s</b><br/><br/>\n", colorname(nongreenwapcolor));
			}
		}
	}

	fprintf(nongreenfd, "</p> </card> </wml>\n");
	fclose(nongreenfd);

	if (chdir(wmldir) == 0) {
		/* Rename the top-level file into place now */
		rename("nongreen.wml.tmp", "nongreen.wml");

		/* Make sure there is the index.wml file pointing to nongreen.wml */
		if (!symlink("nongreen.wml", "index.wml")) {
			errprintf("symlink nongreen.xml->index.wml failed: %s\n", strerror(errno));
		}
	}

	return;
}
예제 #4
0
파일: bbconvert.c 프로젝트: tjyang/abmon
void dump_hobbitdchk(void)
{
	hostlist_t *hwalk;
	entry_t *e;

	for (hwalk = hostlistBegin(); (hwalk); hwalk = hostlistNext()) {
		host_t *h = hwalk->hostentry;

		for (e = h->entries; (e); e = e->next) {
			char logfn[PATH_MAX];
			struct stat st;
			FILE *logfd;
			char *logbuf, *logenc;
			int n;
			size_t bytesread;
			char *flags = NULL;
			char *sender = NULL;
			char *unchstr = NULL;
			char *p;
			time_t validtime;
			int oldcol = -1;
			int lastchange = 0;
			time_t enabletime = 0;
			time_t acktime = 0;
			time_t logtime = 0;
			int cookie = -1;
			time_t cookieexpires = 0;

			sprintf(logfn, "%s/%s.%s", xgetenv("BBLOGS"), commafy(h->hostname), e->column->name);
			if (stat(logfn, &st) == -1) continue;
			logfd = fopen(logfn, "r");
			if (logfd == NULL) continue;
			logbuf = (char *)malloc(st.st_size+1);
			bytesread = fread(logbuf, 1, st.st_size, logfd);
			fclose(logfd);
			if (bytesread == -1) {
				xfree(logbuf);
				continue;
			}
			*(logbuf+bytesread) = '\0';

			logenc = nlencode(logbuf);
			validtime = st.st_mtime;
			logtime = st.st_mtime - 300;	/* Guess */

			p = strstr(logbuf, " <!-- [flags:");
			if (p) p = p + strlen(" <!-- [flags:");
			if (p) {
				char savech;
				n = strspn(p, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
				savech = *(p+n);
				*(p+n) = '\0';
				flags = strdup(p);
				*(p+n) = savech;
			}

			p = strstr(logbuf, "\nMessage received from ");
			if (p) sender = p + strlen("\nMessage received from ");
			p = strstr(logbuf, "\nStatus unchanged in ");
			if (p) unchstr = p + strlen("\nStatus unchanged in ");
			if (sender) { p = strchr(sender, '\n'); if (p) *p = '\0'; } else sender = "";
			if (unchstr) { p = strchr(unchstr, '\n'); if (p) *p = '\0'; } else unchstr = "";

			sprintf(logfn, "%s/%s.%s", xgetenv("BBHIST"), commafy(h->hostname), e->column->name);
			stat(logfn, &st);
			logfd = fopen(logfn, "r");
			if (logfd) {
				char l[100], colstr[20];
				int curcol = COL_GREEN, n;
				if (st.st_size > 130) fseeko(logfd, -130, SEEK_END);
				while (fgets(l, sizeof(l), logfd)) {
					n = sscanf(l+25, "%s %d", colstr, &lastchange);
					if (n == 2) {
						oldcol = curcol;
						curcol = parse_color(colstr);
					}
				}
			}
			fclose(logfd);

			sprintf(logfn, "%s/%s.%s", xgetenv("BBDISABLED"), commafy(h->hostname), e->column->name);
			if (stat(logfn, &st) == 0) enabletime = st.st_mtime;

			printf("@@HOBBITDCHK-V1|%s|%s|%s|%s|%s|%s|%s|%d|%d|%d|%d|%d|%d|%d|%s",
				"", h->hostname, e->column->name, sender,
				colorname(e->color),
				(flags ? flags : ""),
				colorname(oldcol),
				(int) logtime, lastchange, (int) validtime,
				(int) enabletime, (int) acktime,
				cookie, (int) cookieexpires,
				logenc);
			printf("|%s", ""); /* disable msg */
			printf("|%s", ""); /* ack msg */
			printf("\n");
		}
	}
}