#include #include #include #include #include #include #include #include /* netstat average parser */ /* The only lines you need to modify before compiling */ #define IMAGE_URL "images" #define PATH_TO_FILES "results" /* After setting the path to your 'results' file, > gcc miniparser.c -o miniparse.cgi and then put the following in the html document along with the individual stats cgi: Make sure your images directory is the URL path to the images, otherwise they'll likely be broken. Any questions / comments / problems, email: roddy@richards.org Yeah, ok, so I probably could've done it with gd (www.boutell.com/gd/) and spared you the trouble of having to manage 11 .gif files. Maybe I'll do that in the next revision :) 7/24/98 */ #define TOP_COLOR "#B4CFF7" typedef struct { char *from; /* what backbone returned these results */ char *name; /* backbone name */ char *dname; int status; /* 0 if everything's cool, 1 if it's not responding right */ float min; /* Minimum time :from ping */ float avg; /* Average time :from ping */ float max; /* Maximum time :from ping */ int loss; /* Packet Loss :from ping */ } infotype; FILE *fcheck(char name[], char *mode) { FILE *fp; if ((fp = fopen(name,mode)) == NULL) { fprintf(stderr, "Unable to access: %s. Exiting.\n", name); exit(1); } return (fp); } void main (void) { infotype results[128]; /* net data from host, 128 seemed large enough */ int max, i, j, k, loss_gif, rcount, color, overall; char filename[255],line[255], last[64], fullpath[255], table_color[16], bgcolor[16]; /* time */ struct stat stbuf; struct tm *tmptr; FILE *fp; printf("Content-type: text/html\n\n"); fflush(stdout); j = 0; max = 128; rcount = 0; overall = 0; loss_gif = 0; fp = fcheck(PATH_TO_FILES, "r"); while(fgets(line, max, fp) != NULL) { /* divide up the file */ if(line[0] == '|') { results[rcount].name = strdup(strtok(line, "|")); results[rcount].dname = strdup(strtok(NULL, "|")); results[rcount].status = atof(strtok(NULL, "|")); if (results[rcount].status == 0) { results[rcount].min = atof(strtok(NULL, "|")); results[rcount].avg = atof(strtok(NULL, "|")); results[rcount].max = atof(strtok(NULL, "|")); results[rcount].loss = atof(strtok(NULL, "\n")); j = j +1; overall = overall + results[rcount].loss; } rcount++; } /* if */ } overall = overall/j; color =0; /* time stamp */ if (stat(fullpath, &stbuf) == 0) { tmptr = localtime(&stbuf.st_mtime); strftime(last, 40, "%m/%d/%y at %I:%M %p %Z", tmptr); } /* print overall stats, averaged */ if(overall > 2) loss_gif = 1; if(overall > 5) loss_gif = 2; if(overall > 8) loss_gif = 3; if(overall > 11) loss_gif = 4; if(overall > 14) loss_gif = 5; if(overall > 17) loss_gif = 6; if(overall > 20) loss_gif = 7; if(overall > 23) loss_gif = 8; if(overall > 26) loss_gif = 9; if(overall > 29) loss_gif = 10; printf("
\n", TOP_COLOR); printf("\n"); printf("\n", IMAGE_URL, loss_gif); printf("\n\n
Overall Backbone Packet Loss:\n\t\n%d%% Average\n
\n
\n", overall); }