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

Source Code for Module Products.ZenRRD.parsers.Cacti

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2008, 2009 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 or (at your 
 8  # option) any later version as published by the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  import re 
15  # how to parse each value from a Cacti plugin 
16  CacParser = re.compile(r"""([^ :']+|'(.*)'+)\s*:\s*([-+]?[-0-9.]+(?:[Ee][-+]?\d+)?)""") 
17   
18  from Products.ZenUtils.Utils import getExitMessage 
19  from Products.ZenRRD.CommandParser import CommandParser 
20   
21 -class Cacti(CommandParser):
22
23 - def processResults(self, cmd, result):
24 output = cmd.result.output 25 output = output.split('\n')[0].strip() 26 exitCode = cmd.result.exitCode 27 severity = cmd.severity 28 if output.find('|') >= 0: 29 msg, values = output.split('|', 1) 30 msg, values = output, '' 31 32 elif CacParser.search(output): 33 msg, values = '', output 34 35 elif len(cmd.points) == 1: 36 # Special case for plugins that only return one datapoint 37 try: 38 number = float(output) 39 result.values.append( (cmd.points[0], number) ) 40 msg, values = '', output 41 except: 42 msg, values = output, '' 43 44 else: 45 msg, values = output, '' 46 47 msg = msg.strip() or 'Datasource: %s - Code: %s - Msg: %s' % ( 48 cmd.name, exitCode, getExitMessage(exitCode)) 49 if exitCode != 0: 50 if exitCode == 2: 51 severity = min(severity + 1, 5) 52 result.events.append(dict(device=cmd.deviceConfig.device, 53 summary=msg, 54 severity=severity, 55 message=msg, 56 performanceData=values, 57 eventKey=cmd.eventKey, 58 eventClass=cmd.eventClass, 59 component=cmd.component)) 60 61 for parts in CacParser.findall(values): 62 label = parts[0].replace("''", "'") 63 try: 64 value = float(parts[2]) 65 except Exception: 66 value = 'U' 67 for dp in cmd.points: 68 if dp.id == label: 69 result.values.append( (dp, value) ) 70 break
71