Package Products :: Package ZenRRD :: Package parsers :: Module Cacti
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenRRD.parsers.Cacti

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2008, 2009, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  #  
 8  ############################################################################## 
 9   
10   
11  import re 
12  # how to parse each value from a Cacti plugin 
13  CacParser = re.compile(r"""([^ :']+|'(.*)'+)\s*:\s*([-+]?[-0-9.]+(?:[Ee][-+]?\d+)?)""") 
14   
15  from Products.ZenUtils.Utils import getExitMessage 
16  from Products.ZenRRD.CommandParser import CommandParser 
17   
18 -class Cacti(CommandParser):
19
20 - def processResults(self, cmd, result):
21 output = cmd.result.output 22 output = output.split('\n')[0].strip() 23 exitCode = cmd.result.exitCode 24 severity = cmd.severity 25 if output.find('|') >= 0: 26 msg, values = output.split('|', 1) 27 msg, values = output, '' 28 29 elif CacParser.search(output): 30 msg, values = '', output 31 32 elif len(cmd.points) == 1: 33 # Special case for plugins that only return one datapoint 34 try: 35 number = float(output) 36 result.values.append( (cmd.points[0], number) ) 37 msg, values = '', output 38 except: 39 msg, values = output, '' 40 41 else: 42 msg, values = output, '' 43 44 msg = msg.strip() or 'Datasource: %s - Code: %s - Msg: %s' % ( 45 cmd.name, exitCode, getExitMessage(exitCode)) 46 if exitCode != 0: 47 if exitCode == 2: 48 severity = min(severity + 1, 5) 49 result.events.append(dict(device=cmd.deviceConfig.device, 50 summary=msg, 51 severity=severity, 52 message=msg, 53 performanceData=values, 54 eventKey=cmd.eventKey, 55 eventClass=cmd.eventClass, 56 component=cmd.component)) 57 58 for parts in CacParser.findall(values): 59 label = parts[0].replace("''", "'") 60 try: 61 value = float(parts[2]) 62 except Exception: 63 value = 'U' 64 for dp in cmd.points: 65 if dp.id == label: 66 result.values.append( (dp, value) ) 67 break
68