source: people/peter.buschman/backup_monitoring/parsing/parsers/df/_df.py@ 1240

Last change on this file since 1240 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.1 KB
Line 
1import re
2
3from ....builtins import *
4
5from ...exceptions import *
6from ...expressions import *
7from ...streams import *
8
9##
10## df has one record per-line
11##
12def stream(stream, format='df -k'):
13
14 if format in ['df -k']:
15 return NewLineStream(stream, header=1)
16 else:
17 raise ParseError, 'Unknown format %s' % (format)
18
19
20##
21## Parse a df record
22##
23## df -k
24##
25def parse(record, format='df -k', version=None, tz=None):
26
27 fs = ExtendedDict()
28
29 if format == 'df -k':
30
31 regex = re.compile('^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)%\s+(\S+).*$')
32
33 try:
34
35 match = regex.match(record)
36
37 fs['device'] = match.group(1)
38 fs['kbytes'] = long(match.group(2))
39 fs['used'] = long(match.group(3))
40 fs['avail'] = long(match.group(4))
41 fs['pct_full'] = int(match.group(5))
42 fs['mountpoint'] = match.group(6)
43
44 return fs
45
46 except Exception, e:
47
48 raise ParseError, e
49
50 else:
51
52 raise ParseError, 'Unknown format %s' % (format)
Note: See TracBrowser for help on using the repository browser.