host_t *init_host(char *hostname, int issummary, char *displayname, char *clientalias, char *comment, char *description, int ip1, int ip2, int ip3, int ip4, int dialup, double warnpct, int warnstops, char *reporttime, char *alerts, int crittime, char *waps, char *nopropyellowtests, char *nopropredtests, char *noproppurpletests, char *nopropacktests) { host_t *newhost = (host_t *) calloc(1, sizeof(host_t)); hostlist_t *oldlist; hostcount++; dbgprintf("init_host(%s)\n", textornull(hostname)); newhost->hostname = newhost->displayname = strdup(hostname); if (displayname) newhost->displayname = strdup(displayname); newhost->clientalias = (clientalias ? strdup(clientalias) : NULL); newhost->comment = (comment ? strdup(comment) : NULL); newhost->description = (description ? strdup(description) : NULL); sprintf(newhost->ip, "%d.%d.%d.%d", ip1, ip2, ip3, ip4); newhost->pretitle = NULL; newhost->entries = NULL; newhost->color = -1; newhost->oldage = 1; newhost->dialup = dialup; newhost->reportwarnlevel = warnpct; newhost->reportwarnstops = warnstops; newhost->reporttime = (reporttime ? strdup(reporttime) : NULL); if (alerts && crittime) { newhost->alerts = strdup(alerts); } else { newhost->alerts = NULL; } newhost->anywaps = 0; newhost->wapcolor = -1; /* Wap set is : * - Specific WML: tag * - NK: tag * - --wap=COLUMN cmdline option * - NULL */ if (waps || alerts) { newhost->waps = strdup(waps ? waps : alerts); } else { newhost->waps = wapcolumns; } if (nopropyellowtests) { char *p; p = skipword(nopropyellowtests); if (*p) *p = '\0'; else p = NULL; newhost->nopropyellowtests = strdup(build_noprop(nopropyellowdefault, nopropyellowtests)); if (p) *p = ' '; } else { newhost->nopropyellowtests = nopropyellowdefault; } if (nopropredtests) { char *p; p = skipword(nopropredtests); if (*p) *p = '\0'; else p = NULL; newhost->nopropredtests = strdup(build_noprop(nopropreddefault, nopropredtests)); if (p) *p = ' '; } else { newhost->nopropredtests = nopropreddefault; } if (noproppurpletests) { char *p; p = skipword(noproppurpletests); if (*p) *p = '\0'; else p = NULL; newhost->noproppurpletests = strdup(build_noprop(noproppurpledefault, noproppurpletests)); if (p) *p = ' '; } else { newhost->noproppurpletests = noproppurpledefault; } if (nopropacktests) { char *p; p = skipword(nopropacktests); if (*p) *p = '\0'; else p = NULL; newhost->nopropacktests = strdup(build_noprop(nopropackdefault, nopropacktests)); if (p) *p = ' '; } else { newhost->nopropacktests = nopropackdefault; } newhost->parent = NULL; newhost->nonongreen = 0; newhost->next = NULL; /* Summary hosts don't go into the host list */ if (issummary) return newhost; /* * Add this host to the hostlist_t list of known hosts. * HOWEVER: It might be a duplicate! In that case, we need * to figure out which host record we want to use. */ oldlist = find_hostlist(hostname); if (oldlist == NULL) { hostlist_t *newlist; newlist = (hostlist_t *) calloc(1, sizeof(hostlist_t)); newlist->hostentry = newhost; newlist->clones = NULL; add_to_hostlist(newlist); } else { hostlist_t *clone = (hostlist_t *) calloc(1, sizeof(hostlist_t)); dbgprintf("Duplicate host definition for host '%s'\n", hostname); clone->hostentry = newhost; clone->clones = oldlist->clones; oldlist->clones = clone; } return newhost; }
state_t *init_state(char *filename, logdata_t *log) { FILE *fd = NULL; char *p; char *hostname; char *testname; char *testnameidx; state_t *newstate; char fullfn[PATH_MAX]; host_t *host; struct stat log_st; time_t now = getcurrenttime(NULL); time_t histentry_start; int logexpired = 0; int propagating, isacked; dbgprintf("init_state(%s, %d, ...)\n", textornull(filename)); /* Ignore summary files and dot-files (this catches "." and ".." also) */ if ( (strncmp(filename, "summary.", 8) == 0) || (filename[0] == '.')) { return NULL; } if (reportstart || snapshot) { /* Dont do reports for info- and trends-columns */ p = strrchr(filename, '.'); if (p == NULL) return NULL; p++; if (strcmp(p, xgetenv("INFOCOLUMN")) == 0) return NULL; if (strcmp(p, xgetenv("TRENDSCOLUMN")) == 0) return NULL; /* * When doing reports, we are scanning the BBHIST directory. It may * contain files that are named as a host only (no test-name). * Skip those. */ if (find_host(filename)) return NULL; } if (!reportstart && !snapshot) { hostname = strdup(log->hostname); testname = strdup(log->testname); logexpired = (log->validtime < now); } else { sprintf(fullfn, "%s/%s", xgetenv("BBHIST"), filename); /* Check that we can access this file */ if ( (stat(fullfn, &log_st) == -1) || (!S_ISREG(log_st.st_mode)) || ((fd = fopen(fullfn, "r")) == NULL) ) { errprintf("Weird file '%s' skipped\n", fullfn); return NULL; } /* Pick out host- and test-name */ logexpired = (log_st.st_mtime < now); hostname = strdup(filename); p = strrchr(hostname, '.'); /* Skip files that have no '.' in filename */ if (p) { /* Pick out the testname ... */ *p = '\0'; p++; testname = strdup(p); /* ... and change hostname back into normal form */ for (p=hostname; (*p); p++) { if (*p == ',') *p='.'; } } else { xfree(hostname); fclose(fd); return NULL; } } /* Must do these first to get the propagation value for the statistics */ host = find_host(hostname); isacked = (log->acktime > now); propagating = checkpropagation(host, testname, log->color, isacked); /* Count all of the real columns */ if ( (strcmp(testname, xgetenv("INFOCOLUMN")) != 0) && (strcmp(testname, xgetenv("TRENDSCOLUMN")) != 0) ) { statuscount++; switch (log->color) { case COL_RED: case COL_YELLOW: if (propagating) colorcount[log->color] += 1; else colorcount_noprop[log->color] += 1; break; default: colorcount[log->color] += 1; break; } } testnameidx = (char *)malloc(strlen(testname) + 3); sprintf(testnameidx, ",%s,", testname); if (unwantedcolumn(hostname, testname) || (ignorecolumns && strstr(ignorecolumns, testnameidx))) { xfree(hostname); xfree(testname); xfree(testnameidx); if (fd) fclose(fd); return NULL; /* Ignore this type of test */ } xfree(testnameidx); newstate = (state_t *) calloc(1, sizeof(state_t)); newstate->entry = (entry_t *) calloc(1, sizeof(entry_t)); newstate->next = NULL; newstate->entry->column = find_or_create_column(testname, 1); newstate->entry->color = -1; strcpy(newstate->entry->age, ""); newstate->entry->oldage = 0; newstate->entry->propagate = 1; newstate->entry->testflags = NULL; newstate->entry->skin = NULL; newstate->entry->repinfo = NULL; newstate->entry->causes = NULL; newstate->entry->histlogname = NULL; newstate->entry->shorttext = NULL; if (host) { newstate->entry->alert = checkalert(host->alerts, testname); /* If no WAP's specified, default all tests to be on WAP page */ newstate->entry->onwap = (host->waps ? checkalert(host->waps, testname) : 1); } else { dbgprintf(" hostname %s not found\n", hostname); newstate->entry->alert = newstate->entry->onwap = 0; } newstate->entry->sumurl = NULL; if (reportstart) { /* Determine "color" for this test from the historical data */ newstate->entry->repinfo = (reportinfo_t *) calloc(1, sizeof(reportinfo_t)); newstate->entry->color = parse_historyfile(fd, newstate->entry->repinfo, (dynamicreport ? NULL: hostname), (dynamicreport ? NULL : testname), reportstart, reportend, 0, (host ? host->reportwarnlevel : reportwarnlevel), reportgreenlevel, (host ? host->reportwarnstops : reportwarnstops), (host ? host->reporttime : NULL)); newstate->entry->causes = (dynamicreport ? NULL : save_replogs()); } else if (snapshot) { time_t fileage = snapshot - histentry_start; newstate->entry->color = history_color(fd, snapshot, &histentry_start, &newstate->entry->histlogname); newstate->entry->oldage = (fileage >= recentgif_limit); newstate->entry->fileage = fileage; strcpy(newstate->entry->age, agestring(fileage)); } else { time_t fileage = (now - log->lastchange); newstate->entry->color = log->color; newstate->entry->testflags = strdup(log->testflags); if (testflag_set(newstate->entry, 'D')) newstate->entry->skin = dialupskin; if (testflag_set(newstate->entry, 'R')) newstate->entry->skin = reverseskin; newstate->entry->shorttext = strdup(log->msg); newstate->entry->acked = isacked; newstate->entry->oldage = (fileage >= recentgif_limit); newstate->entry->fileage = (log->lastchange ? fileage : -1); if (log->lastchange == 0) strcpy(newstate->entry->age, ""); else strcpy(newstate->entry->age, agestring(fileage)); } if (purplelog && (newstate->entry->color == COL_PURPLE)) { fprintf(purplelog, "%s %s%s\n", hostname, testname, (host ? " (expired)" : " (unknown host)")); } newstate->entry->propagate = propagating; dbgprintf("init_state: hostname=%s, testname=%s, color=%d, acked=%d, age=%s, oldage=%d, propagate=%d, alert=%d\n", textornull(hostname), textornull(testname), newstate->entry->color, newstate->entry->acked, textornull(newstate->entry->age), newstate->entry->oldage, newstate->entry->propagate, newstate->entry->alert); if (host) { hostlist_t *l; /* Add this state entry to the host's list of state entries. */ newstate->entry->next = host->entries; host->entries = newstate->entry; /* There may be multiple host entries, if a host is * listed in several locations in bb-hosts (for display purposes). * This is handled by updating ALL of the cloned host records. * Bug reported by Bluejay Adametz of Fuji. */ /* Cannot use "find_host()" here, as we need the hostlink record, not the host record */ l = find_hostlist(hostname); /* Walk through the clone-list and set the "entries" for all hosts */ for (l=l->clones; (l); l = l->clones) l->hostentry->entries = host->entries; } else { /* No host for this test - must be missing from bb-hosts */ newstate->entry->next = NULL; } xfree(hostname); xfree(testname); if (fd) fclose(fd); return newstate; }