1
2
3
4
5
6
7
8
9
10
11
12
13
14 import re
15
16 NagParser = re.compile(r"""([^ =']+|'(.*)'+)=([-0-9.eE]+)([^;]*;?){0,5}""")
17
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
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 CacParser.search(output):
33 msg, values = '', output
34 else:
35 msg, values = output, ''
36 msg = msg.strip() or 'Cmd: %s - Code: %s - Msg: %s' % (
37 cmd.command, exitCode, getExitMessage(exitCode))
38 if exitCode != 0:
39 if exitCode == 2:
40 severity = min(severity + 1, 5)
41 result.events.append(dict(device=cmd.deviceConfig.device,
42 summary=msg,
43 severity=severity,
44 message=msg,
45 performanceData=values,
46 eventKey=cmd.eventKey,
47 eventClass=cmd.eventClass,
48 component=cmd.component))
49
50 for value in values.split(' '):
51 if value.find('=') > 0:
52 parts = NagParser.match(value)
53 else:
54 parts = CacParser.match(value)
55 if not parts: continue
56 label = parts.group(1).replace("''", "'")
57 try:
58 value = float(parts.group(3))
59 except:
60 value = 'U'
61 for dp in cmd.points:
62 if dp.id == label:
63 result.values.append( (dp, value) )
64 break
65