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