source: people/peter.buschman/backup_monitoring/parsing/parsers/bperror/_bperror.py

Last change on this file was 976, checked in by peter, on Dec 6, 2011 at 10:19:33 AM

Raw checkin of current NetBackup / TSM parsing code.

File size: 2.7 KB
Line 
1import re
2
3import time
4import datetime
5import pytz
6
7from ....builtins import *
8
9from ...exceptions import *
10from ...expressions import *
11from ...autotype import *
12from ...streams import *
13
14##
15## bperror has records separated by blank lines
16##
17def 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##
30def 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)
Note: See TracBrowser for help on using the repository browser.