Beispiel #1
0
void calc_pagecolors(xymongen_page_t *phead)
{
	xymongen_page_t 	*p, *toppage;
	group_t *g;
	host_t  *h;
	int	color, oldage;

	for (toppage=phead; (toppage); toppage = toppage->next) {

		/* Start with the color of immediate hosts */
		color = -1; oldage = 1;
		for (h = toppage->hosts; (h); h = h->next) {
			if (h->color > color) color = h->color;
			oldage &= h->oldage;
		}

		/* Then adjust with the color of hosts in immediate groups */
		for (g = toppage->groups; (g); g = g->next) {
			for (h = g->hosts; (h); h = h->next) {
				if ((g->onlycols == NULL) && (g->exceptcols == NULL)) {
					/* No group-only or group-except directives - use host color */
					if (h->color > color) color = h->color;
					oldage &= h->oldage;
				}
				else if (g->onlycols) {
					/* This is a group-only directive. Color must be
					 * based on the tests included in the group-only
					 * directive, NOT all tests present for the host.
					 * So we need to re-calculate host color from only
					 * the selected tests.
					 */
					entry_t *e;

					for (e = h->entries; (e); e = e->next) {
						if ( e->propagate && 
						     (e->color > color) &&
						     wantedcolumn(e->column->name, g->onlycols) )
							color = e->color;
							oldage &= e->oldage;
					}

					/* Blue and clear is not propagated upwards */
					if ((color == COL_CLEAR) || (color == COL_BLUE)) color = COL_GREEN;
				}
				else if (g->exceptcols) {
					/* This is a group-except directive. Color must be
					 * based on the tests NOT included in the group-except
					 * directive, NOT all tests present for the host.
					 * So we need to re-calculate host color from only
					 * the selected tests.
					 */
					entry_t *e;

					for (e = h->entries; (e); e = e->next) {
						if ( e->propagate && 
						     (e->color > color) &&
						     !wantedcolumn(e->column->name, g->exceptcols) )
							color = e->color;
							oldage &= e->oldage;
					}

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

		/* Then adjust with the color of subpages, if any.  */
		/* These must be calculated first!                  */
		if (toppage->subpages) {
			calc_pagecolors(toppage->subpages);
		}

		for (p = toppage->subpages; (p); p = p->next) {
			if (p->color > color) color = p->color;
			oldage &= p->oldage;
		}

		if (color == -1) {
			/*
			 * If no hosts or subpages, all goes green.
			 */
			color = COL_GREEN;
			oldage = 1;
		}

		toppage->color = color;
		toppage->oldage = oldage;
	}
}
Beispiel #2
0
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;
			}
		}
	}
}