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 severity = 0
51 elif exitCode == 2:
52 severity = min(severity + 1, 5)
53 result.events.append(dict(device=cmd.deviceConfig.device,
54 summary=msg,
55 severity=severity,
56 message=msg,
57 performanceData=values,
58 eventKey=cmd.eventKey,
59 eventClass=cmd.eventClass,
60 component=cmd.component))
61
62 for value in values.split():
63 parts = CacParser.match(value)
64
65 if not parts: continue
66 label = parts.group(1).replace("''", "'")
67 try:
68 value = float(parts.group(3))
69 except:
70 value = 'U'
71 for dp in cmd.points:
72 if dp.id == label:
73 result.values.append( (dp, value) )
74 break
75