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

Source Code for Module Products.ZenModel.DeviceComponent

  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  __doc__="""DeviceComponent 
 12   
 13  All device components inherit from this class 
 14   
 15  """ 
 16   
 17  from Globals import InitializeClass 
 18  from AccessControl import ClassSecurityInfo 
 19  from Acquisition import aq_base 
 20   
 21  import zope.interface 
 22  from Products.ZenModel.interfaces import IIndexed 
 23  from Products.ZenModel.ZenossSecurity import ZEN_VIEW 
 24  from Products.ZenUtils.guid.interfaces import IGloballyIdentifiable 
 25  from Products.ZenRelations.ToManyContRelationship import ToManyContRelationship 
 26  from Lockable import Lockable 
 27  from EventView import EventView 
 28  from Products.ZenUtils.Utils import getAllConfmonObjects 
 29   
30 -class DeviceComponent(Lockable):
31 """ 32 DeviceComponent is a mix-in class for all components of a device. 33 These include LogicalComponent, Software, and Hardware. 34 """ 35 zope.interface.implements(IIndexed, IGloballyIdentifiable) 36 __pychecker__='no-override' 37 event_key = "Component" 38 39 default_catalog = "componentSearch" 40 41 collectors = ('zenperfsnmp', 'zencommand', 'zenwinperf', 42 'zenping') 43 44 security = ClassSecurityInfo() 45 46 perfmonInstance = None 47
48 - def getParentDeviceName(self):
49 """ 50 Return the name of this component's device 51 """ 52 name = "" 53 dev = self.device() 54 if dev: name = dev.getDeviceName() 55 return name
56 hostname = getParentDeviceName 57
58 - def getParentDeviceTitle(self):
59 """ 60 Return the title of this component's device 61 """ 62 title = "" 63 dev = self.device() 64 if dev: title = dev.titleOrId() 65 return title
66
67 - def getParentDeviceUrl(self):
68 """ 69 Return the url of this component's device 70 """ 71 url = "" 72 dev = self.device() 73 if dev: url = dev.absolute_url() 74 return url
75 76 security.declareProtected(ZEN_VIEW, 'name')
77 - def name(self):
78 """ 79 Return the name of this component. Default is id. 80 """ 81 return self.titleOrId()
82 83
84 - def monitored(self):
85 """ 86 Return the monitored status of this component. Default is False. 87 """ 88 return self.monitor
89 90
91 - def getCollectors(self):
92 """ 93 Return list of collectors that want to monitor this component 94 """ 95 return self.collectors
96 97
98 - def getInstDescription(self):
99 """ 100 Return some text that describes this component. Default is name. 101 """ 102 return self.name()
103 104
105 - def getStatus(self, statClass=None):
106 """ 107 Return the status number for this component of class statClass. 108 """ 109 if not self.monitored() \ 110 or not self.device() \ 111 or not self.device().monitorDevice(): return -1 112 if not statClass: statClass = "/Status/%s" % self.meta_type 113 return EventView.getStatus(self, statClass)
114
115 - def getStatusString(self, statClass=None):
116 """ 117 Return a text representation of this component's status 118 """ 119 return self.convertStatus(self.getStatus(statClass=statClass))
120
121 - def getManageIp(self):
122 """ 123 Return the manageIP of the device of this component. 124 """ 125 dev = self.device() 126 if dev: return dev.getManageIp() 127 return ""
128 129
130 - def getNagiosTemplate(self, unused=None):
131 import warnings 132 warnings.warn('anything named nagios is deprecated', DeprecationWarning)
133 134
135 - def getAqProperty(self, prop):
136 """ 137 Get a property from ourself if it exsits then try serviceclass path. 138 """ 139 if getattr(aq_base(self), prop, None) is not None: 140 return getattr(self, prop) 141 classObj = self.getClassObject() 142 if classObj: 143 classObj = classObj.primaryAq() 144 return getattr(classObj, prop)
145 146
147 - def setAqProperty(self, prop, value, type):
148 """ 149 Set a local prop if nessesaary on this service. 150 """ 151 classObj = self.getClassObject() 152 if not classObj: return 153 classObj = classObj.primaryAq() 154 svcval = getattr(classObj, prop) 155 locval = getattr(aq_base(self),prop,None) 156 msg = "" 157 if svcval == value and locval is not None: 158 self._delProperty(prop) 159 msg = "Removed local %s" % prop 160 elif svcval != value and locval is None: 161 self._setProperty(prop, value, type=type) 162 msg = "Set local %s" % prop 163 elif locval is not None and locval != value: 164 self._updateProperty(prop, value) 165 msg = "Update local %s" % prop 166 return msg
167 168
169 - def getClassObject(self):
170 """ 171 If you are going to use acquisition up different class path 172 override this. 173 """ 174 return self.device()
175 176
177 - def getIconPath(self):
178 """ 179 Get the icon for this component. 180 """ 181 return '/zport/dmd/img/icons/noicon.png'
182
183 - def getRRDContextData(self, context):
184 context['comp'] = self 185 context['compId'] = self.id 186 context['compName'] = self.name() 187 if self.device(): 188 context['dev'] = self.device() 189 context['devId'] = self.device().id
190 191
192 - def filterAutomaticCreation(self):
193 """Test if automatic creation (and anchoring into a model) is 194 appropriate for this object. Lets us ignore detectable gunk 195 that's not very interesting to model, like most processes, and 196 loopback network devices, CDROM file systems, etc. 197 198 Returns False if the object should not be added. 199 200 The object will have its full acquisition path, but will not 201 have been added to the database. 202 """ 203 return True
204
206 """Recursively gets every sub component for this component. 207 We use the slow method of just looking at every object 208 underneath this object and yielding those that are DeviceComponents. 209 210 NOTE: this does not use a catalog and is used only to index a catalog. It 211 is painfully inefficient 212 @rtype: generator 213 @return: Every subcomponent directly under this component 214 """ 215 subObjects = getAllConfmonObjects(self) 216 for obj in subObjects: 217 if isinstance(obj, DeviceComponent): 218 yield obj
219 220 InitializeClass(DeviceComponent) 221