1
2
3
4
5
6
7
8
9
10
11
12
13
14 from Globals import InitializeClass
15 from AccessControl import ClassSecurityInfo
16 from ZenModelRM import ZenModelRM
17 from Products.ZenRelations.RelSchema import *
18 from Products.ZenUtils.ZenTales import talesCompile, getEngine
19
20
28
29
31
32 meta_type = 'GraphReportElement'
33
34 deviceId = ''
35 componentPath = ''
36 graphId = ''
37 sequence = 0
38 summary = ('Device: ${dev/id}\n'
39 ' \n'
40 'Component: ${comp/id}\n'
41 ' \n'
42 'Graph: ${graph/id}\n')
43 comments = ('Device: ${dev/id}<br />\n'
44 'Component: ${comp/id}<br />\n'
45 '${graph/id}')
46
47 _properties = ZenModelRM._properties + (
48 {'id':'deviceId', 'type':'string', 'mode':'w'},
49 {'id':'componentPath', 'type':'string', 'mode':'w'},
50 {'id':'graphId', 'type':'string', 'mode':'w'},
51 {'id':'sequence', 'type':'int', 'mode':'w'},
52 {'id':'summary', 'type':'text', 'mode':'w'},
53 {'id':'comments', 'type':'text', 'mode':'w'},
54 )
55
56 _relations = ZenModelRM._relations + (
57 ("report",
58 ToOne(ToManyCont,"Products.ZenModel.GraphReport", "elements")),
59 )
60
61 factory_type_information = (
62 {
63 'immediate_view' : 'editGraphReportElement',
64 'actions' :
65 (
66 {'name' : 'Edit',
67 'action' : 'editGraphReportElement',
68 'permissions' : ("Manage DMD",),
69 },
70 )
71 },
72 )
73
74 security = ClassSecurityInfo()
75
77 dev = self.getDevice()
78 if not dev:
79 return 'Device %s could not be found' % self.deviceId
80 comp = self.getComponent()
81 if not comp:
82 return 'Component %s could not be found for %s' % (
83 self.componentPath, self.deviceId)
84 graph = self.getGraphDef()
85 if not graph:
86 return 'Graph %s could not be found for %s' % (
87 self.graphId, self.deviceId)
88 compiled = talesCompile('string:' + text)
89 e = {'dev':dev, 'device': dev,
90 'comp': comp, 'component':comp,
91 'graph': graph}
92 try:
93 result = compiled(getEngine().getContext(e))
94 if isinstance(result, Exception):
95 result = 'Error: %s' % str(result)
96 except Exception, e:
97 result = 'Error: %s' % str(e)
98 return result
99
100
102 ''' Returns tales-evaluated summary
103 '''
104 return self.talesEval(self.summary)
105
110
111
114
115
124
125
129
130
141
142
143 InitializeClass(GraphReportElement)
144