Package Products :: Package ZenModel :: Module GraphReportElement
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenModel.GraphReportElement

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  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 
19 20 21 @deprecated 22 -def manage_addGraphReportElement(context, id, REQUEST = None):
23 """make a GraphReportElement 24 """ 25 element = GraphReportElement(id) 26 context._setObject(element.id, element) 27 if REQUEST is not None: 28 audit('UI.Report.AddElement', context, element.id) 29 REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')
30
31 32 -class GraphReportElement(ZenModelRM):
33 34 meta_type = 'GraphReportElement' 35 36 deviceId = '' 37 componentPath = '' 38 graphId = '' 39 sequence = 0 40 summary = ('Device: ${dev/titleOrId}\n' 41 '&nbsp;&nbsp;\n' 42 'Component: ${comp/name}\n' 43 '&nbsp;&nbsp;\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
78 - def talesEval(self, text):
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
103 - def getSummary(self):
104 ''' Returns tales-evaluated summary 105 ''' 106 return self.talesEval(self.summary)
107
108 - def getComments(self):
109 ''' Returns tales-evaluated comments 110 ''' 111 return self.talesEval(self.comments)
112 113
114 - def getDevice(self):
115 return self.dmd.Devices.findDevice(self.deviceId)
116 117
118 - def getComponent(self):
119 component = self.getDevice() 120 for part in self.componentPath.split('/'): 121 if part: 122 component = getattr(component, part, None) 123 if not component: 124 break 125 return component
126 127
128 - def getComponentName(self):
129 if self.componentPath: 130 try: 131 dev = self.getDevice() 132 if not dev: 133 return 'Not Found' 134 name = getObjByPath(dev, self.componentPath).name 135 return callable(name) and name() or name 136 except KeyError: 137 return 'Not Found' 138 else: 139 return ''
140 141
142 - def getGraphDef(self):
143 graphDef = self.getComponent().getGraphDef(self.graphId) 144 return graphDef
145 146
147 - def getGraphUrl(self, drange=None):
148 ''' Return the url for the graph 149 ''' 150 url = '' 151 component = self.getComponent() 152 if component: 153 graph = component.getGraphDef(self.graphId) 154 if graph: 155 url = component.getGraphDefUrl(graph, drange, graph.rrdTemplate()) 156 return url
157 158 159 InitializeClass(GraphReportElement) 160