source: people/peter.buschman/backup_monitoring/parsing/parsers/bpplclients/_bpplclients.py@ 976

Last change on this file since 976 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: 1.3 KB
Line 
1import re
2
3from ....builtins import *
4
5from ...exceptions import *
6from ...expressions import *
7from ...streams import *
8
9re_cannot_connect_on_socket = re.compile('^cannot connect on socket.*$')
10
11##
12## bpplclients has one record per-line
13##
14def stream(stream, format='bpplclients -L'):
15
16 if format in ['bpplclients -L']:
17 return NewLineStream(stream, header=0)
18 else:
19 raise ParseError, 'Unknown format %s' % (format)
20
21
22##
23## Parse a bpplclients record
24##
25## bpplclients -allunique -L
26##
27def parse(record, format='bpplclients -L', version=None, tz=None):
28
29 client = ExtendedDict()
30
31 if format == 'bpplclients -L':
32
33 if re_cannot_connect_on_socket.match(record):
34 return None
35
36 regex = re.compile('^Client/HW/OS/Pri:\s+(\S+)\s+(\S+)\s+(\S+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(\S+)$')
37
38 try:
39
40 match = regex.match(record)
41
42 client['client'] = match.group(1)
43 client['name'] = match.group(1)
44 client['hw'] = match.group(2)
45 client['os'] = match.group(3)
46 client['pri'] = int(match.group(4))
47
48 return client
49
50 except Exception, e:
51
52 raise ParseError, e
53
54 else:
55
56 raise ParseError, 'Unknown format %s' % (format)
Note: See TracBrowser for help on using the repository browser.