Package ZenRRD :: Module ComponentCommandParser
[hide private]
[frames] | no frames]

Source Code for Module ZenRRD.ComponentCommandParser

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2008, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  from Products.ZenRRD.CommandParser import CommandParser 
15  import re 
16  from pprint import pformat 
17  import logging 
18   
19  log = logging.getLogger("zen.ComponentCommandParser") 
20   
21 -class ComponentCommandParser(CommandParser):
22 23 componentSplit = '\n' 24 25 componentScanner = '' 26 27 scanners = () 28 29 componentScanValue = 'id' 30
31 - def dataForParser(self, context, dp):
32 return dict(componentScanValue = getattr(context, self.componentScanValue))
33
34 - def processResults(self, cmd, result):
35 36 # Map datapoints by data you can find in the command output 37 ifs = {} 38 for dp in cmd.points: 39 points = ifs.setdefault(dp.data['componentScanValue'], {}) 40 points[dp.id] = dp 41 42 # split data into component blocks 43 parts = cmd.result.output.split(self.componentSplit) 44 45 for part in parts: 46 # find the component match 47 match = re.search(self.componentScanner, part) 48 if not match: continue 49 component = match.groupdict()['component'].strip() 50 points = ifs.get(component, None) 51 if not points: continue 52 53 # find any datapoints 54 for search in self.scanners: 55 match = re.search(search, part) 56 if match: 57 for name, value in match.groupdict().items(): 58 dp = points.get(name, None) 59 if dp is not None: 60 if value in ('-', ''): value = 0 61 result.values.append( (dp, float(value) ) ) 62 63 log.debug(pformat(result)) 64 return result
65