static void zvse_paging_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *pagingstr) { char *p; int ipagerate, pagingyellow, pagingred; float fpagerate=0.0; char pagingresult[100]; int pagingcolor = COL_GREEN; char msgline[4096]; strbuffer_t *upmsg; if (!pagingstr) return; /* * Looking for Paging rate in message * Page Rate=0.00 /sec */ *pagingresult = '\0'; ipagerate=0; p = strstr(pagingstr, "Page Rate=") + 10; if (p) { if (sscanf(p, "%f", &fpagerate) == 1) { ipagerate=fpagerate + 0.5; /* Rounding up */ sprintf(pagingresult, "z/VSE Paging Rate %d per second\n", ipagerate); } } else sprintf(pagingresult, "Can not find page rate value in:\n%s\n", pagingstr); get_paging_thresholds(hinfo, clientclass, &pagingyellow, &pagingred); upmsg = newstrbuffer(0); if (ipagerate > pagingred) { pagingcolor = COL_RED; addtobuffer(upmsg, "&red Paging Rate is CRITICAL\n"); } else if (ipagerate > pagingyellow) { pagingcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Paging Rate is HIGH\n"); } init_status(pagingcolor); sprintf(msgline, "status %s.paging %s %s %s %s\n", commafy(hostname), colorname(pagingcolor), (timestr ? timestr : "<no timestamp data>"), pagingresult, pagingstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
static void zvm_paging_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *cpuutilstr) { char *p; int pagerate, pagingyellow, pagingred; char pagingresult[100]; int pagingcolor = COL_GREEN; char msgline[256]; strbuffer_t *upmsg; if (!cpuutilstr) return; /* * Looking for Paging rate info in 'IND' command response * PAGING-0000/SEC */ *pagingresult = '\0'; /* Skip past three newlines in message to the PAGING text */ p=strstr(cpuutilstr,"PAGING-") + 7; if (sscanf(p, "%d/SEC", &pagerate) == 1) { sprintf(pagingresult, "z/VM Paging Rate %d per second\n", pagerate); } get_paging_thresholds(hinfo, clientclass, &pagingyellow, &pagingred); upmsg = newstrbuffer(0); if (pagerate > pagingred) { pagingcolor = COL_RED; addtobuffer(upmsg, "&red Paging Rate is CRITICAL\n"); } else if (pagerate > pagingyellow) { pagingcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Paging Rate is HIGH\n"); } init_status(pagingcolor); sprintf(msgline, "status %s.paging %s %s %s %s\n", commafy(hostname), colorname(pagingcolor), (timestr ? timestr : "<no timestamp data>"), pagingresult, cpuutilstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
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; }
static void zvm_users_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *psstr) { int pscolor = COL_GREEN; int pchecks; int cmdofs = -1; char msgline[4096]; strbuffer_t *monmsg; static strbuffer_t *countdata = NULL; int anycountdata = 0; char *group; if (!want_msgtype(hinfo, MSG_PROCS)) return; if (!psstr) return; if (!countdata) countdata = newstrbuffer(0); clearalertgroups(); monmsg = newstrbuffer(0); sprintf(msgline, "data %s.proccounts\n", commafy(hostname)); addtobuffer(countdata, msgline); cmdofs = 0; /* Command offset for z/VM isn't necessary */ pchecks = clear_process_counts(hinfo, clientclass); if (pchecks == 0) { /* Nothing to check */ sprintf(msgline, "&%s No process checks defined\n", colorname(noreportcolor)); addtobuffer(monmsg, msgline); pscolor = noreportcolor; } else if (cmdofs >= 0) { /* Count how many instances of each monitored process is running */ char *pname, *pid, *bol, *nl; int pcount, pmin, pmax, pcolor, ptrack; bol = psstr; while (bol) { nl = strchr(bol, '\n'); /* Take care - the ps output line may be shorter than what we look at */ if (nl) { *nl = '\0'; if ((nl-bol) > cmdofs) add_process_count(bol+cmdofs); *nl = '\n'; bol = nl+1; } else { if (strlen(bol) > cmdofs) add_process_count(bol+cmdofs); bol = NULL; } } /* Check the number found for each monitored process */ while ((pname = check_process_count(&pcount, &pmin, &pmax, &pcolor, &pid, &ptrack, &group)) != NULL) { char limtxt[1024]; if (pmax == -1) { if (pmin > 0) sprintf(limtxt, "%d or more", pmin); else if (pmin == 0) sprintf(limtxt, "none"); } else { if (pmin > 0) sprintf(limtxt, "between %d and %d", pmin, pmax); else if (pmin == 0) sprintf(limtxt, "at most %d", pmax); } if (pcolor == COL_GREEN) { sprintf(msgline, "&green %s (found %d, req. %s)\n", pname, pcount, limtxt); addtobuffer(monmsg, msgline); } else { if (pcolor > pscolor) pscolor = pcolor; sprintf(msgline, "&%s %s (found %d, req. %s)\n", colorname(pcolor), pname, pcount, limtxt); addtobuffer(monmsg, msgline); addalertgroup(group); } if (ptrack) { /* Save the count data for later DATA message to track process counts */ if (!pid) pid = "default"; sprintf(msgline, "%s:%u\n", pid, pcount); addtobuffer(countdata, msgline); anycountdata = 1; } } } else { pscolor = COL_YELLOW; sprintf(msgline, "&yellow Expected string not found in ps output header\n"); addtobuffer(monmsg, msgline); } /* Now we know the result, so generate a status message */ init_status(pscolor); group = getalertgroups(); if (group) sprintf(msgline, "status/group:%s ", group); else strcpy(msgline, "status "); addtostatus(msgline); sprintf(msgline, "%s.procs %s %s - Processes %s\n", commafy(hostname), colorname(pscolor), (timestr ? timestr : "<No timestamp data>"), ((pscolor == COL_GREEN) ? "OK" : "NOT ok")); addtostatus(msgline); /* And add the info about what's wrong */ if (STRBUFLEN(monmsg)) { addtostrstatus(monmsg); addtostatus("\n"); } /* And the full virtual machine names output for those who want it */ if (pslistinprocs) { /* * Format the list of virtual machines into four per line, * this list could be fairly long. */ char *tmpstr, *tok, *nm[4]; int nmidx = 0; /* Make a copy of psstr, strtok() will be changing it */ tmpstr = strdup(psstr); /* Use strtok() to split string into pieces delimited by newline */ tok = strtok(tmpstr, "\n"); while (tok) { nm[nmidx++] = tok; if (nmidx == 4) { sprintf(msgline, "%-8s %-8s %-8s %-8s\n", nm[0], nm[1], nm[2], nm[3]); addtostatus(msgline); nmidx = 0; nm[0] = nm[1] = nm[2] = nm[3] = " "; } tok = strtok(NULL, "\n"); } /* Print any remaining names */ if (nmidx > 0) { sprintf(msgline, "%-8s %-8s %-8s %-8s\n", nm[0], nm[1], nm[2], nm[3]); addtostatus(msgline); } free(tmpstr); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(monmsg); if (anycountdata) sendmessage(STRBUF(countdata), NULL, BBTALK_TIMEOUT, NULL); clearstrbuffer(countdata); }
static void zvm_cpu_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *cpuutilstr, char *uptimestr) { char *p; float load1, loadyellow, loadred; int recentlimit, ancientlimit, maxclockdiff; int uphour, upmin; char loadresult[100]; char myupstr[100]; long uptimesecs = -1; long upday; int cpucolor = COL_GREEN; char msgline[1024]; strbuffer_t *upmsg; if (!want_msgtype(hinfo, MSG_CPU)) return; if (!cpuutilstr) return; if (!uptimestr) return; uptimesecs = 0; /* * z/VM: "Uptime: 1 Days, 13 Hours, 38 Minutes" */ sscanf(uptimestr,"Uptime: %ld Days, %d Hours, %d Minutes", &upday, &uphour, &upmin); uptimesecs = upday * 86400; uptimesecs += 60*(60*uphour + upmin); sprintf(myupstr, "%s\n", uptimestr); /* * Looking for average CPU Utilization in 'IND' command response * AVGPROC-000% */ *loadresult = '\0'; p = strstr(cpuutilstr, "AVGPROC-") + 8 ; if (p) { if (sscanf(p, "%f%%", &load1) == 1) { sprintf(loadresult, "z/VM CPU Utilization %3.0f%%\n", load1); } } get_cpu_thresholds(hinfo, clientclass, &loadyellow, &loadred, &recentlimit, &ancientlimit, &maxclockdiff); upmsg = newstrbuffer(0); if (load1 > loadred) { cpucolor = COL_RED; addtobuffer(upmsg, "&red Load is CRITICAL\n"); } else if (load1 > loadyellow) { cpucolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Load is HIGH\n"); } if ((uptimesecs != -1) && (recentlimit != -1) && (uptimesecs < recentlimit)) { if (cpucolor == COL_GREEN) cpucolor = COL_YELLOW; addtobuffer(upmsg, "&yellow Machine recently rebooted\n"); } if ((uptimesecs != -1) && (ancientlimit != -1) && (uptimesecs > ancientlimit)) { if (cpucolor == COL_GREEN) cpucolor = COL_YELLOW; sprintf(msgline, "&yellow Machine has been up more than %d days\n", (ancientlimit / 86400)); addtobuffer(upmsg, msgline); } init_status(cpucolor); sprintf(msgline, "status %s.cpu %s %s %s %s %s\n", commafy(hostname), colorname(cpucolor), (timestr ? timestr : "<no timestamp data>"), loadresult, myupstr, cpuutilstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
void send_http_results(service_t *httptest, testedhost_t *host, testitem_t *firsttest, char *nonetpage, int failgoesclear) { testitem_t *t; int color = -1; char *svcname; strbuffer_t *msgtext; char *nopagename; int nopage = 0; int anydown = 0, totalreports = 0; if (firsttest == NULL) return; svcname = strdup(httptest->testname); if (httptest->namelen) svcname[httptest->namelen] = '\0'; /* Check if this service is a NOPAGENET service. */ nopagename = (char *) malloc(strlen(svcname)+3); sprintf(nopagename, ",%s,", svcname); nopage = (strstr(nonetpage, svcname) != NULL); xfree(nopagename); dbgprintf("Calc http color host %s : ", host->hostname); msgtext = newstrbuffer(0); for (t=firsttest; (t && (t->host == host)); t = t->next) { http_data_t *req = (http_data_t *) t->privdata; /* Skip the data-reports for now */ if (t->senddata) continue; /* Grab session cookies */ update_session_cookies(host->hostname, req->bburl.desturl->host, req->headers); totalreports++; if (req->bburl.okcodes || req->bburl.badcodes) { req->httpcolor = statuscolor_by_set(host, req->httpstatus, req->bburl.okcodes, req->bburl.badcodes); } else { req->httpcolor = statuscolor(host, req->httpstatus); } if (req->httpcolor == COL_RED) anydown++; /* Dialup hosts and dialup tests report red as clear */ if ((req->httpcolor != COL_GREEN) && (host->dialup || t->dialup)) req->httpcolor = COL_CLEAR; /* If ping failed, report CLEAR unless alwaystrue */ if ( ((req->httpcolor == COL_RED) || (req->httpcolor == COL_YELLOW)) && /* Test failed */ (host->downcount > 0) && /* The ping check did fail */ (!host->noping && !host->noconn) && /* We are doing a ping test */ (failgoesclear) && (!t->alwaystrue) ) /* No "~testname" flag */ { req->httpcolor = COL_CLEAR; } /* If test we depend on has failed, report CLEAR unless alwaystrue */ if ( ((req->httpcolor == COL_RED) || (req->httpcolor == COL_YELLOW)) && /* Test failed */ failgoesclear && !t->alwaystrue ) /* No "~testname" flag */ { char *faileddeps = deptest_failed(host, t->service->testname); if (faileddeps) { req->httpcolor = COL_CLEAR; req->faileddeps = strdup(faileddeps); } } dbgprintf("%s(%s) ", t->testspec, colorname(req->httpcolor)); if (req->httpcolor > color) color = req->httpcolor; /* Build the short msgtext which goes on line 1 of the status message. */ addtobuffer(msgtext, (STRBUFLEN(msgtext) ? " ; " : ": ") ); if (req->tcptest->errcode != CONTEST_ENOERROR) { switch (req->tcptest->errcode) { case CONTEST_ETIMEOUT: req->errorcause = "Server timeout"; break; case CONTEST_ENOCONN : req->errorcause = strdup(strerror(req->tcptest->connres)); break; case CONTEST_EDNS : switch (req->parsestatus) { case 1 : req->errorcause = "Invalid URL"; break; case 2 : req->errorcause = "Hostname not in DNS"; break; default: req->errorcause = "DNS error"; break; } break; case CONTEST_EIO : req->errorcause = "I/O error"; break; case CONTEST_ESSL : req->errorcause = "SSL error"; break; default: req->errorcause = "Xfer failed"; } addtobuffer(msgtext, req->errorcause); } else if (req->tcptest->open == 0) { req->errorcause = "Connect failed"; addtobuffer(msgtext, req->errorcause); } else if ((req->httpcolor == COL_RED) || (req->httpcolor == COL_YELLOW)) { char m1[100]; if (req->bburl.okcodes || req->bburl.badcodes) { sprintf(m1, "Unwanted HTTP status %ld", req->httpstatus); } else if (req->headers) { char *p = req->headers; /* Skip past "HTTP/1.x 200 " and pick up the explanatory text, if any */ if (strncasecmp(p, "http/", 5) == 0) { p += 5; p += strspn(p, "0123456789. "); } strncpy(m1, p, sizeof(m1)-1); m1[sizeof(m1)-1] = '\0'; /* Only show the first line of the HTTP status description */ p = strchr(m1, '\n'); if (p) *p = '\0'; } else { sprintf(m1, "HTTP error %ld", req->httpstatus); } addtobuffer(msgtext, m1); req->errorcause = strdup(m1); } else { addtobuffer(msgtext, "OK"); if (req->bburl.okcodes || req->bburl.badcodes) { char m1[100]; sprintf(m1, " (HTTP status %ld)", req->httpstatus); addtobuffer(msgtext, m1); } } } /* It could be that we have 0 http tests - if we only do the apache one */ if (totalreports > 0) { char msgline[4096]; if (anydown) { firsttest->downcount++; if(firsttest->downcount == 1) firsttest->downstart = getcurrenttime(NULL); } else firsttest->downcount = 0; /* Handle the "badtest" stuff for http tests */ if ((color == COL_RED) && (firsttest->downcount < firsttest->badtest[2])) { if (firsttest->downcount >= firsttest->badtest[1]) color = COL_YELLOW; else if (firsttest->downcount >= firsttest->badtest[0]) color = COL_CLEAR; else color = COL_GREEN; } if (nopage && (color == COL_RED)) color = COL_YELLOW; dbgprintf(" --> %s\n", colorname(color)); /* Send off the http status report */ init_status(color); sprintf(msgline, "status+%d %s.%s %s %s", validity, commafy(host->hostname), svcname, colorname(color), timestamp); addtostatus(msgline); addtostrstatus(msgtext); addtostatus("\n"); for (t=firsttest; (t && (t->host == host)); t = t->next) { char *urlmsg; http_data_t *req = (http_data_t *) t->privdata; /* Skip the "data" reports */ if (t->senddata) continue; urlmsg = (char *)malloc(1024 + strlen(req->url)); sprintf(urlmsg, "\n&%s %s - ", colorname(req->httpcolor), req->url); addtostatus(urlmsg); if (req->httpcolor == COL_GREEN) addtostatus("OK"); else { if (req->errorcause) addtostatus(req->errorcause); else addtostatus("failed"); } if (req->bburl.okcodes || req->bburl.badcodes) { char m1[100]; sprintf(m1, " (HTTP status %ld)", req->httpstatus); addtostatus(m1); } addtostatus("\n"); if (req->headers) { addtostatus("\n"); addtostatus(req->headers); } if (req->faileddeps) addtostatus(req->faileddeps); sprintf(urlmsg, "\nSeconds: %5d.%02d\n\n", (unsigned int)req->tcptest->totaltime.tv_sec, (unsigned int)req->tcptest->totaltime.tv_nsec / 10000000 ); addtostatus(urlmsg); xfree(urlmsg); } addtostatus("\n\n"); finish_status(); } /* Send of any HTTP status tests in separate columns */ for (t=firsttest; (t && (t->host == host)); t = t->next) { int color; char msgline[4096]; char *urlmsg; http_data_t *req = (http_data_t *) t->privdata; if ((t->senddata) || (!req->bburl.columnname) || (req->contentcheck != CONTENTCHECK_NONE)) continue; /* Handle the "badtest" stuff */ color = req->httpcolor; if ((color == COL_RED) && (t->downcount < t->badtest[2])) { if (t->downcount >= t->badtest[1]) color = COL_YELLOW; else if (t->downcount >= t->badtest[0]) color = COL_CLEAR; else color = COL_GREEN; } if (nopage && (color == COL_RED)) color = COL_YELLOW; /* Send off the http status report */ init_status(color); sprintf(msgline, "status+%d %s.%s %s %s", validity, commafy(host->hostname), req->bburl.columnname, colorname(color), timestamp); addtostatus(msgline); addtostatus(" : "); addtostatus(req->errorcause ? req->errorcause : "OK"); if (req->bburl.okcodes || req->bburl.badcodes) { char m1[100]; sprintf(m1, " (HTTP status %ld)", req->httpstatus); addtostatus(m1); } addtostatus("\n"); urlmsg = (char *)malloc(1024 + strlen(req->url)); sprintf(urlmsg, "\n&%s %s - ", colorname(req->httpcolor), req->url); addtostatus(urlmsg); xfree(urlmsg); if (req->httpcolor == COL_GREEN) addtostatus("OK"); else { if (req->errorcause) addtostatus(req->errorcause); else addtostatus("failed"); } addtostatus("\n"); if (req->headers) { addtostatus("\n"); addtostatus(req->headers); } if (req->faileddeps) addtostatus(req->faileddeps); sprintf(msgline, "\nSeconds: %5d.%02d\n\n", (unsigned int)req->tcptest->totaltime.tv_sec, (unsigned int)req->tcptest->totaltime.tv_nsec / 10000000 ); addtostatus(msgline); addtostatus("\n\n"); finish_status(); } /* Send off any "data" messages now */ for (t=firsttest; (t && (t->host == host)); t = t->next) { http_data_t *req; char *data = ""; char *msg; if (!t->senddata) continue; req = (http_data_t *) t->privdata; if (req->output) data = req->output; msg = (char *)malloc(1024 + strlen(host->hostname) + strlen(req->bburl.columnname) + strlen(data)); sprintf(msg, "data %s.%s\n%s", commafy(host->hostname), req->bburl.columnname, data); sendmessage(msg, NULL, BBTALK_TIMEOUT, NULL); xfree(msg); } xfree(svcname); freestrbuffer(msgtext); }
void zvse_nparts_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *npartstr) { char npdispstr[256]; long nparts, runparts, partsavail; int npartsyellow, npartsred; float partutil; int npartcolor = COL_GREEN; char msgline[4096]; strbuffer_t *upmsg; if (!npartstr) return; sscanf(npartstr, "%ld %ld", &nparts, &runparts); /* * The nparts message is two values that indicate the maximum number of partitions * configured in the system (based on the NPARTS value in the IPL proc) and * the number of partitions currently running jobs: * The format of the data is: * * nnnnnnn mmmmmmm * */ partsavail = nparts - runparts; partutil = ((float)runparts / (float)nparts) * 100; get_asid_thresholds(hinfo, clientclass, &npartsyellow, &npartsred); upmsg = newstrbuffer(0); if ((int)partutil > npartsred) { if (npartcolor < COL_RED) npartcolor = COL_RED; addtobuffer(upmsg, "&red NPARTS Utilization is CRITICAL\n"); } else if ((int)partutil > npartsyellow) { if (npartcolor < COL_YELLOW) npartcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow NPARTS Utilization is HIGH\n"); } *npdispstr = '\0'; sprintf(npdispstr, "Nparts: %8ld Free: %8ld Used: %8ld %3.1f\n",nparts,partsavail,runparts,partutil); init_status(npartcolor); sprintf(msgline, "status %s.nparts %s %s\n%s", commafy(hostname), colorname(npartcolor), (timestr ? timestr : "<no timestamp data>"), npdispstr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
static void zvse_getvis_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *gvstr) { char *q; int gv24yel, gv24red, gvanyyel, gvanyred; /* Thresholds for getvis */ int getvisok=1; float used24p, usedanyp; char jinfo[11], pid[4], jobname[9]; int size24, used24, free24, sizeany, usedany, freeany; char *getvisentry = NULL; char tempresult[128]; char getvisresult[128]; char msgline[4096]; int memorycolor = COL_GREEN; char getvisokmsg[]="Getvis OK"; char getvisnotokmsg[]="Getvis Not OK"; strbuffer_t *getvismsg; strbuffer_t *upmsg; strbuffer_t *headline; if (!gvstr) return; getvismsg = newstrbuffer(0); upmsg = newstrbuffer(0); headline = newstrbuffer(0); /* * The getvis message is a table if the partitions requested including the SVA. * The format of the table is: * * Partition Used/24 Free/24 Used/Any Free/Any * SVA 748 1500 2056 5604 * F1 824 264 824 264 * Z1-CICSICCF 7160 3844 27516 4992 * O1-CICS1 5912 5092 31584 19352 */ addtobuffer(headline, "z/VSE Getvis Map\nPID Jobname Size24 Used24 Free24 SizeAny UsedAny FreeAny Used24% UsedAny%\n"); getvisentry=strtok(gvstr, "\n"); getvisentry=strtok(NULL, "\n"); /* Skip heading line */ while (getvisentry != NULL) { sscanf(getvisentry, "%s %d %d %d %d", jinfo, &used24, &free24, &usedany, &freeany); q = strchr(jinfo, '-'); /* Check if jobname passed */ if (q) { strncpy(pid, jinfo, 2); /* Copy partition ID */ q++; /* Increment pointer */ strcpy(jobname,q); /* Copy jobname */ } else { strcpy(pid,jinfo); /* Just copy jinfo into partition ID */ strcpy(jobname, "- "); /* Jobname placeholder */ } size24 = used24 + free24; sizeany = usedany + freeany; used24p = ( (float)used24 / (float)size24 ) * 100; usedanyp = ( (float)usedany / (float)sizeany ) * 100; sprintf(getvisresult,"%-3s %-8s %6d %6d %6d %6d %6d %6d %3.0f %3.0f\n", pid, jobname, size24, used24, free24, sizeany, usedany, freeany, used24p, usedanyp); get_zvsegetvis_thresholds(hinfo, clientclass, pid, &gv24yel, &gv24red, &gvanyyel, &gvanyred); if (used24p > (float)gv24red) { memorycolor = COL_RED; getvisok=0; sprintf(tempresult,"&red 24-bit Getvis utilization for %s is CRITICAL\n", pid); addtobuffer(upmsg, tempresult); } else if (used24p > (float)gv24yel) { memorycolor = COL_YELLOW; getvisok=0; sprintf(tempresult,"&yellow 24-bit Getvis utilization for %s is HIGH\n", pid); addtobuffer(upmsg, tempresult); } if (usedanyp > (float)gvanyred) { memorycolor = COL_RED; getvisok=0; sprintf(tempresult,"&red Any Getvis utilization for %s is CRITICAL\n", pid); addtobuffer(upmsg, tempresult); } else if (usedanyp > (float)gvanyyel) { memorycolor = COL_YELLOW; getvisok=0; sprintf(tempresult,"&yellow Any Getvis utilization for %s is HIGH\n", pid); addtobuffer(upmsg, tempresult); } addtobuffer(getvismsg, getvisresult); getvisentry=strtok(NULL, "\n"); } init_status(memorycolor); sprintf(msgline, "status %s.getvis %s %s %s\n", commafy(hostname), colorname(memorycolor), (timestr ? timestr : "<no timestamp data>"), ( (getvisok==1) ? getvisokmsg : getvisnotokmsg ) ); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (STRBUFLEN(getvismsg)) { addtostrstatus(headline); addtostrstatus(getvismsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(headline); freestrbuffer(upmsg); freestrbuffer(getvismsg); }
static void zvse_memory_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *memstr) { int usedyellow, usedred; /* Thresholds for total used system memory */ int sysmemok=1; long totmem, availmem; float pctavail, pctused; char memorystr[1024]; int memorycolor = COL_GREEN; char memokmsg[]="Memory OK"; char memnotokmsg[]="Memory Not OK"; char msgline[4096]; strbuffer_t *upmsg; if (!memstr) return; upmsg = newstrbuffer(0); /* * The message is just two values, the total system memory and * the available memory; both values are in K. * tttttt aaaaaa */ sscanf(memstr, "%ld %ld", &totmem, &availmem); pctavail = ((float)availmem / (float)totmem) * 100; pctused = 100 - pctavail; sprintf(memorystr, "z/VSE VSIZE Utilization %3.1f%%\nMemory Allocated %ldK, Memory Available %ldK\n", pctused, totmem, availmem); get_zvsevsize_thresholds(hinfo, clientclass, &usedyellow, &usedred); if (pctused > (float)usedred) { memorycolor = COL_RED; sysmemok=0; addtobuffer(upmsg, "&red VSIZE Utilization is CRITICAL\n"); } else if (pctused > (float)usedyellow) { memorycolor = COL_YELLOW; sysmemok=0; addtobuffer(upmsg, "&yellow VSIZE Utilization is HIGH\n"); } init_status(memorycolor); sprintf(msgline, "status %s.memory %s %s %s\n%s", commafy(hostname), colorname(memorycolor), (timestr ? timestr : "<no timestamp data>"), ( (sysmemok==1) ? memokmsg : memnotokmsg ), memorystr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
static void zvse_cics_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *cicsstr) { char cicsappl[9], cicsdate[11], cicstime[9]; int numtrans=0, cicsok=1; float dsapct=0.0; float edsapct=0.0; char cicsresult[100]; char tempresult[100]; char *cicsentry = NULL; int cicscolor = COL_GREEN; int dsayel, dsared, edsayel, edsared; char msgline[4096]; char cicsokmsg[]="All CICS Systems OK"; char cicsnotokmsg[]="One or more CICS Systems not OK"; strbuffer_t *headline; strbuffer_t *upmsg; strbuffer_t *cicsmsg; if (!cicsstr) return; cicsmsg = newstrbuffer(0); upmsg = newstrbuffer(0); headline= newstrbuffer(0); addtobuffer(headline, "Appl ID Trans DSA Pct EDSA Pct\n"); /* * * Each CICS system reporting uses one line in the message, the format is: * applid date time numtrans dsapct edsapct * applid is the CICS application id * date and time are the date and time of the report * numtrans is the number of transactions that were executed in CICS since the last report * dsapct is the DSA utilization percentage * edsapct is the EDSA utilization percentage * */ if (cicsstr) { cicsentry=strtok(cicsstr, "\n"); while (cicsentry != NULL) { sscanf(cicsentry, "%8s %10s %8s %d %f %f", cicsappl, cicsdate, cicstime, &numtrans, &dsapct, &edsapct); sprintf(cicsresult,"%-8s %6d %3.1f %3.1f\n", cicsappl, numtrans, dsapct, edsapct); addtobuffer(cicsmsg, cicsresult); if (numtrans == -1 ) { if (cicscolor < COL_YELLOW) cicscolor = COL_YELLOW; cicsok=0; sprintf(tempresult,"&yellow CICS system %s not responding, removed\n", cicsappl); addtobuffer(upmsg, tempresult); } /* Get CICS thresholds for this application ID. */ get_cics_thresholds(hinfo, clientclass, cicsappl, &dsayel, &dsared, &edsayel, &edsared); /* The threshold of the DSA values for each CICS must be checked in this loop. */ if (dsapct > dsared) { if (cicscolor < COL_RED) cicscolor = COL_RED; cicsok=0; sprintf(tempresult,"&red %s DSA Utilization is CRITICAL\n", cicsappl); addtobuffer(upmsg, tempresult); } else if (dsapct > dsayel) { if (cicscolor < COL_YELLOW) cicscolor = COL_YELLOW; cicsok=0; sprintf(tempresult,"&yellow %s DSA Utilization is HIGH\n", cicsappl); addtobuffer(upmsg, tempresult); } if (edsapct > edsared) { if (cicscolor < COL_RED) cicscolor = COL_RED; cicsok=0; sprintf(tempresult,"&red %s EDSA Utilization is CRITICAL\n", cicsappl); addtobuffer(upmsg, tempresult); } else if (edsapct > edsayel) { if (cicscolor < COL_YELLOW) cicscolor = COL_YELLOW; cicsok=0; sprintf(tempresult,"&yellow %s EDSA Utilization is HIGH\n", cicsappl); addtobuffer(upmsg, tempresult); } init_status(cicscolor); cicsentry=strtok(NULL, "\n"); } } sprintf(msgline, "status %s.cics %s %s %s\n", commafy(hostname), colorname(cicscolor), (timestr ? timestr : "<no timestamp data>"), ( (cicsok==1) ? cicsokmsg : cicsnotokmsg) ); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); } if (STRBUFLEN(cicsmsg)) { addtostrstatus(headline); addtostrstatus(cicsmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(headline); freestrbuffer(upmsg); freestrbuffer(cicsmsg); }
void zos_maxuser_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *maxuserstr) { char *p; char maxustr[256]; long maxusers, maxufree, maxuused, rsvtstrt, rsvtfree, rsvtused, rsvnonr, rsvnfree, rsvnused; int maxyellow, maxred; float maxutil, rsvtutil, rsvnutil; int maxcolor = COL_GREEN; char msgline[4096]; strbuffer_t *upmsg; if (!maxuserstr) return; /* * Looking for eyecatchers in message */ p = strstr(maxuserstr, "Maxusers: ") + 9; if (p) { sscanf(p, "%ld Free: %ld", &maxusers, &maxufree); } p = strstr(maxuserstr, "RSVTSTRT: ") + 9; if (p) { sscanf(p, "%ld Free: %ld", &rsvtstrt, &rsvtfree); } p = strstr(maxuserstr, "RSVNONR: ") + 8; if (p) { sscanf(p, "%ld Free: %ld", &rsvnonr, &rsvnfree); } maxuused = maxusers - maxufree; rsvtused = rsvtstrt - rsvtfree; rsvnused = rsvnonr - rsvnfree; if ( maxuused == 0.0 ) maxutil = 0; else maxutil = ((float)maxuused / (float)maxusers) * 100; if ( rsvtused == 0.0 ) rsvtutil = 0; else rsvtutil = ((float)rsvtused / (float)rsvtstrt) * 100; if ( rsvnused == 0.0 ) rsvnutil = 0; else rsvnutil = ((float)rsvnused / (float)rsvnonr) * 100; get_asid_thresholds(hinfo, clientclass, &maxyellow, &maxred); upmsg = newstrbuffer(0); if ((int)maxutil > maxred) { if (maxcolor < COL_RED) maxcolor = COL_RED; addtobuffer(upmsg, "&red ASID (Maxuser) Utilization is CRITICAL\n"); } else if ((int)maxutil > maxyellow) { if (maxcolor < COL_YELLOW) maxcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow ASID (Maxuser) Utilization is HIGH\n"); } *maxustr = '\0'; sprintf(maxustr, " Maxuser: %8ld Free: %8ld Used: %8ld %3.1f\nRSVTSTRT: %8ld Free: %8ld Used: %8ld %3.1f\n RSVNONR: %8ld Free: %8ld Used: %8ld %3.1f\n",maxusers,maxufree,maxuused,maxutil,rsvtstrt,rsvtfree,rsvtused,rsvtutil,rsvnonr,rsvnfree,rsvnused,rsvnutil); init_status(maxcolor); sprintf(msgline, "status %s.maxuser %s %s\n%s", commafy(hostname), colorname(maxcolor), (timestr ? timestr : "<no timestamp data>"), maxustr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }
void zos_memory_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *memstr) { char *p; char headstr[100], csastr[100], ecsastr[100], sqastr[100], esqastr[100]; long csaalloc, csaused, csahwm, ecsaalloc, ecsaused, ecsahwm; long sqaalloc, sqaused, sqahwm, esqaalloc, esqaused, esqahwm; float csautil, ecsautil, sqautil, esqautil; int csayellow, csared, ecsayellow, ecsared, sqayellow, sqared, esqayellow, esqared; int memcolor = COL_GREEN; char msgline[4096]; strbuffer_t *upmsg; if (!memstr) return; /* * Looking for memory eyecatchers in message */ p = strstr(memstr, "CSA ") + 4; if (p) { sscanf(p, "%ld %ld %ld", &csaalloc, &csaused, &csahwm); } p = strstr(memstr, "ECSA ") + 5; if (p) { sscanf(p, "%ld %ld %ld", &ecsaalloc, &ecsaused, &ecsahwm); } p = strstr(memstr, "SQA ") + 4; if (p) { sscanf(p, "%ld %ld %ld", &sqaalloc, &sqaused, &sqahwm); } p = strstr(memstr, "ESQA ") + 5; if (p) { sscanf(p, "%ld %ld %ld", &esqaalloc, &esqaused, &esqahwm); } csautil = ((float)csaused / (float)csaalloc) * 100; ecsautil = ((float)ecsaused / (float)ecsaalloc) * 100; sqautil = ((float)sqaused / (float)sqaalloc) * 100; esqautil = ((float)esqaused / (float)esqaalloc) * 100; get_zos_memory_thresholds(hinfo, clientclass, &csayellow, &csared, &ecsayellow, &ecsared, &sqayellow, &sqared, &esqayellow, &esqared); upmsg = newstrbuffer(0); if (csautil > csared) { if (memcolor < COL_RED) memcolor = COL_RED; addtobuffer(upmsg, "&red CSA Utilization is CRITICAL\n"); } else if (csautil > csayellow) { if (memcolor < COL_YELLOW) memcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow CSA Utilization is HIGH\n"); } if (ecsautil > ecsared) { if (memcolor < COL_RED) memcolor = COL_RED; addtobuffer(upmsg, "&red ECSA Utilization is CRITICAL\n"); } else if (ecsautil > ecsayellow) { if (memcolor < COL_YELLOW) memcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow ECSA Utilization is HIGH\n"); } if (sqautil > sqared) { if (memcolor < COL_RED) memcolor = COL_RED; addtobuffer(upmsg, "&red SQA Utilization is CRITICAL\n"); } else if (sqautil > sqayellow) { if (memcolor < COL_YELLOW) memcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow SQA Utilization is HIGH\n"); } if (esqautil > esqared) { if (memcolor < COL_RED) memcolor = COL_RED; addtobuffer(upmsg, "&red ESQA Utilization is CRITICAL\n"); } else if (esqautil > esqayellow) { if (memcolor < COL_YELLOW) memcolor = COL_YELLOW; addtobuffer(upmsg, "&yellow ESQA Utilization is HIGH\n"); } *headstr = '\0'; *csastr = '\0'; *ecsastr = '\0'; *sqastr = '\0'; *esqastr = '\0'; strcpy(headstr, "z/OS Memory Map\n Area Alloc Used HWM Util%\n"); sprintf(csastr, "CSA %8ld %8ld %8ld %3.1f\n", csaalloc, csaused, csahwm, csautil); sprintf(ecsastr, "ECSA %8ld %8ld %8ld %3.1f\n", ecsaalloc, ecsaused, ecsahwm, ecsautil); sprintf(sqastr, "SQA %8ld %8ld %8ld %3.1f\n", sqaalloc, sqaused, sqahwm, sqautil); sprintf(esqastr, "ESQA %8ld %8ld %8ld %3.1f\n", esqaalloc, esqaused, esqahwm, esqautil); init_status(memcolor); sprintf(msgline, "status %s.memory %s %s\n%s %s %s %s %s", commafy(hostname), colorname(memcolor), (timestr ? timestr : "<no timestamp data>"), headstr, csastr, ecsastr, sqastr, esqastr); addtostatus(msgline); if (STRBUFLEN(upmsg)) { addtostrstatus(upmsg); addtostatus("\n"); } if (fromline && !localmode) addtostatus(fromline); finish_status(); freestrbuffer(upmsg); }