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

Source Code for Module ZenRRD.parsers.Auto

 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  import re 
15  # how to parse each value from a nagios command 
16  NagParser = re.compile(r"""([^ =']+|'(.*)'+)=([-0-9.eE]+)([^;]*;?){0,5}""") 
17  # how to parse each value from a cacti command 
18  CacParser = re.compile(r"""([^ :']+|'(.*)'+):([-0-9.]+)""") 
19   
20  from Products.ZenUtils.Utils import getExitMessage 
21  from Products.ZenRRD.CommandParser import CommandParser 
22   
23 -class Auto(CommandParser):
24
25 - def processResults(self, cmd, result):
26 output = cmd.result.output 27 output = output.split('\n')[0].strip() 28 exitCode = cmd.result.exitCode 29 severity = cmd.severity 30 if output.find('|') >= 0: 31 msg, values = output.split('|', 1) 32 elif cmd.parser == 'Nagios': 33 msg, values = output, '' 34 elif CacParser.search(output): 35 msg, values = '', output 36 else: 37 msg, values = output, '' 38 msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % ( 39 cmd.command, exitCode, getExitMessage(exitCode)) 40 if exitCode == 0: 41 severity = 0 42 elif exitCode == 2: 43 severity = min(severity + 1, 5) 44 result.events.append(dict(device=cmd.deviceConfig.device, 45 summary=msg, 46 severity=severity, 47 message=msg, 48 performanceData=values, 49 eventKey=cmd.eventKey, 50 eventClass=cmd.eventClass, 51 component=cmd.component)) 52 53 for value in values.split(' '): 54 if value.find('=') > 0: 55 parts = NagParser.match(value) 56 else: 57 parts = CacParser.match(value) 58 if not parts: continue 59 label = parts.group(1).replace("''", "'") 60 try: 61 value = float(parts.group(3)) 62 except: 63 value = 'U' 64 for dp in cmd.points: # FIXME: linear search 65 if dp.id == label: 66 result.values.append( (dp, value) ) 67 break
68