1
2
3
4
5
6
7
8
9
10
11
12
13
14 import re
15
16 CacParser = re.compile(r"""([^ :']+|'(.*)'+):([-0-9.]+)""")
17
18 from Products.ZenUtils.Utils import getExitMessage
19 from Products.ZenRRD.CommandParser import CommandParser
20
21 -class Cacti(CommandParser):
22
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
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 'Cmd: %s - Code: %s - Msg: %s' % (
48 cmd.command, 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 value in values.split():
62 parts = CacParser.match(value)
63
64 if not parts: continue
65 label = parts.group(1).replace("''", "'")
66 try:
67 value = float(parts.group(3))
68 except:
69 value = 'U'
70 for dp in cmd.points:
71 if dp.id == label:
72 result.values.append( (dp, value) )
73 break
74