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.Utils import getObjByPath
19 from Products.ZenUtils.ZenTales import talesCompile, getEngine
20
21
29
30
32
33 meta_type = 'GraphReportElement'
34
35 deviceId = ''
36 componentPath = ''
37 graphId = ''
38 sequence = 0
39 summary = ('Device: ${dev/titleOrId}\n'
40 ' \n'
41 'Component: ${comp/name}\n'
42 ' \n'
43 'Graph: ${graph/id}\n')
44 comments = ('Device: ${dev/titleOrId}<br />\n'
45 'Component: ${comp/name}<br />\n'
46 '${graph/id}')
47
48 _properties = ZenModelRM._properties + (
49 {'id':'deviceId', 'type':'string', 'mode':'w'},
50 {'id':'componentPath', 'type':'string', 'mode':'w'},
51 {'id':'graphId', 'type':'string', 'mode':'w'},
52 {'id':'sequence', 'type':'int', 'mode':'w'},
53 {'id':'summary', 'type':'text', 'mode':'w'},
54 {'id':'comments', 'type':'text', 'mode':'w'},
55 )
56
57 _relations = ZenModelRM._relations + (
58 ("report",
59 ToOne(ToManyCont,"Products.ZenModel.GraphReport", "elements")),
60 )
61
62 factory_type_information = (
63 {
64 'immediate_view' : 'editGraphReportElement',
65 'actions' :
66 (
67 {'name' : 'Edit',
68 'action' : 'editGraphReportElement',
69 'permissions' : ("Manage DMD",),
70 },
71 )
72 },
73 )
74
75 security = ClassSecurityInfo()
76
78 dev = self.getDevice()
79 if not dev:
80 return 'Device %s could not be found' % self.deviceId
81 comp = self.getComponent()
82 if not comp:
83 return 'Component %s could not be found for %s' % (
84 self.componentPath, self.deviceId)
85 graph = self.getGraphDef()
86 if not graph:
87 return 'Graph %s could not be found for %s' % (
88 self.graphId, self.deviceId)
89 compiled = talesCompile('string:' + text)
90 e = {'dev':dev, 'device': dev,
91 'comp': comp, 'component':comp,
92 'graph': graph}
93 try:
94 result = compiled(getEngine().getContext(e))
95 if isinstance(result, Exception):
96 result = 'Error: %s' % str(result)
97 except Exception, e:
98 result = 'Error: %s' % str(e)
99 return result
100
101
103 ''' Returns tales-evaluated summary
104 '''
105 return self.talesEval(self.summary)
106
111
112
115
116
125
126
136
137
141
142
153
154
155 InitializeClass(GraphReportElement)
156