source: WAeUP_SysConf/logging/trunk/usr/local/lib/zevents.awk @ 2826

Last change on this file since 2826 was 2826, checked in by uli, 17 years ago

Added logging scripts and configs.

File size: 3.6 KB
Line 
1## zevents.awk -- analyse Zope logs
2##
3## Parse Zope-Events logfile-data and extract fields. Output
4## as CSV or SQL format.
5##
6## (c) 2006 Uli Fouquet
7##
8## Syntax: awk [-v SQL=0|1] [-v TRACEBACK=0|1] -f zevents.awk <input-file>
9##
10## Options:
11##
12## -v SQL if SQL is set, SQL output will be generated.
13##              Othwewise you will get CSV output (default:0)
14##
15## -v TRACEBACK if this option is set to '0', tracebacks will
16##              not be included in output (default: 1)
17##
18## This Script is GPL software.
19##
20
21function quoted( STRING ) {
22  #gsub("\"", "\\\"", STRING);
23  gsub("\"", "'", STRING);
24  #gsub("'", "\\'", STRING);
25  return STRING
26}
27function quoteds( STRING ) {
28  #gsub("\"", "\\\"", STRING);
29  #gsub("\"", "'", STRING);
30  gsub("'", "\"", STRING);
31  return STRING
32}
33
34BEGIN {
35  RS="------\n"; FS="\n";
36
37  if ( TRACEBACK != "0" ) {
38    tbout=",\"TRACEBACK\"";
39  }
40
41  if ( SQL != "1" ) {
42    print "\"ID\",\"DATE\",\"TIME\",\"LOGLEVEL\",\"MSG_SRC\",\"MSG_TEXT\",\"ERR_TYPE\",\"ERR_MSG\"" tbout;
43  }
44}
45{
46  rest = $1;
47  pos = index( rest, " ");
48  timestamp = substr(rest, 0, pos-1);
49  sub("T", " ", timestamp );
50
51  datestr = "";
52  timestr = "";
53
54  if ( length( timestamp ) != 0 ) {
55    if ( split( timestamp, tsarray, " " ) == 2 )
56      {
57        datestr = tsarray[1];
58        timestr = tsarray[2];
59      }
60  }
61
62  if ( datestr == "" ) {
63    next;
64  }
65
66
67## Create a non-unique ID. DBs may create a primary key of date/time
68## and ID.
69  myid=sprintf("%07d", NR );
70
71## loglevel...
72  rest = substr( rest, pos+1 );
73  pos = index( rest, " ");
74  loglevel =  substr(rest, 0, pos-1);
75
76## exceptsrc...
77  rest = substr( rest, pos+1 );
78  pos = index( rest, " ");
79  exceptsrc =  substr(rest, 0, pos-1);
80
81## msg...
82  msg = substr( rest, pos+1 );
83
84## traceback...
85  traceback = "";
86  for ( i = 2; i <= NF; i++ ) {
87    traceback = traceback "\n" $i;
88  }
89  traceback = substr( traceback, 2 );
90
91
92## err_type, err_msg...
93  err_type = "";
94  err_msg  = "";
95  if ( loglevel != "INFO" ) {
96    if ( NF > 2 && index( $(NF-1), ":" ) != 0 ) {
97      pos = index( $(NF-1), ":" );
98      err_type = substr($(NF-1), 0, pos-1);
99      err_msg  = substr($(NF-1), pos+1);
100    }
101  }
102
103  if ( err_type == "" && loglevel == "ERROR" && index( traceback, "notFoundError" ) != 0 ) {
104    err_type = "notFoundError";
105    err_msg = msg;
106  }
107
108  if ( err_type == "" && exceptsrc == "ZPublisher.Conflict" ) {
109    err_type = "ConflictError";
110    err_msg = ""; #msg;
111  }
112
113## output...
114  if ( SQL == "1" ) {
115    ## Output SQL...
116
117    if ( TRACEBACK != "0" ) {
118      output = sprintf( "INSERT INTO \"ZEVENTS\" (\"ID\",\"DATESTR\",\"TIMESTR\",\"LOGLEVEL\",\"MSG_SRC\",\"MSG\",\"ERR_TYPE\",\"ERR_MSG\",\"TRACEBACK\") VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s');",
119                        quoteds(myid),
120                        quoteds(datestr), quoteds(timestr),
121                        quoteds(loglevel), quoteds(exceptsrc),
122                        quoteds(msg), quoteds(err_type),
123                        quoteds(err_msg), quoteds(traceback) );
124    } else {
125      output = sprintf( "INSERT INTO \"ZEVENTS\" (\"ID\",\"DATESTR\",\"TIMESTR\",\"LOGLEVEL\",\"MSG_SRC\",\"MSG\",\"ERR_TYPE\",\"ERR_MSG\") VALUES ('%s','%s','%s','%s','%s','%s','%s','%s');",
126                        quoteds(myid),
127                        quoteds(datestr), quoteds(timestr),
128                        quoteds(loglevel), quoteds(exceptsrc),
129                        quoteds(msg), quoteds(err_type),
130                        quoteds(err_msg) );
131    }
132  } else {
133    output = sprintf( "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"",
134                      quoted(myid),
135                      quoted(datestr), quoted(timestr),
136                      quoted(loglevel), quoted(exceptsrc),
137                      quoted(msg), quoted(err_type), quoted(err_msg) );
138    if ( TRACEBACK != "0" ) {
139      output = sprintf( "%s,\"%s\"" , output, quoted( traceback ));
140    }
141  }
142  print output;
143}
Note: See TracBrowser for help on using the repository browser.