void find_candidate(ghost_t *rec) { /* * Try to find an existing host definition for this ghost. * We look at the IP-address. * If the ghost reports with a FQDN, look for a host with * the same hostname without domain. * If the ghost reports a plain hostname (no domain), look * for a FQDN record with the same plain hostname. */ void *hrec; int found; char *gdelim, *tdelim, *ghostnofqdn, *hname; ghostnofqdn = rec->name; if ((gdelim = strchr(ghostnofqdn, '.')) != NULL) *gdelim = '\0'; for (hrec = first_host(), found = 0; (hrec && !found); hrec = next_host(hrec, 0)) { /* Check the IP */ found = (strcmp(rec->sender, xmh_item(hrec, XMH_IP)) == 0); if (!found) { /* Check if hostnames w/o domain match */ hname = xmh_item(hrec, XMH_HOSTNAME); if ((tdelim = strchr(hname, '.')) != NULL) *tdelim = '\0'; found = (strcasecmp(ghostnofqdn, hname) == 0); if (tdelim) *tdelim = '.'; } if (found) rec->candidate = hrec; } if (gdelim) *gdelim = '.'; }
int main(int argc, char *argv[]) { void *walk; load_hostnames(xgetenv("HOSTSCFG"), NULL, get_fqdn()); for (walk = first_host(); (walk); walk=next_host(walk, 0)) { char *nk, *nktime, *tok; nk = xmh_item(walk, XMH_NK); if (!nk) continue; nktime = xmh_item(walk, XMH_NKTIME); nk = strdup(nk); tok = strtok(nk, ","); while (tok) { char *hostname = xmh_item(walk, XMH_HOSTNAME); char *startstr = "", *endstr = "", *ttgroup = "", *ttextra = "", *updinfo = "Migrated"; int priority = 2; fprintf(stdout, "%s|%s|%s|%s|%s|%d|%s|%s|%s\n", hostname, tok, startstr, endstr, (nktime ? nktime : ""), priority, ttgroup, ttextra, updinfo); tok = strtok(NULL, ","); } xfree(nk); } return 0; }
static void count_events(countlist_t **hostcounthead, countlist_t **svccounthead) { void *hostwalk; for (hostwalk = first_host(); (hostwalk); hostwalk = next_host(hostwalk, 0)) { eventcount_t *swalk; countlist_t *hrec, *srec; swalk = (eventcount_t *)xmh_item(hostwalk, XMH_DATA); if (!swalk) continue; hrec = (countlist_t *)malloc(sizeof(countlist_t)); hrec->src = hostwalk; hrec->total = 0; hrec->next = *hostcounthead; *hostcounthead = hrec; for (swalk = (eventcount_t *)xmh_item(hostwalk, XMH_DATA); (swalk); swalk = swalk->next) { hrec->total += swalk->count; for (srec = *svccounthead; (srec && (srec->src != (void *)swalk->service)); srec = srec->next) ; if (!srec) { srec = (countlist_t *)malloc(sizeof(countlist_t)); srec->src = (void *)swalk->service; srec->total = 0; srec->next = *svccounthead; *svccounthead = srec; } srec->total += swalk->count; } } }
static void dump_eventtree(void) { void *hwalk; elist_t *lwalk; ed_t *ewalk; for (hwalk = first_host(); (hwalk); hwalk = next_host(hwalk, 0)) { printf("%s\n", xmh_item(hwalk, XMH_HOSTNAME)); lwalk = (elist_t *)xmh_item(hwalk, XMH_DATA); while (lwalk) { printf("\t%s\n", lwalk->svc->name); ewalk = lwalk->head; while (ewalk) { printf("\t\t%ld->%ld = %6ld %s\n", (long) ewalk->event->changetime, (long) ewalk->event->eventtime, (long) ewalk->event->duration, colorname(ewalk->event->oldcolor)); ewalk = ewalk->next; } lwalk = lwalk->next; } } }
int main(int argc, char *argv[]) { void *hwalk; char *hostsfn = NULL; char *netstring = NULL; char *include2 = NULL; int extras = 1; int testuntagged = 0; int nodownhosts = 0; int onlypreferredentry = 0; char *p; char **lookv; int argi, lookc; strbuffer_t *wantedtags; if ((argc <= 1) || (strcmp(argv[1], "--help") == 0)) { printf("Usage:\n%s test1 [test1] [test2] ... \n", argv[0]); exit(1); } lookv = (char **)malloc(argc*sizeof(char *)); lookc = 0; hostsfn = xgetenv("HOSTSCFG"); conncolumn = xgetenv("PINGCOLUMN"); for (argi=1; (argi < argc); argi++) { if (strcmp(argv[argi], "--noextras") == 0) { extras = 0; } else if (strcmp(argv[argi], "--test-untagged") == 0) { testuntagged = 1; } else if (argnmatch(argv[argi], "--no-down")) { char *p; nodownhosts = 1; p = strchr(argv[argi], '='); if (p) testcolumn = strdup(p+1); } else if (strcmp(argv[argi], "--version") == 0) { printf("xymongrep version %s\n", VERSION); exit(0); } else if ((strcmp(argv[argi], "--net") == 0) || (strcmp(argv[argi], "--bbnet") == 0)) { include2 = "netinclude"; onlypreferredentry = 0; } else if ((strcmp(argv[argi], "--web") == 0) || (strcmp(argv[argi], "--bbdisp") == 0)) { include2 = "dispinclude"; onlypreferredentry = 1; } else if (argnmatch(argv[argi], "--hosts=")) { hostsfn = strchr(argv[argi], '=') + 1; } else { lookv[lookc] = strdup(argv[argi]); lookc++; } } lookv[lookc] = NULL; if ((hostsfn == NULL) || (strlen(hostsfn) == 0)) { errprintf("Environment variable HOSTSCFG is not set - aborting\n"); exit(2); } load_hostnames(hostsfn, include2, get_fqdn()); if (first_host() == NULL) { errprintf("Cannot load %s, or file is empty\n", hostsfn); exit(3); } /* If we must avoid downed or disabled hosts, let's find out what those are */ if (nodownhosts) load_hoststatus(); /* Each network test tagged with NET:locationname */ p = xgetenv("XYMONNETWORK"); if ((p == NULL) || (strlen(p) == 0)) p = xgetenv("BBLOCATION"); if (p && strlen(p)) netstring = strdup(p); hwalk = first_host(); wantedtags = newstrbuffer(0); while (hwalk) { char hostip[IP_ADDR_STRLEN]; char *curnet = xmh_item(hwalk, XMH_NET); char *curname = xmh_item(hwalk, XMH_HOSTNAME); /* * Only look at the hosts whose NET: definition matches the wanted one. * Must also check if the host is currently down (not responding to ping). * And if the host is OK with knownhost(), because it may be time-limited. */ if (netok(netstring, curnet, testuntagged) && downok(curname, nodownhosts) && knownhost(curname, hostip, GH_IGNORE)) { char *item; clearstrbuffer(wantedtags); for (item = xmh_item_walk(hwalk); (item); item = xmh_item_walk(NULL)) { int i; char *realitem = item + strspn(item, "!~?"); for (i=0; lookv[i]; i++) { char *outitem = NULL; if (lookv[i][strlen(lookv[i])-1] == '*') { if (strncasecmp(realitem, lookv[i], strlen(lookv[i])-1) == 0) { outitem = (extras ? item : realitem); } } else if (strcasecmp(realitem, lookv[i]) == 0) { outitem = (extras ? item : realitem); } if (outitem) { int needquotes = ((strchr(outitem, ' ') != NULL) || (strchr(outitem, '\t') != NULL)); addtobuffer(wantedtags, " "); if (needquotes) addtobuffer(wantedtags, "\""); addtobuffer(wantedtags, outitem); if (needquotes) addtobuffer(wantedtags, "\""); } } } if (STRBUF(wantedtags) && (*STRBUF(wantedtags) != '\0') && extras) { if (xmh_item(hwalk, XMH_FLAG_DIALUP)) addtobuffer(wantedtags, " dialup"); if (xmh_item(hwalk, XMH_FLAG_TESTIP)) addtobuffer(wantedtags, " testip"); } if (STRBUF(wantedtags) && *STRBUF(wantedtags)) { printf("%s %s #%s\n", xmh_item(hwalk, XMH_IP), xmh_item(hwalk, XMH_HOSTNAME), STRBUF(wantedtags)); } } do { hwalk = next_host(hwalk, 1); } while (hwalk && onlypreferredentry && (strcmp(curname, xmh_item(hwalk, XMH_HOSTNAME)) == 0)); } return 0; }
static void count_duration(time_t fromtime, time_t totime, pcre *pageregexp, pcre *expageregexp, pcre *hostregexp, pcre *exhostregexp, pcre *testregexp, pcre *extestregexp, int ignoredialups, f_hostcheck hostcheck, event_t *eventhead, countlist_t **hostcounthead, countlist_t **svccounthead) { void *hwalk; elist_t *lwalk; event_t *ewalk; ed_t *ed; sendreturn_t *bdata; /* * Restructure the event-list so we have a tree instead: * * HostRecord * | *Data ----> EventList * | | *Service * | | *EventHead --> Event --> Event --> Event * | | *EventTail --------------------------^ * | | * | v * | * v * */ for (ewalk = eventhead; (ewalk); ewalk = ewalk->next) { lwalk = (elist_t *)xmh_item(ewalk->host, XMH_DATA); while (lwalk && (lwalk->svc != ewalk->service)) lwalk = lwalk->next; if (lwalk == NULL) { lwalk = (elist_t *)calloc(1, sizeof(elist_t)); lwalk->svc = ewalk->service; lwalk->next = (elist_t *)xmh_item(ewalk->host, XMH_DATA); xmh_set_item(ewalk->host, XMH_DATA, (void *)lwalk); } ed = (ed_t *)calloc(1, sizeof(ed_t)); ed->event = ewalk; ed->next = lwalk->head; if (lwalk->head == NULL) lwalk->tail = ed; lwalk->head = ed; } if (debug) { printf("\n\nEventtree before fixups\n\n"); dump_eventtree(); } /* * Next, we must add a pseudo record for the current state. * This is for those statuses that haven't changed since the * start of our data-collection period - they won't have any events * so we cannot tell what color they are. By grabbing the current * color we can add a pseudo-event that lets us determine what the * color has been since the start of the event-period. */ bdata = newsendreturnbuf(1, NULL); if (sendmessage("xymondboard fields=hostname,testname,color,lastchange", NULL, XYMON_TIMEOUT, bdata) == XYMONSEND_OK) { char *bol, *eol; char *hname, *tname; int color; time_t lastchange; void *hrec; htnames_t *srec; char *icname = xgetenv("INFOCOLUMN"); char *tcname = xgetenv("TRENDSCOLUMN"); bol = getsendreturnstr(bdata, 0); while (bol) { eol = strchr(bol, '\n'); if (eol) *eol = '\0'; hname = strtok(bol, "|"); tname = (hname ? strtok(NULL, "|") : NULL); color = (tname ? parse_color(strtok(NULL, "|")) : -1); lastchange = ((color != -1) ? atol(strtok(NULL, "\n")) : totime+1); if (hname && tname && (color != -1) && (strcmp(tname, icname) != 0) && (strcmp(tname, tcname) != 0)) { hrec = hostinfo(hname); srec = getname(tname, 1); if (eventfilter(hrec, tname, pageregexp, expageregexp, hostregexp, exhostregexp, testregexp, extestregexp, ignoredialups, hostcheck) == 0) goto nextrecord; lwalk = (elist_t *)xmh_item(hrec, XMH_DATA); while (lwalk && (lwalk->svc != srec)) lwalk = lwalk->next; if (lwalk == NULL) { lwalk = (elist_t *)calloc(1, sizeof(elist_t)); lwalk->svc = srec; lwalk->next = (elist_t *)xmh_item(hrec, XMH_DATA); xmh_set_item(hrec, XMH_DATA, (void *)lwalk); } /* See if we already have an event past the "totime" value */ if (lwalk->head) { ed = lwalk->head; while (ed && (ed->event->eventtime < totime)) ed = ed->next; if (ed) { ed->next = NULL; lwalk->tail = ed; } else { ed = (ed_t *)calloc(1, sizeof(ed_t)); ed->event = (event_t *)calloc(1, sizeof(event_t)); lwalk->tail->next = ed; ed->event->host = hrec; ed->event->service = srec; ed->event->eventtime = totime; ed->event->changetime = lwalk->tail->event->eventtime; ed->event->duration = (totime - lwalk->tail->event->eventtime); ed->event->newcolor = -1; ed->event->oldcolor = lwalk->tail->event->newcolor; ed->event->next = NULL; ed->next = NULL; lwalk->tail = ed; } } else if (lastchange < totime) { ed = (ed_t *)calloc(1, sizeof(ed_t)); ed->event = (event_t *)calloc(1, sizeof(event_t)); ed->event->host = hrec; ed->event->service = srec; ed->event->eventtime = totime; ed->event->changetime = (lwalk->tail ? lwalk->tail->event->eventtime : fromtime); ed->event->duration = (totime - ed->event->changetime); ed->event->newcolor = color; ed->event->oldcolor = (lwalk->tail ? lwalk->tail->event->newcolor : color); ed->event->next = NULL; ed->next = NULL; lwalk->head = lwalk->tail = ed; } } nextrecord: bol = (eol ? eol+1 : NULL); } freesendreturnbuf(bdata); } else { errprintf("Cannot get the current state\n"); freesendreturnbuf(bdata); return; } if (debug) { printf("\n\nEventtree after pseudo-events\n\n"); dump_eventtree(); } /* * Fixup the beginning-time (and duration) of the first events recorded. * This is to handle events that begin BEFORE our event-logging period. * Fixup the end-time (and duration) of the last events recorded. * This is to handle events that end AFTER our event-logging period. */ for (hwalk = first_host(); (hwalk); hwalk = next_host(hwalk, 0)) { elist_t *lwalk; event_t *erec; ed_t *ewalk; lwalk = (elist_t *)xmh_item(hwalk, XMH_DATA); while (lwalk) { if (lwalk->head) { erec = lwalk->head->event; if (erec->changetime > totime) { /* First event is after our start-time. Drop the events */ lwalk->head = lwalk->tail = NULL; } else if (erec->changetime < fromtime) { /* First event is before our start-time. Adjust to starttime. */ erec->changetime = fromtime; erec->duration = (erec->eventtime - fromtime); } ewalk = lwalk->head; while (ewalk && (ewalk->event->eventtime < totime)) ewalk = ewalk->next; if (ewalk) { lwalk->tail = ewalk; lwalk->tail->next = 0; } if (lwalk->tail) { erec = lwalk->tail->event; if (erec->eventtime > totime) { /* Last event is after our end-time. Adjust to end-time */ erec->eventtime = totime; erec->duration = (totime - erec->changetime); } } } lwalk = lwalk->next; } } if (debug) { printf("\n\nEventtree after fixups\n\n"); dump_eventtree(); } for (hwalk = first_host(); (hwalk); hwalk = next_host(hwalk, 0)) { countlist_t *hrec, *srec; hrec = (countlist_t *)malloc(sizeof(countlist_t)); hrec->src = hwalk; hrec->total = 0; hrec->next = *hostcounthead; *hostcounthead = hrec; lwalk = (elist_t *)xmh_item(hwalk, XMH_DATA); while (lwalk) { for (srec = *svccounthead; (srec && (srec->src != (void *)lwalk->svc)); srec = srec->next) ; if (!srec) { srec = (countlist_t *)malloc(sizeof(countlist_t)); srec->src = (void *)lwalk->svc; srec->total = 0; srec->next = *svccounthead; *svccounthead = srec; } if (lwalk->head) { ed_t *ewalk = lwalk->head; while (ewalk) { if (ewalk->event->oldcolor >= COL_YELLOW) { hrec->total += ewalk->event->duration; srec->total += ewalk->event->duration; } ewalk = ewalk->next; } } lwalk = lwalk->next; } } if (debug) dump_countlists(*hostcounthead, *svccounthead); }
int main(int argc, char *argv[]) { void *hostwalk, *clonewalk; int argi; char *envarea = NULL; strbuffer_t *outbuf; char msgline[4096]; char oneurl[10240]; int gotany = 0; enum { OP_INITIAL, OP_YES, OP_NO } gotonepage = OP_INITIAL; /* Tracks if all matches are on one page */ char *onepage = NULL; /* If gotonepage==OP_YES, then this is the page */ /*[wm] regex support */ #define BUFSIZE 256 regex_t re; char re_errstr[BUFSIZE]; int re_status; for (argi=1; (argi < argc); argi++) { if (argnmatch(argv[argi], "--env=")) { char *p = strchr(argv[argi], '='); loadenv(p+1, envarea); } else if (argnmatch(argv[argi], "--area=")) { char *p = strchr(argv[argi], '='); envarea = strdup(p+1); } } redirect_cgilog("findhost"); cgidata = cgi_request(); if (cgidata == NULL) { /* Present the query form */ sethostenv("", "", "", colorname(COL_BLUE), NULL); printf("Content-type: %s\n\n", xgetenv("HTMLCONTENTTYPE")); showform(stdout, "findhost", "findhost_form", COL_BLUE, getcurrenttime(NULL), NULL, NULL); return 0; } parse_query(); if ( (re_status = regcomp(&re, pSearchPat, re_flag)) != 0 ) { regerror(re_status, &re, re_errstr, BUFSIZE); print_header(); printf("<tr><td align=left><font color=red>%s</font></td>\n", pSearchPat); printf("<td align=left><font color=red>%s</font></td></tr>\n", re_errstr); print_footer(); return 0; } outbuf = newstrbuffer(0); load_hostnames(xgetenv("HOSTSCFG"), NULL, get_fqdn()); hostwalk = first_host(); while (hostwalk) { /* * [wm] - Allow the search to be done on the hostname * also on the "displayname" and the host comment * Maybe this should be implemented by changing the HTML form, but until than.. * we're supposing that hostname will NEVER be null */ char *hostname, *displayname, *comment, *ip; hostname = xmh_item(hostwalk, XMH_HOSTNAME); displayname = xmh_item(hostwalk, XMH_DISPLAYNAME); comment = xmh_item(hostwalk, XMH_COMMENT); ip = xmh_item(hostwalk, XMH_IP); if ( regexec (&re, hostname, (size_t)0, NULL, 0) == 0 || (regexec(&re, ip, (size_t)0, NULL, 0) == 0) || (displayname && regexec (&re, displayname, (size_t)0, NULL, 0) == 0) || (comment && regexec (&re, comment, (size_t)0, NULL, 0) == 0) ) { /* match */ addtobuffer(outbuf, "<tr>\n"); sprintf(msgline, "<td align=left> %s </td>\n", displayname ? displayname : hostname); addtobuffer(outbuf, msgline); sprintf(oneurl, "%s/%s/#%s", xgetenv("XYMONWEB"), xmh_item(hostwalk, XMH_PAGEPATH), hostname); sprintf(msgline, "<td align=left> <a href=\"%s\">%s</a>\n", oneurl, xmh_item(hostwalk, XMH_PAGEPATHTITLE)); addtobuffer(outbuf, msgline); gotany++; /* See if all of the matches so far are on one page */ switch (gotonepage) { case OP_INITIAL: gotonepage = OP_YES; onepage = xmh_item(hostwalk, XMH_PAGEPATH); break; case OP_YES: if (strcmp(onepage, xmh_item(hostwalk, XMH_PAGEPATH)) != 0) gotonepage = OP_NO; break; case OP_NO: break; } clonewalk = next_host(hostwalk, 1); while (clonewalk && (strcmp(xmh_item(hostwalk, XMH_HOSTNAME), xmh_item(clonewalk, XMH_HOSTNAME)) == 0)) { sprintf(msgline, "<br><a href=\"%s/%s/#%s\">%s</a>\n", xgetenv("XYMONWEB"), xmh_item(clonewalk, XMH_PAGEPATH), xmh_item(clonewalk, XMH_HOSTNAME), xmh_item(clonewalk, XMH_PAGEPATHTITLE)); addtobuffer(outbuf, msgline); clonewalk = next_host(clonewalk, 1); gotany++; } addtobuffer(outbuf, "</td>\n</tr>\n"); hostwalk = clonewalk; } else { hostwalk = next_host(hostwalk, 0); } } regfree (&re); /*[wm] - free regex compiled patern */ if (dojump) { if (gotany == 1) { printf("Location: %s%s\n\n", xgetenv("XYMONWEBHOST"), oneurl); return 0; } else if ((gotany > 1) && (gotonepage == OP_YES)) { printf("Location: %s%s/%s/\n\n", xgetenv("XYMONWEBHOST"), xgetenv("XYMONWEB"), onepage); return 0; } } print_header(); if (!gotany) { printf("<tr><td align=left>%s</td><td align=left>Not found</td></tr>\n", pSearchPat); } else { printf("%s", grabstrbuffer(outbuf)); } print_footer(); /* [wm] - Free the strdup allocated memory */ if (pSearchPat) xfree(pSearchPat); return 0; }
int main(int argc, char *argv[]) { void *hwalk; int argi; strbuffer_t *statusmsg, *jrockout, *qout; for (argi = 1; (argi < argc); argi++) { if ((strcmp(argv[argi], "--help") == 0)) { printf("beastat version %s\n\n", VERSION); printf("Usage:\n%s [--debug] [--no-update] [--port=SNMPPORT] [--community=SNMPCOMMUNITY]\n", argv[0]); exit(0); } else if ((strcmp(argv[argi], "--version") == 0)) { printf("beastat version %s\n", VERSION); exit(0); } else if ((strcmp(argv[argi], "--debug") == 0)) { debug = 1; } else if ((strcmp(argv[argi], "--no-update") == 0)) { dontsendmessages = 1; } else if (argnmatch(argv[argi], "--timeout=")) { char *p = strchr(argv[argi], '='); extcmdtimeout = atoi(p+1); } else if (argnmatch(argv[argi], "--port=")) { char *p = strchr(argv[argi], '='); default_port = atoi(p+1); } else if (argnmatch(argv[argi], "--community=")) { char *p = strchr(argv[argi], '='); default_community = strdup(p+1); } } load_hostnames(xgetenv("BBHOSTS"), "netinclude", get_fqdn()); if (first_host() == NULL) { errprintf("Cannot load bb-hosts\n"); return 1; } if (xgetenv("BBLOCATION")) location = strdup(xgetenv("BBLOCATION")); init_timestamp(); combo_start(); statusmsg = newstrbuffer(0); jrockout = newstrbuffer(0); qout = newstrbuffer(0); for (hwalk = first_host(); (hwalk); hwalk = next_host(hwalk, 0)) { char *tspec = bbh_custom_item(hwalk, "bea="); char *snmpcommunity = default_community; char *beadomain = ""; int snmpport = default_port; char *p; char pipecmd[4096]; int jrockres, qres; clearstrbuffer(statusmsg); clearstrbuffer(jrockout); clearstrbuffer(qout); /* Check if we have a "bea" test for this host, and it is a host we want to test */ if (!tspec || !wanted_host(hwalk, location)) continue; /* Parse the testspec: bea=[SNMPCOMMUNITY@]BEADOMAIN[:SNMPPORT] */ tspec = strdup(tspec+strlen("bea=")); p = strchr(tspec, ':'); if (p) { *p = '\0'; snmpport = atoi(p+1); } p = strchr(tspec, '@'); if (p) { *p = '\0'; snmpcommunity = strdup(tspec); beadomain = strdup(p+1); } else { beadomain = strdup(tspec); } /* Prepare for the host status */ statuscolor = COL_GREEN; /* Setup the snmpwalk pipe-command for jrockit stats */ sprintf(pipecmd, "snmpwalk -m BEA-WEBLOGIC-MIB -c %s@%s -v 1 %s:%d enterprises.140.625.302.1", snmpcommunity, beadomain, bbh_item(hwalk, BBH_IP), snmpport); jrockres = run_command(pipecmd, NULL, jrockout, 0, extcmdtimeout); if (jrockres == 0) { find_idxes(STRBUF(jrockout), "BEA-WEBLOGIC-MIB::jrockitRuntimeIndex."); send_data(hwalk, beadomain, STRBUF(jrockout), jrockitems); } else { if (statuscolor < COL_YELLOW) statuscolor = COL_YELLOW; sprintf(msgline, "Could not retrieve BEA jRockit statistics from %s:%d domain %s (code %d)\n", bbh_item(hwalk, BBH_IP), snmpport, beadomain, jrockres); addtobuffer(statusmsg, msgline); } /* Setup the snmpwalk pipe-command for executeQueur stats */ sprintf(pipecmd, "snmpwalk -m BEA-WEBLOGIC-MIB -c %s@%s -v 1 %s:%d enterprises.140.625.180.1", snmpcommunity, beadomain, bbh_item(hwalk, BBH_IP), snmpport); qres = run_command(pipecmd, NULL, qout, 0, extcmdtimeout); if (qres == 0) { find_idxes(STRBUF(qout), "BEA-WEBLOGIC-MIB::executeQueueRuntimeIndex."); send_data(hwalk, beadomain, STRBUF(qout), qitems); } else { if (statuscolor < COL_YELLOW) statuscolor = COL_YELLOW; sprintf(msgline, "Could not retrieve BEA executeQueue statistics from %s:%d domain %s (code %d)\n", bbh_item(hwalk, BBH_IP), snmpport, beadomain, qres); addtobuffer(statusmsg, msgline); } /* FUTURE: Have the statuscolor/statusmsg be updated to check against thresholds */ /* Right now, the "bea" status is always green */ init_status(statuscolor); sprintf(msgline, "status %s.%s %s %s\n\n", commafy(bbh_item(hwalk, BBH_HOSTNAME)), "bea", colorname(statuscolor), timestamp); addtostatus(msgline); if (STRBUFLEN(statusmsg) == 0) addtobuffer(statusmsg, "All BEA monitors OK\n"); addtostrstatus(statusmsg); finish_status(); } combo_end(); freestrbuffer(statusmsg); freestrbuffer(jrockout); freestrbuffer(qout); return 0; }
xymongen_page_t *load_layout(char *pgset) { char pagetag[100], subpagetag[100], subparenttag[100], vpagetag[100], vsubpagetag[100], vsubparenttag[100], grouptag[100], summarytag[100], titletag[100], hosttag[100]; char *name, *link, *onlycols, *exceptcols; char hostname[MAX_LINE_LEN]; xymongen_page_t *toppage, *curpage, *cursubpage, *cursubparent; group_t *curgroup; host_t *curhost; char *curtitle; int ip1, ip2, ip3, ip4; char *p; int fqdn = get_fqdn(); char *cfgdata, *inbol, *ineol, insavchar = '\0'; if (loadhostsfromxymond) { if (load_hostnames("@", NULL, fqdn) != 0) { errprintf("Cannot load host configuration from xymond\n"); return NULL; } } else { if (load_hostnames(xgetenv("HOSTSCFG"), "dispinclude", fqdn) != 0) { errprintf("Cannot load host configuration from %s\n", xgetenv("HOSTSCFG")); return NULL; } } if (first_host() == NULL) { errprintf("Empty configuration from %s\n", (loadhostsfromxymond ? "xymond" : xgetenv("HOSTSCFG"))); return NULL; } dbgprintf("load_layout(pgset=%s)\n", textornull(pgset)); /* * load_hostnames() picks up the hostname definitions, but not the page * layout. So we will scan the file again, this time doing the layout. */ if (pgset == NULL) pgset = ""; sprintf(pagetag, "%spage", pgset); sprintf(subpagetag, "%ssubpage", pgset); sprintf(subparenttag, "%ssubparent", pgset); sprintf(vpagetag, "v%spage", pgset); sprintf(vsubpagetag, "v%ssubpage", pgset); sprintf(vsubparenttag, "v%ssubparent", pgset); sprintf(grouptag, "%sgroup", pgset); sprintf(summarytag, "%ssummary", pgset); sprintf(titletag, "%stitle", pgset); sprintf(hosttag, "%s:", pgset); for (p=hosttag; (*p); p++) *p = toupper((int)*p); toppage = init_page("", "", 0); addtopagelist(toppage); curpage = NULL; cursubpage = NULL; curgroup = NULL; curhost = NULL; cursubparent = NULL; curtitle = NULL; inbol = cfgdata = hostscfg_content(); while (inbol && *inbol) { inbol += strspn(inbol, " \t"); ineol = strchr(inbol, '\n'); if (ineol) { while ((ineol > inbol) && (isspace(*ineol) || (*ineol == '\n'))) ineol--; if (*ineol != '\n') ineol++; insavchar = *ineol; *ineol = '\0'; } dbgprintf("load_layout: -- got line '%s'\n", inbol); if ((strncmp(inbol, pagetag, strlen(pagetag)) == 0) || (strncmp(inbol, vpagetag, strlen(vpagetag)) == 0)) { getnamelink(inbol, &name, &link); if (curpage == NULL) { /* First page - hook it on toppage as a subpage from there */ curpage = toppage->subpages = init_page(name, link, (strncmp(inbol, vpagetag, strlen(vpagetag)) == 0)); } else { curpage = curpage->next = init_page(name, link, (strncmp(inbol, vpagetag, strlen(vpagetag)) == 0)); } curpage->parent = toppage; if (curtitle) { curpage->pretitle = curtitle; curtitle = NULL; } cursubpage = NULL; cursubparent = NULL; curgroup = NULL; curhost = NULL; addtopagelist(curpage); } else if ( (strncmp(inbol, subpagetag, strlen(subpagetag)) == 0) || (strncmp(inbol, vsubpagetag, strlen(vsubpagetag)) == 0) ) { if (curpage == NULL) { errprintf("'subpage' ignored, no preceding 'page' tag : %s\n", inbol); goto nextline; } getnamelink(inbol, &name, &link); if (cursubpage == NULL) { cursubpage = curpage->subpages = init_page(name, link, (strncmp(inbol, vsubpagetag, strlen(vsubpagetag)) == 0)); } else { cursubpage = cursubpage->next = init_page(name, link, (strncmp(inbol, vsubpagetag, strlen(vsubpagetag)) == 0)); } cursubpage->parent = curpage; if (curtitle) { cursubpage->pretitle = curtitle; curtitle = NULL; } cursubparent = NULL; curgroup = NULL; curhost = NULL; addtopagelist(cursubpage); } else if ( (strncmp(inbol, subparenttag, strlen(subparenttag)) == 0) || (strncmp(inbol, vsubparenttag, strlen(vsubparenttag)) == 0) ) { xymongen_page_t *parentpage, *walk; getparentnamelink(inbol, toppage, &parentpage, &name, &link); if (parentpage == NULL) { errprintf("'subparent' ignored, unknown parent page: %s\n", inbol); goto nextline; } cursubparent = init_page(name, link, (strncmp(inbol, vsubparenttag, strlen(vsubparenttag)) == 0)); if (parentpage->subpages == NULL) { parentpage->subpages = cursubparent; } else { for (walk = parentpage->subpages; (walk->next); (walk = walk->next)) ; walk->next = cursubparent; } if (curtitle) { cursubparent->pretitle = curtitle; curtitle = NULL; } cursubparent->parent = parentpage; curgroup = NULL; curhost = NULL; addtopagelist(cursubparent); } else if (strncmp(inbol, grouptag, strlen(grouptag)) == 0) { int sorthosts = (strstr(inbol, "group-sorted") != NULL); getgrouptitle(inbol, pgset, &link, &onlycols, &exceptcols); if (curgroup == NULL) { curgroup = init_group(link, onlycols, exceptcols, sorthosts); if (cursubparent != NULL) { cursubparent->groups = curgroup; } else if (cursubpage != NULL) { /* We're in a subpage */ cursubpage->groups = curgroup; } else if (curpage != NULL) { /* We're on a main page */ curpage->groups = curgroup; } else { /* We're on the top page */ toppage->groups = curgroup; } } else { curgroup->next = init_group(link, onlycols, exceptcols, sorthosts); curgroup = curgroup->next; } if (curtitle) { curgroup->pretitle = curtitle; curtitle = NULL; } curhost = NULL; } else if (sscanf(inbol, "%3d.%3d.%3d.%3d %s", &ip1, &ip2, &ip3, &ip4, hostname) == 5) { void *xymonhost = NULL; int dialup, nonongreen, crittime = 1; double warnpct = reportwarnlevel; int warnstops = reportwarnstops; char *displayname, *clientalias, *comment, *description; char *alertlist, *onwaplist, *reporttime; char *nopropyellowlist, *nopropredlist, *noproppurplelist, *nopropacklist; char *targetpagelist[MAX_TARGETPAGES_PER_HOST]; int targetpagecount; char *hval; /* Check for ".default." hosts - they are ignored. */ if (*hostname == '.') goto nextline; if (!fqdn) { /* Strip any domain from the hostname */ char *p = strchr(hostname, '.'); if (p) *p = '\0'; } /* Get the info */ xymonhost = hostinfo(hostname); if (xymonhost == NULL) { errprintf("Confused - hostname '%s' cannot be found. Ignored\n", hostname); goto nextline; } /* Check for no-display hosts - they are ignored. */ /* But only when we're building the default pageset */ if ((strlen(pgset) == 0) && (xmh_item(xymonhost, XMH_FLAG_NODISP) != NULL)) goto nextline; for (targetpagecount=0; (targetpagecount < MAX_TARGETPAGES_PER_HOST); targetpagecount++) targetpagelist[targetpagecount] = NULL; targetpagecount = 0; dialup = (xmh_item(xymonhost, XMH_FLAG_DIALUP) != NULL); nonongreen = (xmh_item(xymonhost, XMH_FLAG_NONONGREEN) != NULL); alertlist = xmh_item(xymonhost, XMH_NK); hval = xmh_item(xymonhost, XMH_NKTIME); if (hval) crittime = within_sla(xmh_item(xymonhost, XMH_HOLIDAYS), hval, 0); onwaplist = xmh_item(xymonhost, XMH_WML); nopropyellowlist = xmh_item(xymonhost, XMH_NOPROPYELLOW); if (nopropyellowlist == NULL) nopropyellowlist = xmh_item(xymonhost, XMH_NOPROP); nopropredlist = xmh_item(xymonhost, XMH_NOPROPRED); noproppurplelist = xmh_item(xymonhost, XMH_NOPROPPURPLE); nopropacklist = xmh_item(xymonhost, XMH_NOPROPACK); displayname = xmh_item(xymonhost, XMH_DISPLAYNAME); comment = xmh_item(xymonhost, XMH_COMMENT); description = xmh_item(xymonhost, XMH_DESCRIPTION); hval = xmh_item(xymonhost, XMH_WARNPCT); if (hval) warnpct = atof(hval); hval = xmh_item(xymonhost, XMH_WARNSTOPS); if (hval) warnstops = atof(hval); reporttime = xmh_item(xymonhost, XMH_REPORTTIME); clientalias = xmh_item(xymonhost, XMH_CLIENTALIAS); if (xymonhost && (strcmp(xmh_item(xymonhost, XMH_HOSTNAME), clientalias) == 0)) clientalias = NULL; if (xymonhost && (strlen(pgset) > 0)) { /* Walk the clone-list and pick up the target pages for this host */ void *cwalk = xymonhost; do { hval = xmh_item_walk(cwalk); while (hval) { if (strncasecmp(hval, hosttag, strlen(hosttag)) == 0) targetpagelist[targetpagecount++] = strdup(hval+strlen(hosttag)); hval = xmh_item_walk(NULL); } cwalk = next_host(cwalk, 1); } while (cwalk && (strcmp(xmh_item(cwalk, XMH_HOSTNAME), xmh_item(xymonhost, XMH_HOSTNAME)) == 0) && (targetpagecount < MAX_TARGETPAGES_PER_HOST) ); /* * HACK: Check if the pageset tag is present at all in the host * entry. If it isn't, then drop this incarnation of the host. * * Without this, the following hosts.cfg file will have the * www.hswn.dk host listed twice on the alternate pageset: * * adminpage nyc NYC * * 127.0.0.1 localhost # bbd http://localhost/ CLIENT:osiris * 172.16.10.2 www.xymon.com # http://www.xymon.com/ ADMIN:nyc ssh noinfo * * page superdome Superdome * 172.16.10.2 www.xymon.com # noconn * */ if (strstr(inbol, hosttag) == NULL) targetpagecount = 0; } if (strlen(pgset) == 0) { /* * Default pageset generated. Put the host into * whatever group or page is current. */ if (curhost == NULL) { curhost = init_host(hostname, 0, displayname, clientalias, comment, description, ip1, ip2, ip3, ip4, dialup, warnpct, warnstops, reporttime, alertlist, crittime, onwaplist, nopropyellowlist, nopropredlist, noproppurplelist, nopropacklist); if (curgroup != NULL) { curgroup->hosts = curhost; } else if (cursubparent != NULL) { cursubparent->hosts = curhost; } else if (cursubpage != NULL) { cursubpage->hosts = curhost; } else if (curpage != NULL) { curpage->hosts = curhost; } else { toppage->hosts = curhost; } } else { curhost = curhost->next = init_host(hostname, 0, displayname, clientalias, comment, description, ip1, ip2, ip3, ip4, dialup, warnpct, warnstops, reporttime, alertlist, crittime, onwaplist, nopropyellowlist,nopropredlist, noproppurplelist, nopropacklist); } curhost->parent = (cursubparent ? cursubparent : (cursubpage ? cursubpage : curpage)); if (curtitle) { curhost->pretitle = curtitle; curtitle = NULL; } curhost->nonongreen = nonongreen; } else if (targetpagecount) { int pgnum; for (pgnum=0; (pgnum < targetpagecount); pgnum++) { char *targetpagename = targetpagelist[pgnum]; char savechar; int wantedgroup = 0; xymonpagelist_t *targetpage = NULL; /* Put the host into the page specified by the PGSET: tag */ p = strchr(targetpagename, ','); if (p) { savechar = *p; *p = '\0'; wantedgroup = atoi(p+1); } else { savechar = '\0'; p = targetpagename + strlen(targetpagename); } /* Find the page */ if (strcmp(targetpagename, "*") == 0) { *targetpagename = '\0'; } for (targetpage = pagelisthead; (targetpage && (strcmp(targetpagename, targetpage->pageentry->name) != 0)); targetpage = targetpage->next) ; *p = savechar; if (targetpage == NULL) { errprintf("Warning: Cannot find any target page named '%s' in set '%s' - dropping host '%s'\n", targetpagename, pgset, hostname); } else { host_t *newhost = init_host(hostname, 0, displayname, clientalias, comment, description, ip1, ip2, ip3, ip4, dialup, warnpct, warnstops, reporttime, alertlist, crittime, onwaplist, nopropyellowlist,nopropredlist, noproppurplelist, nopropacklist); if (wantedgroup > 0) { group_t *gwalk; host_t *hwalk; int i; for (gwalk = targetpage->pageentry->groups, i=1; (gwalk && (i < wantedgroup)); i++,gwalk=gwalk->next) ; if (gwalk) { if (gwalk->hosts == NULL) gwalk->hosts = newhost; else { for (hwalk = gwalk->hosts; (hwalk->next); hwalk = hwalk->next) ; hwalk->next = newhost; } } else { errprintf("Warning: Cannot find group %d for host %s - dropping host\n", wantedgroup, hostname); } } else { /* Just put in on the page's hostlist */ host_t *walk; if (targetpage->pageentry->hosts == NULL) targetpage->pageentry->hosts = newhost; else { for (walk = targetpage->pageentry->hosts; (walk->next); walk = walk->next) ; walk->next = newhost; } } newhost->parent = targetpage->pageentry; if (curtitle) newhost->pretitle = curtitle; } curtitle = NULL; } } } else if (strncmp(inbol, summarytag, strlen(summarytag)) == 0) { /* summary row.column IP-ADDRESS-OF-PARENT http://xymon.com/ */ char sumname[MAX_LINE_LEN]; char receiver[MAX_LINE_LEN]; char url[MAX_LINE_LEN]; summary_t *newsum; if (sscanf(inbol, "summary %s %s %s", sumname, receiver, url) == 3) { newsum = init_summary(sumname, receiver, url); newsum->next = sumhead; sumhead = newsum; } } else if (strncmp(inbol, titletag, strlen(titletag)) == 0) { /* Save the title for the next entry */ curtitle = strdup(skipwhitespace(skipword(inbol))); } nextline: if (ineol) { *ineol = insavchar; if (*ineol != '\n') ineol = strchr(ineol, '\n'); inbol = (ineol ? ineol+1 : NULL); } else inbol = NULL; } xfree(cfgdata); return toppage; }
int main(int argc, char *argv[]) { int argi; struct sigaction sa; namelist_t *hostwalk; time_t nexttimeout; for (argi=1; (argi < argc); argi++) { if (argnmatch(argv[argi], "--server=")) { char *p = strchr(argv[argi], '='); serverip = strdup(p+1); } else if (argnmatch(argv[argi], "--interval=")) { char *p = strchr(argv[argi], '='); pollinterval = atoi(p+1); } else if (argnmatch(argv[argi], "--log-interval=")) { char *p = strchr(argv[argi], '='); errorloginterval = atoi(p+1); } else if (argnmatch(argv[argi], "--id=")) { char *p = strchr(argv[argi], '='); serverid = atoi(p+1); } else if (strcmp(argv[argi], "--debug") == 0) { debug = 1; } } setup_signalhandler("hobbitfetch"); memset(&sa, 0, sizeof(sa)); sa.sa_handler = sigmisc_handler; sigaction(SIGHUP, &sa, NULL); sigaction(SIGTERM, &sa, NULL); sigaction(SIGUSR1, &sa, NULL); /* SIGUSR1 triggers logging of active requests */ clients = rbtNew(name_compare); nexttimeout = time(NULL) + 60; { /* Seed the random number generator */ struct timeval tv; struct timezone tz; gettimeofday(&tv, &tz); srandom(tv.tv_usec); } do { RbtIterator handle; conn_t *connwalk, *cprev; fd_set fdread, fdwrite; int n, maxfd; struct timeval tmo; time_t now; now = time(NULL); if (now > reloadtime) { /* Time to reload the bb-hosts file */ reloadtime = now + 600; load_hostnames(xgetenv("BBHOSTS"), NULL, get_fqdn()); for (hostwalk = first_host(); (hostwalk); hostwalk = hostwalk->next) { char *hname; clients_t *newclient; if (!bbh_item(hostwalk, BBH_FLAG_PULLDATA)) continue; hname = bbh_item(hostwalk, BBH_HOSTNAME); handle = rbtFind(clients, hname); if (handle == rbtEnd(clients)) { newclient = (clients_t *)calloc(1, sizeof(clients_t)); newclient->hostname = strdup(hname); rbtInsert(clients, newclient->hostname, newclient); whentoqueue = now; } } } now = time(NULL); if (now > nexttimeout) { /* Check for connections that have timed out */ nexttimeout = now + 60; for (connwalk = chead; (connwalk); connwalk = connwalk->next) { if ((connwalk->tstamp + 60) < now) { if (debug || (connwalk->client->nexterrortxt < now)) { errprintf("Timeout while talking to %s (req %lu): Aborting session\n", addrstring(&connwalk->caddr), connwalk->seq); connwalk->client->nexterrortxt = now + errorloginterval; } flag_cleanup(connwalk); } } } if (needcleanup) { /* Remove any finished requests */ needcleanup = 0; connwalk = chead; cprev = NULL; dbgprintf("Doing cleanup\n"); while (connwalk) { conn_t *zombie; if ((connwalk->action == C_READING) || (connwalk->action == C_WRITING)) { /* Active connection - skip to the next conn_t record */ cprev = connwalk; connwalk = connwalk->next; continue; } if (connwalk->action == C_CLEANUP) { if (connwalk->ctype == C_CLIENT) { /* * Finished getting data from a client, * flag idle and set next poll time. */ connwalk->client->busy = 0; set_polltime(connwalk->client); } else if (connwalk->ctype == C_SERVER) { /* Nothing needed for server cleanups */ } } /* Unlink the request from the list of active connections */ zombie = connwalk; if (cprev == NULL) { chead = zombie->next; connwalk = chead; cprev = NULL; } else { cprev->next = zombie->next; connwalk = zombie->next; } /* Purge the zombie */ dbgprintf("Request completed: req %lu, peer %s, action was %d, type was %d\n", zombie->seq, addrstring(&zombie->caddr), zombie->action, zombie->ctype); close(zombie->sockfd); freestrbuffer(zombie->msgbuf); xfree(zombie); } /* Set the tail pointer correctly */ ctail = chead; if (ctail) { while (ctail->next) ctail = ctail->next; } } if (dumpsessions) { /* Set by SIGUSR1 - dump the list of active requests */ dumpsessions = 0; for (connwalk = chead; (connwalk); connwalk = connwalk->next) { char *ctypestr, *actionstr; char timestr[30]; switch (connwalk->ctype) { case C_CLIENT: ctypestr = "client"; break; case C_SERVER: ctypestr = "server"; break; } switch (connwalk->action) { case C_READING: actionstr = "reading"; break; case C_WRITING: actionstr = "writing"; break; case C_CLEANUP: actionstr = "cleanup"; break; } strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&connwalk->tstamp)); errprintf("Request %lu: state %s/%s, peer %s, started %s (%lu secs ago)\n", connwalk->seq, ctypestr, actionstr, addrstring(&connwalk->caddr), timestr, (now - connwalk->tstamp)); } } now = time(NULL); if (now >= whentoqueue) { /* Scan host-tree for clients we need to contact */ for (handle = rbtBegin(clients); (handle != rbtEnd(clients)); handle = rbtNext(clients, handle)) { clients_t *clientwalk; char msgline[100]; strbuffer_t *request; char *pullstr, *ip; int port; clientwalk = (clients_t *)gettreeitem(clients, handle); if (clientwalk->busy) continue; if (clientwalk->nextpoll > now) continue; /* Deleted hosts stay in our tree - but should disappear from the known hosts */ hostwalk = hostinfo(clientwalk->hostname); if (!hostwalk) continue; pullstr = bbh_item(hostwalk, BBH_FLAG_PULLDATA); if (!pullstr) continue; ip = strchr(pullstr, '='); port = atoi(xgetenv("BBPORT")); if (!ip) { ip = strdup(bbh_item(hostwalk, BBH_IP)); } else { /* There is an explicit IP setting in the pulldata tag */ char *p; ip++; /* Skip the '=' */ ip = strdup(ip); p = strchr(ip, ':'); if (p) { *p = '\0'; port = atoi(p+1); } if (*ip == '\0') { /* No IP given, just a port number */ xfree(ip); ip = strdup(bbh_item(hostwalk, BBH_IP)); } } if (strcmp(ip, "0.0.0.0") == 0) { struct hostent *hent; xfree(ip); ip = NULL; hent = gethostbyname(clientwalk->hostname); if (hent) { struct in_addr addr; memcpy(&addr, *(hent->h_addr_list), sizeof(addr)); ip = strdup(inet_ntoa(addr)); } } if (!ip) continue; /* * Build the "pullclient" request, which includes the latest * clientdata config we got from the server. Keep the clientdata * here - we send "pullclient" requests more often that we actually * contact the server, but we should provide the config data always. */ request = newstrbuffer(0); sprintf(msgline, "pullclient %d\n", serverid); addtobuffer(request, msgline); if (clientwalk->clientdata) addtobuffer(request, clientwalk->clientdata); /* Put the request on the connection queue */ addrequest(C_CLIENT, ip, port, request, clientwalk); clientwalk->busy = 1; xfree(ip); } } /* Handle request queue */ FD_ZERO(&fdread); FD_ZERO(&fdwrite); maxfd = -1; for (connwalk = chead; (connwalk); connwalk = connwalk->next) { switch (connwalk->action) { case C_READING: FD_SET(connwalk->sockfd, &fdread); if (connwalk->sockfd > maxfd) maxfd = connwalk->sockfd; break; case C_WRITING: FD_SET(connwalk->sockfd, &fdwrite); if (connwalk->sockfd > maxfd) maxfd = connwalk->sockfd; break; case C_CLEANUP: break; } } /* Do select with a 1 second timeout */ tmo.tv_sec = 1; tmo.tv_usec = 0; n = select(maxfd+1, &fdread, &fdwrite, NULL, &tmo); if (n == -1) { if (errno == EINTR) continue; /* Interrupted, e.g. a SIGHUP */ /* This is a "cannot-happen" failure. Bail out */ errprintf("select failure: %s\n", strerror(errno)); return 0; } if (n == 0) continue; /* Timeout */ for (connwalk = chead; (connwalk); connwalk = connwalk->next) { switch (connwalk->action) { case C_READING: if (FD_ISSET(connwalk->sockfd, &fdread)) grabdata(connwalk); break; case C_WRITING: if (FD_ISSET(connwalk->sockfd, &fdwrite)) senddata(connwalk); break; case C_CLEANUP: break; } } } while (running); return 0; }
int main(int argc, char **argv) { pcre *hostptn, *exhostptn, *pageptn, *expageptn; void *hwalk; char *hostname, *pagename; hostptn = exhostptn = pageptn = expageptn = NULL; if (getenv("QUERY_STRING") == NULL) { /* Not invoked through the CGI */ if (argc < 4) { errprintf("Usage:\n%s HOSTNAME-PATTERN STARTTIME ENDTIME", argv[0]); return 1; } hostpattern = argv[1]; if (strncmp(hostpattern, "--page=", 7) == 0) { pagepattern = strchr(argv[1], '=') + 1; hostpattern = NULL; } starttimedate = argv[2]; starttimehm = "00:00:00"; endtimedate = argv[3]; endtimehm = "00:00:00"; if (argc > 4) { if (strncmp(argv[4], "--csv", 5) == 0) { char *p; outform = O_CSV; if ((p = strchr(argv[4], '=')) != NULL) csvdelim = *(p+1); } } } else { char *envarea = NULL; int argi; for (argi = 1; (argi < argc); argi++) { if (argnmatch(argv[argi], "--env=")) { char *p = strchr(argv[argi], '='); loadenv(p+1, envarea); } else if (argnmatch(argv[argi], "--area=")) { char *p = strchr(argv[argi], '='); envarea = strdup(p+1); } else if (strcmp(argv[argi], "--debug") == 0) { debug = 1; } } /* Parse CGI parameters */ parse_query(); format_rrdtime(starttime, &starttimedate, &starttimehm); format_rrdtime(endtime, &endtimedate, &endtimehm); switch (outform) { case O_XML: printf("Content-type: application/xml\n\n"); break; case O_CSV: printf("Content-type: text/csv\n\n"); break; case O_NONE: load_hostnames(xgetenv("HOSTSCFG"), NULL, get_fqdn()); printf("Content-type: %s\n\n", xgetenv("HTMLCONTENTTYPE")); showform(stdout, "perfdata", "perfdata_form", COL_BLUE, getcurrenttime(NULL), NULL, NULL); return 0; } } load_hostnames(xgetenv("HOSTSCFG"), NULL, get_fqdn()); if (hostpattern) hostptn = compileregex(hostpattern); if (exhostpattern) exhostptn = compileregex(exhostpattern); if (pagepattern) pageptn = compileregex(pagepattern); if (expagepattern) expageptn = compileregex(expagepattern); switch (outform) { case O_XML: printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n"); printf("<datasets>\n"); break; default: break; } dbgprintf("Got hosts, it is %s\n", (first_host() == NULL) ? "empty" : "not empty"); for (hwalk = first_host(); (hwalk); hwalk = next_host(hwalk, 0)) { hostname = xmh_item(hwalk, XMH_HOSTNAME); pagename = xmh_item(hwalk, XMH_PAGEPATH); dbgprintf("Processing host %s\n", hostname); if (hostpattern && !matchregex(hostname, hostptn)) continue; if (exhostpattern && matchregex(hostname, exhostptn)) continue; if (pagepattern && !matchregex(pagename, pageptn)) continue; if (expagepattern && matchregex(pagename, expageptn)) continue; onehost(hostname, starttime, endtime); } switch (outform) { case O_XML: printf("</datasets>\n"); break; default: break; } return 0; }