- \r
- free(restor);\r
-}\r
-\r
-/* == This function strips extra characters after IP address and stores it = */\r
-\r
-void parse_ip(char *str)\r
-{\r
- char *ptr,*ipaddr=NULL,*ipname=NULL,*lmsid=NULL;\r
-\r
- ptr=strchr(str,'{');\r
- if(ptr)\r
- {\r
- lmsid=++ptr;\r
- while(*ptr && *ptr!='}')\r
- {\r
- ptr++;\r
- }\r
- *ptr=0;\r
- }\r
- \r
- ptr=str;\r
- while(*ptr && *ptr!=' ' && *ptr!=9)\r
- {\r
- ptr++;\r
- }\r
- \r
- *ptr=0;\r
- ipaddr=str;\r
- ptr++;\r
- while(*ptr && (*ptr==' ' || *ptr==9))\r
- {\r
- ptr++;\r
- }\r
- ipname=ptr; \r
- while(*ptr && *ptr!=' ' && *ptr!=9)\r
- {\r
- ptr++;\r
- }\r
- *ptr=0;\r
-\r
- if_exists(ip,ips,eq(ip->addr,ipaddr));\r
- else\r
- {\r
- TheIP();\r
- }\r
- ip->addr=ipaddr;\r
- ip->name=ipname;\r
- if(lmsid)\r
- {\r
- ip->lmsid=atoi(lmsid);\r
- found_lmsid=1;\r
- }\r
-}\r
-\r
-char *parse_datafile_line(char *str)\r
-{\r
- char *ptr=strchr(str,' ');\r
-\r
- if(ptr)\r
- {\r
- *ptr=0;\r
- ptr++;\r
- return ptr;\r
- } \r
- else \r
- {\r
- return NULL;\r
- }\r
-}\r
-\r
-struct IpLog\r
-{\r
- char *name;\r
- long traffic;\r
- long guaranted;\r
- int i;\r
- int lmsid;\r
- long l;\r
- list(IpLog);\r
-} *iplog,*iplogs;\r
-\r
-void parse_ip_log(int argc, char **argv) \r
-{\r
- char *month, *year, *str, *name="(undefined)", *ptr, *ptr2, *filename;\r
- long traffic=0l, traffic_month, total=0, guaranted;\r
- int col, col2, y_ok, m_ok, accept_month, i=1, any_month=0, lmsid;\r
- char mstr[4], ystr[5];\r
- FILE *f; \r
- string(str,STRLEN);\r
- string(filename,STRLEN);\r
-\r
- if(argv[1][1]=='l') /* -l */\r
- {\r
- if(argc<4)\r
- {\r
- puts("Missing parameter(s)!\nUsage: prometheus -l Mmm YYYY (Mmm=Jan-Dec or Year, YYYY=year)");\r
- exit(-1);\r
- }\r
- else\r
- {\r
- month=argv[2];\r
- if(eq(month,"Year")) any_month=1;\r
- year=argv[3];\r
- }\r
- }\r
- else\r
- { \r
- time_t t = time(NULL) - 3600*24 ; /* yesterday's timestamp*/\r
- struct tm *timep = localtime(&t); \r
-\r
- if(argv[1][1]=='m') /* -m yestarday - month */\r
- {\r
- strftime(mstr, 4, "%b", timep);\r
- month=mstr;\r
- strftime(ystr, 5, "%Y", timep);\r
- year=ystr; \r
- }\r
- else /* -y yesterday - year */\r
- {\r
- month="Year";\r
- any_month=1;\r
- strftime(ystr, 5, "%Y", timep);\r
- year=ystr;\r
- }\r
- }\r
- printf("Analysing traffic for %s %s ...\n",month,year);\r
-\r
- /* sorry... next release of C<<1 header file will include for_path_files(name,path) { } macro */\r
- sprintf(str,"%s %s/",ls,log_dir);\r
- shell(str);\r
- input(str,STRLEN) \r
- {\r
- if(strstr(str,".log"))\r
- {\r
- ptr=strrchr(str,'\n');\r
- if(ptr) *ptr='\0';\r
- sprintf(filename,"%s/%s",log_dir,str);\r
- printf("Parsing %s ...",filename);\r
- accept_month=0;\r
- traffic_month=0;\r
- guaranted=0;\r
- lmsid=-1;\r
- parse(filename)\r
- {\r
- y_ok=m_ok=0; \r
- valid_columns(ptr,_,'\t',col) switch(col)\r
- {\r
- case 2: name = ptr;break;\r
- case 3: traffic = atol(ptr);break;\r
- /* column number - was 7, now 11...*/\r
- case 7:\r
- case 8:\r
- case 9:\r
- case 10:\r
- case 11: if (isalpha(*ptr)) /* character, not numeric string = date, just one*/\r
- {\r
- valid_columns(ptr2,ptr,' ',col2) switch(col2)\r
- {\r
- case 2: if(any_month || eq(ptr2,month)) m_ok = 1; break;\r
- case 5: if(eq(ptr2,year)) y_ok = 1; break;\r
- }\r
- }\r
- else\r
- {\r
- if(col == 7) guaranted = atol(ptr);\r
- if(col == 10) lmsid = atoi(ptr);\r
- }\r
- }\r
- \r
- if(y_ok && m_ok) \r
- {\r
- traffic_month += traffic;\r
- accept_month = 1;\r
- }\r
- }\r
- done;\r