1 | import re
|
---|
2 |
|
---|
3 | import time
|
---|
4 | import datetime
|
---|
5 | import pytz
|
---|
6 |
|
---|
7 | from ....builtins import *
|
---|
8 |
|
---|
9 | from ...exceptions import *
|
---|
10 | from ...expressions import *
|
---|
11 | from ...autotype import *
|
---|
12 | from ...streams import *
|
---|
13 |
|
---|
14 | ##
|
---|
15 | ## bperror has records separated by blank lines
|
---|
16 | ##
|
---|
17 | def stream(stream, format='bperror -L'):
|
---|
18 |
|
---|
19 | if format in ['bperror -L']:
|
---|
20 | return BlankLineStream(stream, header=1)
|
---|
21 | else:
|
---|
22 | raise ParseError, 'Unknown format %s' % (format)
|
---|
23 |
|
---|
24 |
|
---|
25 | ##
|
---|
26 | ## Parse a bperror record
|
---|
27 | ##
|
---|
28 | ## bperror -L
|
---|
29 | ##
|
---|
30 | def parse(record, format='bperror -L', version=None, tz=None):
|
---|
31 |
|
---|
32 | re_line1 = re.compile('^(\d\d/\d\d/\d\d\d\d \d\d:\d\d:\d\d)\s+V(\S+)\s+S:(\S+)\s+C:(\S+)\s+J:(\S+)\s+\(U:(\S+),(\S+)\)$')
|
---|
33 | re_line2 = re.compile('^ (\w+)\((\w+)\) (\w+)\((\w+)\) (\w+)$')
|
---|
34 |
|
---|
35 | strptime_format = '%m/%d/%Y %H:%M:%S'
|
---|
36 |
|
---|
37 | error = ExtendedDict()
|
---|
38 |
|
---|
39 | if format == 'bperror -L':
|
---|
40 |
|
---|
41 | try:
|
---|
42 |
|
---|
43 | line1 = record[0]
|
---|
44 |
|
---|
45 | match = re_line1.match(line1)
|
---|
46 |
|
---|
47 | Datetime = datetime.datetime.strptime(match.group(1), strptime_format).replace(tzinfo=tz)
|
---|
48 | nbu_version = match.group(2)
|
---|
49 | server = match.group(3)
|
---|
50 | client = match.group(4)
|
---|
51 | job_id = int(match.group(5))
|
---|
52 | job_group_id = int(match.group(6))
|
---|
53 | unused_field = match.group(7)
|
---|
54 |
|
---|
55 | line2 = record[1]
|
---|
56 | match = re_line2.match(line2)
|
---|
57 | severity_name = match.group(1)
|
---|
58 | severity_code = int(match.group(2), 0)
|
---|
59 | type_name = match.group(3)
|
---|
60 | type_code = int(match.group(4), 0)
|
---|
61 | who = match.group(5)
|
---|
62 |
|
---|
63 | error.datetime = Datetime
|
---|
64 | error.nbu_version = nbu_version
|
---|
65 | error.server = server
|
---|
66 | error.client = client
|
---|
67 | error.job_id = job_id
|
---|
68 | error.job_group_id = job_group_id
|
---|
69 | error.unused_field = unused_field
|
---|
70 | error.severity_name = severity_name
|
---|
71 | error.severity_code = severity_code
|
---|
72 | error.type_name = type_name
|
---|
73 | error.type_code = type_code
|
---|
74 | error.who = who
|
---|
75 |
|
---|
76 | message = record[2][2:]
|
---|
77 |
|
---|
78 | for line in record[3:]:
|
---|
79 | message = '%s%s' % (message, line[1:])
|
---|
80 |
|
---|
81 | error.message = message
|
---|
82 |
|
---|
83 | return error
|
---|
84 |
|
---|
85 | except Exception, e:
|
---|
86 |
|
---|
87 | for line in record:
|
---|
88 | print line
|
---|
89 |
|
---|
90 | raise ParseError, e
|
---|
91 |
|
---|
92 | else:
|
---|
93 |
|
---|
94 | raise ParseError, 'Unknown format %s' % (format)
|
---|