void check_load_stats(int conn, int warn, int crit, char *param) { char *p, *v; int rc=0; struct xmltree *response; int value=-1; sendreq(conn, "<lo>-1</lo>"); response=xmlparsefd(conn); if (!strcmp(param, "1")) v=xmlvalue(response, "isr/LOAD/one"); else if (!strcmp(param, "5")) v=xmlvalue(response, "isr/LOAD/fv"); else if (!strcmp(param, "15")) v=xmlvalue(response, "isr/LOAD/ff"); if (v!=NULL) value=atoi(v); if (value==-1) { rc=3; } else if (crit>0 && value>crit) { rc=2; } else if (crit<0 && value<-crit) { rc=2; } else if (warn>0 && value>warn) { rc=1; } else if (warn<0 && value<-warn) { rc=1; } addcheckresult(rc, 'l', param, value, warn, crit, 0, -1); xmlfreetree(response); }
void check_cpu_stats(int conn, int warn, int crit, char *param) { char *p, *v; int rc=0; struct xmltree *response; int total=0; char buf[]="isr/CPU/c/."; sendreq(conn, "<c>-1</c>"); response=xmlparsefd(conn); total=0; for (p=param; *p; p++) { buf[sizeof buf - 2]=*p; if ((v=xmlvalue(response, buf))==NULL) { addcheckresult(3, 'c', p, 0, warn, crit, 0, 100); return; } total+=atoi(v); } if (crit>0 && total>crit) { rc=2; } else if (crit<0 && total<-crit) { rc=2; } else if (warn>0 && total>warn) { rc=1; } else if (warn<0 && total<-warn) { rc=1; } addcheckresult(rc, 'c', param, total, warn, crit, 0, 100); xmlfreetree(response); }
void check_memory_stats(int conn, int warn, int crit, char *param) { int rc=0; struct xmltree *response; int total=0, temp; char buf[80], parmbuf[80], *p, *r; sendreq(conn, "<m>-1</m>"); response=xmlparsefd(conn); strcpy(parmbuf, param); p=strtok(parmbuf, ","); while (p) { strcpy(buf, "isr/MEM/"); strcat(buf, p); if ((r=xmlvalue(response, buf))==NULL) { addcheckresult(3, 'm', p, 0, warn, crit, 0, -1); return; } temp=atoi(r); total+=temp; p=strtok(NULL, ","); } if (crit>0 && total>crit) { rc=2; } else if (crit<0 && total<-crit) { rc=2; } else if (warn>0 && total>warn) { rc=1; } else if (warn<0 && total<-warn) { rc=1; } addcheckresult(rc, 'm', param, total, warn, crit, 0, 100); xmlfreetree(response); }
char const * xmlselect (NODE * node, char const * element, char const * attribute) { node = xmlelement (node, element); if ((attribute) && (* attribute)) { node = xmlattribute (node, attribute); node = xmlvalue (node); } else { node = xmlcontent (node); } return (node? node->text: ""); }
void check_uptime(int conn, int warn, int crit) { char *p, *v; int rc=0; struct xmltree *response; int value=-1; sendreq(conn, "<u></u>"); response=xmlparsefd(conn); v=xmlvalue(response, "isr/UPT/u"); if (v!=NULL) value=atoi(v); if (value==-1) { rc=3; } else if (crit>0 && value>crit) { rc=2; } else if (crit<0 && value<-crit) { rc=2; } else if (warn>0 && value>warn) { rc=1; } else if (warn<0 && value<-warn) { rc=1; } addcheckresult(rc, 'u', "", value, warn, crit, 0, -1); xmlfreetree(response); }