char version[] = "@(#) Taylor UUCP Log File Summary Filter, Version 1.2.2";
static char rcsid[] = "$Id: uurate.c,v 1.15 1994/04/07 21:47:11 kdburg Rel $";
#include <ctype.h>
#include <math.h>
#include "uucp.h"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#define _DEBUG_ 0
#define IN 0
#define OUT 1
#define MAXCOLS 8
#define MAXREP 6
#define MAXFNAME 64
#define MAXDNAME 8
struct File_Stats
{
int files;
unsigned long bytes;
double time;
};
struct Phone_Call
{
int calls;
int succs;
double connect_time;
struct File_Stats flow[2];
};
struct Execution_Command
{
struct Execution_Command *next;
char Commandname[64];
int count;
};
struct Protocol_Summary
{
struct Protocol_Summary *next;
char type[3];
long int pr_cnt;
long int pr_psent;
long int pr_present;
long int pr_preceived;
long int pr_eheader;
long int pr_echksum;
long int pr_eorder;
long int pr_ereject;
long int pr_pwinmin;
long int pr_pwinmax;
long int pr_psizemin;
long int pr_psizemax;
};
struct Host_entry
{
struct Host_entry *next;
char Hostname[32];
struct Execution_Command *cmds;
struct Phone_Call call[2];
struct Protocol_Summary *proto;
};
struct Host_entry *hosts = NULL;
struct Host_entry *tot = NULL;
struct Host_entry *cur = NULL;
struct Execution_Command *cmd, *t_cmds = NULL;
struct Protocol_Summary *prot, *t_prot, *s_prot, *ss_prot = NULL;
extern int optind;
extern char *optarg;
extern int getopt();
#if ! HAVE_STDLIB_H
extern pointer *calloc();
#endif
static char *def_logs[3] = { NULL, NULL, NULL};
char *I_conf = NULL;
char *D_conf = NULL;
char *Tlog = NULL;
char *Tstat = NULL;
char Pgm_name[64];
char logline[BUFSIZ+1];
char noConf[] = "- not defined -";
char buff[16*BUFSIZ];
char sbuff[2*BUFSIZ];
int p_done = FALSE;
int hdr_done = FALSE;
int show_files = FALSE;
int show_calls = FALSE;
int show_commands = FALSE;
int show_efficiency = FALSE;
int show_all = FALSE;
int show_proto = FALSE;
int use_stdin = FALSE;
int be_quiet = FALSE;
int have_files[2];
int have_calls = FALSE;
int have_commands = FALSE;
int have_proto = FALSE;
int no_records = TRUE;
static pointer *getmem(unsigned n);
static void inc_cmd(struct Execution_Command **, char *name);
static void fmtime(double sec, char *buf);
static void fmbytes(unsigned long n, char *buf);
static void usage();
static int chk_config(char *conf, int n, int type);
static void hdrprt(char c, int bot);
struct Protocol_Summary *prot_sum(struct Protocol_Summary **, char *, int);
int main(argc, argv)
int argc;
char *argv[];
{
FILE *Log = NULL;
int c;
char *p, *s, *stt, *flq = NULL;
char Hostname[MAXHOSTNAMELEN];
char Filename[15];
char in_date[14];
char in_time[14];
char dt_info[31];
char *logmsg;
int sent, called = IN;
int report = 0;
int junk;
Hostname[0] = '\0';
have_files[IN]= have_files[OUT]= FALSE;
setvbuf(stdout,sbuff,_IOFBF,sizeof(sbuff));
if ((stt = strrchr(argv[0],'/')) != NULL)
strcpy(Pgm_name,++stt);
else
strcpy(Pgm_name,argv[0]);
def_logs[0] = Pgm_name;
#if !HAVE_TAYLOR_LOGGING && !HAVE_V2_LOGGING
fprintf(stderr,"\a%s: (E) %s\n",Pgm_name,"Your config of Taylor UUCP is not yet supported.");
fprintf(stderr,"%s: (E) %s\n",Pgm_name,"Current support is for V2 or TAYLOR logging only.");
puts(" Run aborted due to errors\n")
exit(1);
#endif
if (sizeof(NEWCONFIGLIB) > 1)
{
D_conf = (char *)getmem((sizeof(NEWCONFIGLIB) + sizeof("/config")));
strcpy(D_conf,NEWCONFIGLIB);
strcat(D_conf,"/config");
}
Tlog = (char *)getmem(sizeof(LOGFILE));
Tstat = (char *)getmem(sizeof(STATFILE));
Tlog = LOGFILE;
Tstat = STATFILE;
while((c = getopt(argc, argv, "I:s:cfdexaitphv")) != EOF)
{
switch(c)
{
case 'h':
(void) usage();
case 's':
strcpy(Hostname, optarg);
break;
case 'c':
show_calls = TRUE;
++report;
break;
case 'd':
printf("%s: (I) config-file default: %s\n",Pgm_name,D_conf);
exit (0);
break;
case 'f':
show_files = TRUE;
++report;
break;
case 'x':
show_commands = TRUE;
++report;
break;
case 'e':
show_efficiency = TRUE;
++report;
break;
case 'a':
show_calls = show_files = show_commands = show_efficiency = TRUE;
report = 4;
break;
case 'i':
use_stdin = TRUE;
break;
case 't':
show_all = TRUE;
report = MAXREP;
break;
case 'p':
show_proto = TRUE;
++report;
break;
case 'I':
I_conf = (char *)getmem(sizeof(optarg));
I_conf = optarg;
break;
case 'q':
be_quiet = TRUE;
break;
case 'v':
printf("%s\n",rcsid);
exit (0);
default :
(void) usage();
}
}
if (report == 0)
++report;
if (! be_quiet)
hdrprt('i',0);
argc -= (optind - 1);
argv += (optind - 1);
if (use_stdin)
{
if (argc != 1)
{
fprintf(stderr,"\a%s: (E) %s\n",Pgm_name,
"it's not posssible to give file args with '-i'");
(void) usage();
}
else
{
argc = 2;
Log = stdin;
if (! be_quiet)
puts(" Input from stdin; no other files will be used\n");
}
}
else
{
if (argc != 1)
{
if (! be_quiet)
puts(" No defaults used; will use passed file arguments\n");
}
else
{
def_logs[1] = Tlog;
def_logs[2] = Tstat;
if (! be_quiet)
printf(" Config for this run: ");
if (I_conf != NULL)
{
junk = 0;
if (! be_quiet)
printf("%s\n",I_conf);
if (0 != (chk_config(I_conf,be_quiet,junk)))
return (8);
}
else
{
if (D_conf != NULL)
{
junk = 1;
if (! be_quiet)
printf("%s\n",D_conf);
chk_config(D_conf,be_quiet,junk);
}
else
if (! be_quiet)
printf("%s\n",noConf);
}
def_logs[1] = Tlog;
def_logs[2] = Tstat;
argv = def_logs;
argc = sizeof(def_logs) / sizeof(def_logs[0]);
}
}
if (!use_stdin)
{
if (argc < 3 && ! be_quiet)
{
puts(" (W) there is only one input file!");
puts(" (W) some reports may not be printed");
}
if (! be_quiet)
hdrprt('d',0);
}
while (argc > 1)
{
if (!use_stdin && (Log = fopen(argv[1], "r")) == NULL)
{
perror(argv[1]);
exit (8);
}
setvbuf(Log,buff,_IOFBF,sizeof(buff));
if ((flq = strrchr(argv[1], '/')) == NULL)
strncpy(Filename,argv[1],sizeof(Filename)-1);
else
strncpy(Filename,++flq,sizeof(Filename)-1);
strcpy(in_date," n/a");
strcpy(in_time," n/a");
p_done = FALSE;
no_records = TRUE;
while (fgets(logline, sizeof(logline), Log))
{
if (NULL == (p = strchr(logline, ' ')))
continue;
no_records = FALSE;
++p;
if (NULL != (stt = strchr(p, '(')))
{
if (! p_done && ! use_stdin && ! be_quiet)
{
#if HAVE_TAYLOR_LOGGING
sscanf(++stt,"%s%*c%[^.]",in_date,in_time);
#endif
#if HAVE_V2_LOGGING
sscanf(++stt,"%[^-]%*c%[1234567890:]",in_date,in_time);
#endif
printf(" %-14s %10s %8s",Filename, in_date, in_time);
strcpy(in_date," n/a");
strcpy(in_time," n/a");
p_done = TRUE;
}
else
{
if (! use_stdin && ! be_quiet)
strncpy(dt_info,++stt,sizeof(dt_info)-1);
}
}
if (NULL != (s = strchr(p, ' ')))
*s = '\0';
for (s = p; *s; ++s)
if (isupper(*s))
*s = tolower(*s);
if (Hostname[0] != '\0')
if ( (p[0] != '-' || p[1] != '\0') && 0 != strcmp(p, Hostname) )
continue;
if ((s = strchr(++s, ')')) == NULL)
continue;
#if ! HAVE_TAYLOR_LOGGING
#if HAVE_V2_LOGGING
if ((strncmp(s,") (",3)) == 0)
if ((s = strchr(++s, ')')) == NULL)
continue;
#endif
#endif
logmsg = s + 2;
if ((0 != strncmp(logmsg, "Call complete", 13)) &&
(0 != strncmp(logmsg, "Calling system", 14)) &&
(0 != strncmp(logmsg, "Incoming call", 13)) &&
(0 != strncmp(logmsg, "Handshake successful", 20)) &&
(0 != strncmp(logmsg, "Retry time not", 14)) &&
(0 != strncmp(logmsg, "ERROR: All matching ports", 25)) &&
(0 != strncmp(logmsg, "Executing", 9)) &&
(0 != strncmp(logmsg, "Protocol ", 9)) &&
(0 != strncmp(logmsg, "sent ", 5)) &&
(0 != strncmp(logmsg, "received ", 9)) &&
(0 != strncmp(logmsg, "failed after ", 13)) &&
(0 != strncmp(logmsg, "Errors: ", 8)))
continue;
if ((cur == NULL) || (0 != strcmp(p, cur->Hostname)))
{
struct Host_entry *e, *last;
for (e= cur= hosts; cur != NULL ; e= cur, cur= cur->next)
if (0 == strcmp(cur->Hostname, p))
break;
if (cur == NULL)
{
cur= (struct Host_entry *)getmem(sizeof(*hosts));
strcpy(cur->Hostname, p);
if (hosts == NULL)
e= hosts= cur;
else {
e = hosts;
last = NULL;
while (e != NULL) {
if (strcmp(e->Hostname, cur->Hostname) <= 0) {
if (e->next == NULL) {
e->next = cur;
break;
}
last = e;
e = e->next;
}
else {
cur->next = e;
if (last == NULL)
hosts = cur;
else
last->next = cur;
break;
}
}
}
}
}
if (0 == strncmp(logmsg, "Executing", 9))
{
if (NULL == (p = strchr(logmsg, '(')))
continue;
if ((s = strpbrk(++p, " )")) == NULL)
continue;
*s = '\0';
inc_cmd(&cur->cmds, p);
inc_cmd(&t_cmds, p);
have_commands = TRUE;
continue;
}
if ((0 == strncmp(logmsg, "Calling system", 14)) ||
(0 == strncmp(logmsg, "Retry time not", 14)) ||
(0 == strncmp(logmsg, "ERROR: All matching ports", 25)))
{
called = OUT;
cur->call[OUT].calls++;
have_calls = TRUE;
s_prot = NULL;
continue;
}
if (0 == strncmp(logmsg, "Incoming call", 13))
{
called = IN;
s_prot = NULL;
continue;
}
if (0 == strncmp(logmsg, "Handshake successful", 20))
{
if ( called==IN )
cur->call[IN].calls++;
have_calls = TRUE;
s_prot = NULL;
if (NULL == (p = strchr(logmsg, '(')))
continue;
if (0 == strncmp(p, "(protocol ", 10))
{
if (NULL == (p = strchr(p, '\'')))
continue;
ss_prot = prot_sum(&cur->proto, ++p, 1);
s_prot = prot_sum(&t_prot, p, 1);
continue;
}
}
if (0 == strncmp(logmsg, "Protocol ", 9))
{
s_prot = NULL;
if (NULL == (p = strchr(logmsg, '\'')))
continue;
ss_prot = prot_sum(&cur->proto, ++p, 2);
s_prot = prot_sum(&t_prot, p, 2);
continue;
}
if ((0 == strncmp(logmsg, "Errors: header", 14)) && s_prot != NULL)
{
int i1,i2,i3,i4 = 0;
sscanf(logmsg,"%*s %*s %d%*c%*s %d%*c%*s %d%*c%*s %*s%*c %d",&i1,&i2,&i3,&i4);
ss_prot->pr_eheader += i1;
ss_prot->pr_echksum += i2;
ss_prot->pr_eorder += i3;
ss_prot->pr_ereject += i4;
s_prot->pr_eheader += i1;
s_prot->pr_echksum += i2;
s_prot->pr_eorder += i3;
s_prot->pr_ereject += i4;
s_prot = NULL;
continue;
}
if (0 == strncmp(logmsg, "Call complete", 13))
{
cur->call[called].succs++;
s_prot = NULL;
if (NULL == (s = strchr(logmsg, '(')))
continue;
cur->call[called].connect_time += atof(s+1);
continue;
}
sent = IN;
if (0 == strncmp(logmsg, "failed after ",13))
logmsg += 13;
if (0 == strncmp(logmsg, "sent", 4))
sent = OUT;
else if (0 == strncmp(logmsg, "received", 8))
sent = IN;
have_files[sent] = TRUE;
cur->call[called].flow[sent].files++;
if (NULL == (s = strchr(logmsg, ' ')))
continue;
#if HAVE_TAYLOR_LOGGING
cur->call[called].flow[sent].bytes += atol(++s);
#endif
#if HAVE_V2_LOGGING
if (NULL == (s = strpbrk(s, "0123456789")))
continue;
cur->call[called].flow[sent].bytes += atol(s);
#endif
if (NULL == (s = strchr(s, ' ')))
continue;
if (NULL == (s = strpbrk(s, "0123456789")))
continue;
cur->call[called].flow[sent].time += atof(s);
}
if (stt != NULL && ! use_stdin && ! be_quiet && ! no_records)
{
#if HAVE_TAYLOR_LOGGING
sscanf(dt_info,"%s%*c%[^.]",in_date,in_time);
#endif
#if HAVE_V2_LOGGING
sscanf(dt_info,"%[^-]%*c%[1234567890:]",in_date,in_time);
#endif
printf(" %10s %8s\n",in_date, in_time);
p_done = FALSE;
}
if (Log != stdin)
{
if (0 != ferror(Log))
{
if (! be_quiet)
printf(" %-14s data is incomplete; read error"," ");
else
fprintf(stderr,"%s (W) data is incomplete; read error on %s\n",
Pgm_name,argv[1]);
}
else
{
if (! be_quiet && no_records)
printf(" %-14s %10s\n",Filename, " is empty ");
}
}
fclose(Log);
argc--;
argv++;
}
if (cur == NULL)
{
puts("\n(I) Sorry! No data is available for any requested report\n");
exit(0);
}
for (cur = hosts; cur != NULL;cur = cur->next)
{
cur->Hostname[MAXDNAME] = '\0';
if (cur->next == NULL)
{
cur->next = (struct Host_entry *)getmem(sizeof(*hosts));
strcpy(cur->next->Hostname,"Totals");
tot = cur->next;
for (cur = hosts; cur != NULL; cur = cur->next)
{
if (cur->next != NULL)
{
tot->call[IN].flow[IN].bytes += cur->call[IN].flow[IN].bytes;
tot->call[OUT].flow[IN].bytes += cur->call[OUT].flow[IN].bytes;
tot->call[IN].flow[OUT].bytes += cur->call[IN].flow[OUT].bytes;
tot->call[OUT].flow[OUT].bytes += cur->call[OUT].flow[OUT].bytes;
tot->call[IN].flow[IN].time += cur->call[IN].flow[IN].time;
tot->call[OUT].flow[IN].time += cur->call[OUT].flow[IN].time;
tot->call[IN].flow[OUT].time += cur->call[IN].flow[OUT].time;
tot->call[OUT].flow[OUT].time += cur->call[OUT].flow[OUT].time;
tot->call[IN].flow[IN].files += cur->call[IN].flow[IN].files;
tot->call[OUT].flow[IN].files += cur->call[OUT].flow[IN].files;
tot->call[IN].flow[OUT].files += cur->call[IN].flow[OUT].files;
tot->call[OUT].flow[OUT].files += cur->call[OUT].flow[OUT].files;
tot->call[OUT].succs += cur->call[OUT].succs;
tot->call[OUT].calls += cur->call[OUT].calls;
tot->call[OUT].connect_time += cur->call[OUT].connect_time;
tot->call[IN].succs += cur->call[IN].succs;
tot->call[IN].calls += cur->call[IN].calls;
tot->call[IN].connect_time += cur->call[IN].connect_time;
}
}
break;
}
}
#if _DEBUG_
putchar('\n');
#endif
if ( !(show_calls || show_files ||
show_efficiency || show_commands || show_proto) || show_all)
{
if (have_calls || have_files[IN] || have_files[OUT])
{
char t1[32], t2[32], t3[32], t4[32], t5[32];
long ib, ob, b, rf, sf;
double it, ot, ir, or;
hdr_done = FALSE;
for (cur = hosts; cur != NULL; cur = cur->next)
{
ib = (cur->call[IN].flow[IN].bytes +
cur->call[OUT].flow[IN].bytes);
fmbytes(ib, t1);
ob = (cur->call[IN].flow[OUT].bytes +
cur->call[OUT].flow[OUT].bytes);
fmbytes(ob, t2);
if (( b= ib+ob ) == 0 )
continue;
if (! hdr_done)
{
hdrprt('s',0);
hdr_done = TRUE;
}
fmbytes(b, t3);
it = cur->call[IN].flow[IN].time +
cur->call[OUT].flow[IN].time;
fmtime(it, t4);
ot = cur->call[IN].flow[OUT].time +
cur->call[OUT].flow[OUT].time;
fmtime(ot, t5);
rf = cur->call[IN].flow[IN].files +
cur->call[OUT].flow[IN].files;
sf = cur->call[IN].flow[OUT].files +
cur->call[OUT].flow[OUT].files;
ir = (it == 0.0) ? 0.0 : (ib / it);
or = (ot == 0.0) ? 0.0 : (ob / ot);
if (cur->next == NULL)
hdrprt('s',1);
printf("%-8s %4ld %4ld %9s %9s %9s %8s %8s %5.0f %5.0f\n",
cur->Hostname, rf, sf,
t1, t2, t3, t4, t5,
ir, or);
}
if (! hdr_done)
{
puts("\n(I) No data found to print Compact summary report");
}
}
else
{
puts("\n(I) No data available for Compact summary report");
--report;
}
}
if (show_proto || show_all)
{
if (have_proto)
{
char *type = NULL;
hdr_done = FALSE;
for (cur = hosts; cur != NULL; cur = cur->next)
{
type = cur->Hostname;
if (cur->next == NULL)
{
if (hdr_done)
puts("-------------------------------------------------------------------");
cur->proto = t_prot;
}
for (prot = cur->proto; prot != NULL; prot = prot->next)
{
if (! hdr_done)
{
hdrprt('p',0);
hdr_done = TRUE;
}
printf("%-8s %3s %4ld %4ld %5ld %4ld %10ld %7ld %10ld\n",
type == NULL ? " ":cur->Hostname,
prot->type,
prot->pr_psizemin,
prot->pr_psizemax,
prot->pr_pwinmin,
prot->pr_pwinmax,
prot->pr_psent,
prot->pr_present,
prot->pr_preceived);
type = NULL;
}
}
if (! hdr_done)
puts("\n(I) No data found to print Protocol packet report");
type = NULL;
hdr_done = FALSE;
if (t_prot != NULL)
{
for (cur = hosts; cur != NULL; cur = cur->next)
{
type = cur->Hostname;
if (cur->next == NULL)
{
if (hdr_done)
puts("--------------------------------------------------------------");
cur->proto = t_prot;
}
for (prot = cur->proto; prot != NULL; prot = prot->next)
{
if ((prot->pr_eheader + prot->pr_echksum +
prot->pr_eorder + prot->pr_ereject) != 0)
{
if (! hdr_done)
{
hdrprt('p',1);
hdr_done = TRUE;
}
printf("%-8s %3s %11ld %11ld %11ld %11ld\n",
type == NULL ? " ":cur->Hostname,
prot->type,
prot->pr_eheader,
prot->pr_echksum,
prot->pr_eorder,
prot->pr_ereject);
type = NULL;
}
}
}
}
if (! hdr_done)
puts("\n(I) No data found to print Protocol error report");
}
else
{
puts("\n(I) No data available for Protocol reports");
--report;
}
}
if (show_calls || show_all)
{
if (have_calls)
{
char t1[32], t2[32];
hdr_done = FALSE;
for (cur = hosts; cur != NULL; cur = cur->next)
{
if (cur->next == NULL)
{
if (hdr_done)
hdrprt('c',1);
}
else
{
if ( cur->call[OUT].calls + cur->call[IN].calls == 0 )
continue;
if (! hdr_done)
{
hdrprt('c',0);
hdr_done = TRUE;
}
}
if ( cur->call[OUT].calls > 0 || cur->next == NULL)
{
fmtime(cur->call[OUT].connect_time, t1);
printf( " %-8s %7d %7d %7d %9s",
cur->Hostname,
cur->call[OUT].succs,
cur->call[OUT].calls - cur->call[OUT].succs,
cur->call[OUT].calls,
t1 );
}
else
{
printf( " %-42s", cur->Hostname );
}
if ( cur->call[IN].calls > 0 || cur->next == NULL )
{
fmtime(cur->call[IN].connect_time, t2);
printf( " %7d %7d %7d %9s",
cur->call[IN].succs,
cur->call[IN].calls - cur->call[IN].succs,
cur->call[IN].calls,
t2 );
}
putchar('\n');
}
if (! hdr_done)
{
puts("\n(I) No data found to print Call statistics report");
}
}
else
{
puts("\n(I) No data available for Call statistics report");
--report;
}
}
if (show_files || show_all)
{
if (have_files[IN] || have_files[OUT])
{
char t1[32], t2[32];
double rate = 0, time = 0;
int b = 0;
int lineOut = 0;
hdr_done = FALSE;
for (cur = hosts; cur != NULL; cur = cur->next)
{
lineOut = 0;
for (sent= IN; sent <= OUT; ++sent)
{
b = cur->call[IN].flow[sent].bytes +
cur->call[OUT].flow[sent].bytes;
time = cur->call[IN].flow[sent].time +
cur->call[OUT].flow[sent].time;
if ( (b != 0 && time != 0.0) || cur->next == NULL)
{
if (! hdr_done)
{
hdrprt('f',0);
hdr_done = TRUE;
}
fmbytes(b, t1);
rate = (cur->call[IN].flow[sent].bytes +
cur->call[OUT].flow[sent].bytes) / time;
fmtime((cur->call[IN].flow[sent].time +
cur->call[OUT].flow[sent].time), t2);
if (lineOut == 0)
{
if (cur->next == NULL)
hdrprt('f',1);
printf(" %-8s", cur->Hostname);
if (sent == OUT)
printf("%34s", " ");
}
printf(" %5d %11s %9s %5.0f",
cur->call[IN].flow[sent].files +
cur->call[OUT].flow[sent].files,
t1, t2, rate);
lineOut = 1;
}
}
if (lineOut)
printf("\n");
}
if (! hdr_done)
{
puts("\n(I) No data found to print File statistics report");
}
}
else
{
puts("\n(I) No data available for File statistics report");
--report;
}
}
if (show_efficiency || show_all)
{
if (have_files[IN] || have_files[OUT])
{
char t1[32], t2[32], t3[32];
double total, flow;
hdr_done = FALSE;
for (cur = hosts; cur != NULL; cur = cur->next)
{
if ( 0 == cur->call[IN].flow[IN].files +
cur->call[IN].flow[OUT].files +
cur->call[OUT].flow[IN].files +
cur->call[OUT].flow[OUT].files ||
0.0 == (total= cur->call[IN].connect_time +
cur->call[OUT].connect_time))
{
continue;
}
if (! hdr_done)
{
hdrprt('e',0);
hdr_done = TRUE;
}
flow = cur->call[IN].flow[IN].time +
cur->call[IN].flow[OUT].time +
cur->call[OUT].flow[IN].time +
cur->call[OUT].flow[OUT].time;
fmtime(total, t1);
fmtime(flow, t2);
fmtime(total-flow, t3);
if (cur->next == NULL)
hdrprt('e',1);
printf(" %-8s %10s %10s %10s %7.2f\n",
cur->Hostname, t1, t2, t3,
flow >= total ? 100.0: flow*100.0/total);
}
if (! hdr_done)
{
puts("\n(I) No data found to print Efficiency report");
}
}
else
{
puts("\n(I) No data available for Efficiency report");
--report;
}
}
if (show_commands || show_all)
{
if (have_commands)
{
int ncmds, i, match;
hdr_done = FALSE;
for (ncmds= 0, cmd= t_cmds;
cmd != NULL && ncmds <= MAXCOLS-1;
ncmds++, cmd= cmd->next)
{
if (! hdr_done)
{
puts("\nCommand executions:");
puts("-------------------");
puts(" Name of ");
fputs(" site ", stdout);
hdr_done = TRUE;
}
printf(" %7s", cmd->Commandname);
}
if (! hdr_done)
{
puts("\n(I) No data found to print Command execution report");
}
else
{
fputs("\n --------", stdout);
for (i= 0; i<ncmds; i++)
fputs(" ------", stdout);
putchar('\n');
for (cur= hosts; cur != NULL; cur= cur->next)
{
if (cur->next == NULL)
break;
if (cur->cmds == NULL)
continue;
printf(" %-8s", cur->Hostname);
for (cmd= t_cmds; cmd != NULL; cmd= cmd->next)
{
struct Execution_Command *ec;
match = FALSE;
for(ec= cur->cmds; ec != NULL; ec= ec->next)
{
if ( 0 == strcmp(cmd->Commandname, ec->Commandname) )
{
printf(" %7d", ec->count);
match = TRUE;
break;
}
}
if (! match)
printf("%8s"," ");
}
putchar('\n');
}
fputs(" --------", stdout);
for (i= 0; i<ncmds; i++)
fputs("--------", stdout);
printf("\n %-8s", cur->Hostname);
for (cmd= t_cmds; cmd != NULL; cmd= cmd->next)
{
printf(" %7d", cmd->count);
}
putchar('\n');
}
}
else
{
puts("\n(I) No data available for Command execution report");
--report;
}
}
if (report <= 0 )
{
puts("\n(I) Sorry! No data is available for any requested report\n");
exit(1);
}
puts("\n(I) End of reports\n");
exit (0);
}
void usage()
{
fprintf(stderr,"Usage uurate [-acdefhiptvx] [-s hostname] [-I config file] [logfile(s) ... logfile(s)]\n");
fprintf(stderr,"where:\t-a\tPrint reports c,e,f,x\n");
fprintf(stderr,"\t-c\tReport call statistics\n");
fprintf(stderr,"\t-d\tPrint the name of the default config file\n");
fprintf(stderr,"\t-e\tReport efficiency statistics\n");
fprintf(stderr,"\t-f\tReport file transfer statistics\n");
fprintf(stderr,"\t-h\tPrint this help\n");
fprintf(stderr,"\t-i\tRead log info from standard input\n");
fprintf(stderr,"\t-p\tReport protocol statistics\n");
fprintf(stderr,"\t-t\tAll available reports plus compact summary report\n");
fprintf(stderr,"\t-v\tPrint version number\n");
fprintf(stderr,"\t-x\tReport command execution statistics\n");
fprintf(stderr,"\t-s host\tReport activities involving HOST only\n");
fprintf(stderr,"\t-I config Use config instead of standard config file\n");
fprintf(stderr,"If no report options given, a compact summary report is printed.\n");
fprintf(stderr,"log files should be given as pairs that is Log/Stats ... .\n");
fprintf(stderr,"If neither -i nor logfiles given, those names found in config will be used\n");
exit (1);
}
static pointer *getmem(n)
unsigned n;
{
pointer *p;
if( NULL== (p= calloc(1, n)) )
{
fprintf(stderr,"\a%s (C) %s\n",Pgm_name, "out of memory\n");
exit (8);
}
return p;
}
static void inc_cmd(cmds, name)
struct Execution_Command **cmds;
char *name;
{
int cnt = 0;
struct Execution_Command *cmd, *ec;
for (ec = cmd = *cmds; cmd != NULL; ec= cmd, cmd= cmd->next, cnt++)
if ( (0 == strcmp(cmd->Commandname, name)) ||
(0 == strcmp(cmd->Commandname, "Misc.")) )
break;
if (cmd == NULL)
{
cmd= (struct Execution_Command *)getmem(sizeof(*cmd));
if (cnt <= MAXCOLS-1)
{
strcpy(cmd->Commandname, name);
if (*cmds == NULL)
ec = *cmds = cmd;
else
ec->next= cmd;
}
else
{
strcpy(ec->Commandname, "Misc.");
cmd = ec;
}
}
cmd->count++;
}
struct Protocol_Summary *
prot_sum(proto, ptype, ind)
struct Protocol_Summary **proto;
char *ptype;
int ind;
{
int cnt = 0;
int i1, i2, i3 = 0;
struct Protocol_Summary *cur, *first;
for (first = cur = *proto; cur != NULL; first= cur, cur= cur->next, cnt++)
{
if ( (0 == strncmp(cur->type, ptype,strlen(cur->type))))
break;
}
if (cur == NULL)
{
cur= (struct Protocol_Summary *)getmem(sizeof(*cur));
sscanf(ptype,"%[^\' ]3",cur->type);
if (*proto == NULL)
first = *proto = cur;
else
first->next= cur;
}
if (NULL == (ptype = strchr(ptype, ' ')))
return (NULL);
cur->pr_cnt++;
have_proto = TRUE;
++ptype;
switch(ind)
{
case 1:
i1 = i2 = 0;
if (NULL == (strchr(ptype, '/')))
sscanf(ptype,"%*s %*s %d %*s %d",&i1,&i2);
else
sscanf(ptype,"%*s %*s %d/%d",&i1,&i2);
if (i1 > cur->pr_psizemax)
cur->pr_psizemax = i1;
if (i1 < cur->pr_psizemin || cur->pr_psizemin == 0)
cur->pr_psizemin = i1;
if (i2 > cur->pr_pwinmax)
cur->pr_pwinmax = i2;
if (i2 < cur->pr_pwinmin || cur->pr_pwinmin == 0)
cur->pr_pwinmin = i2;
break;
case 2:
i1 = i2 = i3 = 0;
sscanf(ptype,"%*s %*s %d%*c %*s %d%*c %*s %d",&i1,&i2,&i3);
cur->pr_psent += i1;
cur->pr_present += i2;
cur->pr_preceived += i3;
break;
default:
break;
}
return (cur);
}
static void fmtime(dsec, buf)
double dsec;
char *buf;
{
long hrs, min, lsec;
if( dsec <= 0 )
{
strcpy(buf, "0" );
return;
}
lsec = fmod(dsec+0.5, 60L);
hrs = dsec / 3600L;
min = ((long)dsec / 60L) % 60L;
if (hrs == 0)
if (min == 0)
sprintf(buf,"%6s%2ld"," ",lsec);
else
sprintf(buf,"%3s%2ld:%02ld"," ",min,lsec);
else
sprintf(buf,"%2ld:%02ld:%02ld",hrs,min,lsec);
}
static void fmbytes(n, buf)
unsigned long n;
char *buf;
{
if ( n == 0 )
{
strcpy( buf, "0.0" );
return;
}
sprintf(buf, "%.1f", (double)n / 1000.0);
}
int chk_config(char *T_conf,int be_quiet, int type)
{
FILE *Conf;
char keywrd[9];
char name[MAXPATHLEN+1];
char *pos1, *pos2;
int i = 0;
int logf = FALSE;
int statf = FALSE;
if ((Conf = fopen(T_conf, "r")) == NULL)
{
if (! be_quiet)
{
puts(" Could not open config");
if (type == 0)
{
puts(" The run will be aborted\n");
return (8);
}
}
else
{
fprintf(stderr,"%s (E) %s %s \n",Pgm_name,
"could not open config:",
T_conf);
if (type != 0)
fprintf(stderr,"%s (W) defaults used for all files\n",
Pgm_name);
else
{
fprintf(stderr,"%s (C) ended due to errors\n",
Pgm_name);
return (8);
}
}
}
else
{
while (fgets(logline, sizeof(logline), Conf))
{
if (logline[0] == '#')
continue;
sscanf(logline,"%8s %s",keywrd,name);
if (0 == strncmp(keywrd,"logfile",7))
{
pos1 = pos2 = name;
for (i=0;(i<=MAXPATHLEN && *pos1 != '\0');pos1++,pos2++,i++)
{
if (*pos1 == '#')
break;
if (*pos1 == '\\')
{
++pos1;
if (*pos1 != '#')
{
puts(" Config error:");
puts(" Found filename continuation; bailing out\n");
exit (8);
}
}
*pos2 = *pos1;
}
*pos2 = '\0';
Tlog = (char *)getmem(strlen(name)+1);
strcpy(Tlog,name);
if (! be_quiet)
printf(" logfile used: %s\n",Tlog);
logf = TRUE;
if (statf)
break;
continue;
}
if (0 == strncmp(keywrd,"statfile",8))
{
pos1 = pos2 = name;
for (i=0;(i<=MAXPATHLEN && *pos1 != '\0');pos1++,pos2++,i++)
{
if (*pos1 == '#')
break;
if (*pos1 == '\\')
{
++pos1;
if (*pos1 != '#')
{
puts(" Config error:");
puts(" Found filename continuation; bailing out\n");
exit (8);
}
}
*pos2 = *pos1;
}
*pos2 = '\0';
Tstat = (char *)getmem(strlen(name)+1);
strcpy(Tstat,name);
if (! be_quiet)
printf(" statfile used: %s\n",Tstat);
statf = TRUE;
if (logf)
break;
continue;
}
}
fclose(Conf);
}
if (! be_quiet)
{
if (! logf)
puts(" logfile used: - default -");
if (! statf)
puts(" statfile used: - default -");
}
return 0;
}
static void hdrprt(char head, int bot)
{
switch(head)
{
case('s'):
if (bot == 0)
{
puts("\nCompact summary:");
puts("----------------");
puts("\
Name of + Files + +------- Bytes/1000 --------+ +----- Time ----+ + Avg CPS +\n\
site in out inbound outbound total inbound outbound in out\n\
-------- ---- ---- --------- --------- --------- -------- -------- ----- -----");
}
else
puts("\
------------------------------------------------------------------------------");
break;
case('f'):
if (bot == 0)
{
puts("\nFile statistics:");
puts("----------------");
puts(" Name of +----------- Inbound -----------+ +---------- Outbound -----------+");
puts(" site files Bytes/1000 xfr time B/sec files Bytes/1000 xfr time B/sec");
puts(" -------- ----- ----------- --------- ----- ----- ----------- --------- -----");
}
else
puts("\
----------------------------------------------------------------------------");
break;
case('c'):
if (bot == 0)
{
puts("\nCall statistics:");
puts("----------------");
puts(" Name of +------- Outbound Calls -------+ +-------- Inbound Calls ------+");
puts(" site succ. failed total time succ. failed total time");
puts(" -------- ------ ------ ------ --------- ------ ------ ------ ---------");
}
else
puts("\
----------------------------------------------------------------------------");
break;
case('e'):
if (bot == 0)
{
puts("\nEfficiency:");
puts("-----------");
puts(" Name of +------ Times inbound/outbound -------+");
puts(" site connected xfr time overhead eff. %");
puts(" -------- --------- --------- --------- ------");
}
else
puts(" -------------------------------------------------");
break;
case('i'):
if (bot == 0)
{
puts("\nEnvironment Information:");
puts("------------------------");
printf(" Default config: %s\n",D_conf == NULL ?
noConf:D_conf);
printf(" Default logfile: %s\n",Tlog);
printf(" Default statfile: %s\n\n",Tstat);
}
break;
case('d'):
if (bot == 0)
{
puts("\n Date coverage of input files:");
puts(" Name of +----- Start -----+ +------ End ------+");
puts(" file date time date time");
puts(" -------- ---------- -------- ---------- --------");
}
break;
case('p'):
if (bot == 0)
{
puts("\nProtocol packet report:");
puts("-----------------------");
puts(" +------- protocol -----+ +--------- Packets ----------+");
puts("Name of packet window ");
puts("site typ min max min max sent resent received");
puts("-------- --- ---- ---- ---- ---- ----------- ------- ----------");
}
else
{
puts("\nProtocol error report:");
puts("----------------------");
puts("Name of +----------------- Error Types --------------------+");
puts("site typ header checksum order rem-reject");
puts("-------- --- ----------- ---------- ----------- ----------");
}
break;
default:
if (bot == 0)
{
puts("\nNo header for this report defined:");
}
else
puts(" ");
break;
}
}