source: people/peter.buschman/backup_monitoring/parsing/parsers/dsmadmc/_dsmadmc.py@ 1056

Last change on this file since 1056 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.1 KB
Line 
1import re
2
3from ....builtins import *
4
5from ...exceptions import *
6from ...expressions import *
7from ...streams import *
8from ...autotype import *
9
10re_error = re.compile('^AN[RS]\d+E .*$')
11re_no_match_found = re.compile('^ANR2034E SELECT: No match found using this criteria.*$')
12re_session_rejected = re.compile('^ANS1017E Session rejected: TCP/IP connection failure.*$')
13re_unable_to_establish_session = re.compile('ANS8023E Unable to establish session with server.*$')
14
15##
16## dsmadmc records
17##
18def stream(stream, format='dsmadmc -dataonly=yes -displaymode=list'):
19
20 if format in ['dsmadmc -dataonly=yes -displaymode=list']:
21 return BlankLineStream(stream, header=0)
22 else:
23 raise ParseError, 'Unknown format %s' % (format)
24
25
26##
27## Parse a dsmadmc record
28##
29## dsmadmc -dataonly=yes -displaymode=list
30##
31def parse(record, format='dsmadmc -dataonly=yes -displaymode=list', version=None, tz=None):
32
33 obj = ExtendedDict()
34 re_pair = re.compile('^\s*([^:]+):\s+(.*)$')
35
36 if format == 'dsmadmc -dataonly=yes -displaymode=list':
37
38 try:
39
40 for line in record:
41
42 if re_error.match(line):
43 return None
44
45 #if re_no_match_found.match(line):
46 # return None
47
48 #if re_session_rejected(line):
49 # return None
50
51 #if re_unable_to_establish_session:
52 # return None
53
54 match = re_pair.match(line)
55
56 key = match.group(1)
57 value = match.group(2)
58 key = key.lower()
59 key = key.replace(' ', '_')
60 key = key.replace('/', '_')
61 key = key.replace('\\', '_')
62 key = key.replace('?', '')
63 key = key.replace('.', '')
64
65 value = autotype(value, tz=tz)
66
67 #if value == '':
68 # value = None
69
70 obj[key] = value
71
72 return obj
73
74 except Exception, e:
75
76 raise ParseError, e
77
78 else:
79
80 raise ParseError, 'Unknown format %s' % (format)
81
82
Note: See TracBrowser for help on using the repository browser.