static void zvm_mdc_report(char *hostname, char *clientclass, enum ostype_t os, void *hinfo, char *fromline, char *timestr, char *cpuutilstr) { char *p; int mdcreads, mdcwrites, mdchitpct; char mdcresult[100]; char msgline[256]; strbuffer_t *msg; if (!cpuutilstr) return; msg = newstrbuffer(0); /* * Looking for MDC info in 'IND' command response * MDC READS-000001/SEC WRITES-000001/SEC HIT RATIO-098% */ *mdcresult = '\0'; /* Skip past three newlines in message to the PAGING text */ p=strstr(cpuutilstr,"READS-"); if (p) { p += 6; sscanf(p, "%d/SEC", &mdcreads); p=strstr(cpuutilstr,"WRITES-") + 7; sscanf(p, "%d/SEC", &mdcwrites); p=strstr(cpuutilstr,"RATIO-") + 6; sscanf(p, "%d", &mdchitpct); sprintf(msgline, "data %s.mdc\n%s\n%d:%d:%d\n", commafy(hostname), osname(os), mdcreads, mdcwrites, mdchitpct); addtobuffer(msg, msgline); combo_add(msg); } freestrbuffer(msg); }
void finish_status(void) { if (debug) { char *p = strchr(STRBUF(msgbuf), '\n'); if (p) *p = '\0'; dbgprintf("Adding to combo msg: %s\n", STRBUF(msgbuf)); if (p) *p = '\n'; } combo_add(msgbuf); }
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) combo_add(countdata); clearstrbuffer(countdata); }
void send_test_results(listhead_t *head, char *collector, int issubmodule, char *location, int usebackfeed) { char msgline[4096]; listitem_t *walk; xtreePos_t handle; void *hostresults = xtreeNew(strcasecmp); if (usebackfeed) combo_start_local(); else combo_start(); for (walk = head->head; (walk); walk = walk->next) { hostresult_t *hres; myconn_t *rec = (myconn_t *)walk->data; char *s; if (rec->ignoreresult) continue; switch (rec->talkprotocol) { case TALK_PROTO_PING: if (!issubmodule && (rec->talkresult == TALK_OK)) { add_to_sub_queue(rec, "ping", location, NULL); continue; } break; #ifdef HAVE_LDAP case TALK_PROTO_LDAP: if (!issubmodule && (rec->talkresult == TALK_OK)) { char *creds = xmh_item(rec->hostinfo, XMH_LDAPLOGIN); add_to_sub_queue(rec, "ldap", location, creds, NULL); continue; } break; #endif case TALK_PROTO_EXTERNAL: if (!issubmodule && (rec->talkresult == TALK_OK)) { if (strncmp(rec->testspec, "rpc=", 4) == 0) add_to_sub_queue(rec, "rpc", location, NULL); else add_to_sub_queue(rec, rec->testspec, location, NULL); continue; } break; default: break; } handle = xtreeFind(hostresults, xmh_item(rec->hostinfo, XMH_HOSTNAME)); if (handle == xtreeEnd(hostresults)) { hres = (hostresult_t *)calloc(1, sizeof(hostresult_t)); hres->hinfo = rec->hostinfo; hres->txt = newstrbuffer(0); xtreeAdd(hostresults, xmh_item(rec->hostinfo, XMH_HOSTNAME), hres); snprintf(msgline, sizeof(msgline), "client/%s %s.netcollect netcollect\n", collector, xmh_item(rec->hostinfo, XMH_HOSTNAME)); addtobuffer(hres->txt, msgline); } else { hres = xtreeData(hostresults, handle); } switch (rec->talkprotocol) { case TALK_PROTO_DNSQUERY: snprintf(msgline, sizeof(msgline), "\n[dns=%s]\n", rec->testspec); addtobuffer(hres->txt, msgline); break; case TALK_PROTO_PING: snprintf(msgline, sizeof(msgline), "\n[ping=%s]\n", rec->netparams.destinationip); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "SourceSpec: %s\n", rec->testspec); addtobuffer(hres->txt, msgline); break; default: snprintf(msgline, sizeof(msgline), "\n[%s]\n", rec->testspec); addtobuffer(hres->txt, msgline); break; } snprintf(msgline, sizeof(msgline), "Handler: %s\n", talkproto_names[rec->talkprotocol]); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "StartTime: %d\nEndTime: %d\n", (int)rec->teststarttime, (int)rec->testendtime); addtobuffer(hres->txt, msgline); if (rec->netparams.lookupstring) { snprintf(msgline, sizeof(msgline), "TargetHostname: %s\n", rec->netparams.lookupstring); addtobuffer(hres->txt, msgline); } snprintf(msgline, sizeof(msgline), "TargetIP: %s\n", rec->netparams.destinationip); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "TargetPort: %d\n", rec->netparams.destinationport); addtobuffer(hres->txt, msgline); if (rec->netparams.sourceip) { snprintf(msgline, sizeof(msgline), "SourceIP: %s\n", rec->netparams.sourceip); addtobuffer(hres->txt, msgline); } if (location) { snprintf(msgline, sizeof(msgline), "Location: %s\n", location); addtobuffer(hres->txt, msgline); } if (rec->talkprotocol == TALK_PROTO_PING) s = "ICMP"; else { switch (rec->netparams.socktype) { case CONN_SOCKTYPE_STREAM: s = "TCP"; break; case CONN_SOCKTYPE_DGRAM: s = "UDP"; break; default: s = "UNKNOWN"; break; } } snprintf(msgline, sizeof(msgline), "Protocol: %s\n", s); addtobuffer(hres->txt, msgline); switch (rec->netparams.sslhandling) { case CONN_SSL_NO: s = "NO"; break; case CONN_SSL_YES: s = "YES"; break; case CONN_SSL_STARTTLS_CLIENT: s = "STARTTLS_CLIENT"; break; case CONN_SSL_STARTTLS_SERVER: s = "STARTTLS_SERVER"; break; default: s = "UNKNOWN"; break; } snprintf(msgline, sizeof(msgline), "SSL: %s\n", s); addtobuffer(hres->txt, msgline); switch (rec->talkresult) { case TALK_CONN_FAILED: s = "CONN_FAILED"; break; case TALK_CONN_TIMEOUT: s = "CONN_TIMEOUT"; break; case TALK_OK: s = "OK"; break; case TALK_BADDATA: s = "BADDATA"; break; case TALK_BADSSLHANDSHAKE: s = "BADSSLHANDSHAKE"; break; case TALK_INTERRUPTED: s = "INTERRUPTED"; break; case TALK_CANNOT_RESOLVE: s = "CANNOT_RESOLVE"; break; case TALK_MODULE_FAILED: s = "MODULE_FAILED"; break; default: s = "UNKNOWN"; break; } snprintf(msgline, sizeof(msgline), "Status: %s\n", s); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "TestID: %lu\nElapsedMS: %d.%02d\nDNSMS: %d.%02d\nTimeoutMS: %d\nIntervalMS: %d\n", rec->testid, (rec->elapsedus / 1000), (rec->elapsedus % 1000), (rec->dnselapsedus / 1000), (rec->dnselapsedus % 1000), rec->timeout*1000, rec->interval*1000); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "BytesRead: %u\nBytesWritten: %u\n", rec->bytesread, rec->byteswritten); addtobuffer(hres->txt, msgline); if (rec->peercertificate) { char exps[50]; addtobuffer(hres->txt, "PeerCertificateSubject: "); addtobuffer(hres->txt, rec->peercertificate); addtobuffer(hres->txt, "\n"); addtobuffer(hres->txt, "PeerCertificateIssuer: "); addtobuffer(hres->txt, rec->peercertificateissuer); addtobuffer(hres->txt, "\n"); strftime(exps, sizeof(exps), "%Y-%m-%d %H:%M:%S UTC", gmtime(&rec->peercertificatestart)); snprintf(msgline, sizeof(msgline), "PeerCertificateStart: %d %s\n", (int)rec->peercertificatestart, exps); addtobuffer(hres->txt, msgline); strftime(exps, sizeof(exps), "%Y-%m-%d %H:%M:%S UTC", gmtime(&rec->peercertificateexpiry)); snprintf(msgline, sizeof(msgline), "PeerCertificateExpiry: %d %s\n", (int)rec->peercertificateexpiry, exps); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "PeerCertificateKeysize: %d\n", (int)rec->peercertificatekeysize); addtobuffer(hres->txt, msgline); snprintf(msgline, sizeof(msgline), "PeerCertificateDetails: %d\n", (int)strlen(rec->peercertificatedetails)+1); addtobuffer(hres->txt, msgline); addtobuffer(hres->txt, rec->peercertificatedetails); addtobuffer(hres->txt, "\n"); } switch (rec->talkprotocol) { case TALK_PROTO_PLAIN: result_plain(rec, hres->txt); break; case TALK_PROTO_NTP: result_ntp(rec, hres->txt); break; case TALK_PROTO_HTTP: result_http(rec, hres->txt); break; case TALK_PROTO_DNSQUERY: result_dns(rec, hres->txt); break; case TALK_PROTO_PING: result_subqueue("PING", rec, hres->txt); break; #ifdef HAVE_LDAP case TALK_PROTO_LDAP: result_subqueue("LDAP", rec, hres->txt); break; #endif case TALK_PROTO_EXTERNAL: result_subqueue(rec->testspec, rec, hres->txt); break; default: break; } } for (handle = xtreeFirst(hostresults); handle != xtreeEnd(hostresults); handle = xtreeNext(hostresults, handle)) { hostresult_t *hres = xtreeData(hostresults, handle); combo_add(hres->txt); freestrbuffer(hres->txt); xtreeDelete(hostresults, xmh_item(hres->hinfo, XMH_HOSTNAME)); xfree(hres); } xtreeDestroy(hostresults); combo_end(); }