int main(int argc, char *argv[]) { int ch; while ((ch = getopt(argc, argv, "al")) != -1) switch (ch) { case 'a': allopt++; break; case 'l': longopt++; break; default: usage(); /* NOTREACHED */ } setlinebuf(stdout); if (argc == optind) allhosts(); else { for (; optind < argc; optind++) onehost(argv[optind]); } exit(0); }
int main(int argc, char *argv[]) { int ch, retval; retval = 0; while ((ch = getopt(argc, argv, "")) != -1) switch (ch) { default: usage(); /*NOTREACHED*/ } setlinebuf(stdout); if (argc == optind) allhosts(); else { for (; optind < argc; optind++) retval += onehost(argv[optind]); } exit(retval ? 1 : 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; }