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

Source Code for Module ZenModel.DeviceComponent

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 11  # 
 12  ########################################################################### 
 13   
 14  __doc__="""DeviceComponent 
 15   
 16  All device components inherit from this class 
 17   
 18  $Id: DeviceComponent.py,v 1.1 2004/04/06 21:05:03 edahl Exp $""" 
 19   
 20  __version__ = "$Revision: 1.1 $"[11:-2] 
 21   
 22  from Globals import InitializeClass 
 23  from AccessControl import ClassSecurityInfo 
 24  from Acquisition import aq_base 
 25  from Lockable import Lockable 
 26   
27 -class DeviceComponent(Lockable):
28 """ 29 DeviceComponent is a mix-in class for all components of a device. 30 These include LogicalComponent, Software, and Hardware. 31 """ 32 __pychecker__='no-override' 33 event_key = "Component" 34 35 default_catalog = "componentSearch" 36 37 collectors = ('zenperfsnmp', 'zencommand', 'zenwinperf') 38 39 security = ClassSecurityInfo() 40 41 perfmonInstance = None 42
43 - def getParentDeviceName(self):
44 """ 45 Return the name of this component's device 46 """ 47 name = "" 48 dev = self.device() 49 if dev: name = dev.getDeviceName() 50 return name
51 hostname = getParentDeviceName 52 53
54 - def getParentDeviceUrl(self):
55 """ 56 Return the url of this component's device 57 """ 58 url = "" 59 dev = self.device() 60 if dev: url = dev.absolute_url() 61 return url
62 63
64 - def name(self):
65 """ 66 Return the name of this component. Default is id. 67 """ 68 return self.id
69 70
71 - def monitored(self):
72 """ 73 Return the monitored status of this component. Default is False. 74 """ 75 return self.monitor
76 77
78 - def getCollectors(self):
79 """ 80 Return list of collectors that want to monitor this component 81 """ 82 return self.collectors
83 84
85 - def getInstDescription(self):
86 """ 87 Return some text that describes this component. Default is name. 88 """ 89 return self.name()
90 91
92 - def getStatus(self, statClass=None):
93 """ 94 Return the status number for this component of class statClass. 95 """ 96 if not self.monitored() \ 97 or not self.device() \ 98 or not self.device().monitorDevice(): return -1 99 if not statClass: statClass = "/Status/%s" % self.meta_type 100 return self.getEventManager().getComponentStatus( 101 self.getParentDeviceName(), self.name(), statclass=statClass)
102 103
104 - def getStatusString(self, statClass=None):
105 """ 106 Return a text representation of this component's status 107 """ 108 return self.convertStatus(self.getStatus(statClass))
109 110
111 - def getManageIp(self):
112 """ 113 Return the manageIP of the device of this component. 114 """ 115 dev = self.device() 116 if dev: return dev.getManageIp() 117 return ""
118 119
120 - def getNagiosTemplate(self, unused=None):
121 import warnings 122 warnings.warn('anything named nagios is deprecated', DeprecationWarning)
123 124
125 - def getAqProperty(self, prop):
126 """ 127 Get a property from ourself if it exsits then try serviceclass path. 128 """ 129 if getattr(aq_base(self), prop, None) is not None: 130 return getattr(self, prop) 131 classObj = self.getClassObject() 132 if classObj: 133 classObj = classObj.primaryAq() 134 return getattr(classObj, prop)
135 136
137 - def setAqProperty(self, prop, value, type):
138 """ 139 Set a local prop if nessesaary on this service. 140 """ 141 classObj = self.getClassObject() 142 if not classObj: return 143 classObj = classObj.primaryAq() 144 svcval = getattr(classObj, prop) 145 locval = getattr(aq_base(self),prop,None) 146 msg = "" 147 if svcval == value and locval is not None: 148 self._delProperty(prop) 149 msg = "Removed local %s" % prop 150 elif svcval != value and locval is None: 151 self._setProperty(prop, value, type=type) 152 msg = "Set local %s" % prop 153 elif locval is not None and locval != value: 154 self._updateProperty(prop, value) 155 msg = "Update local %s" % prop 156 return msg
157 158
159 - def getClassObject(self):
160 """ 161 If you are going to use acquisition up different class path 162 override this. 163 """ 164 return self.device()
165 166
167 - def getRRDContextData(self, context):
168 context['comp'] = self 169 context['compId'] = self.id 170 context['compName'] = self.name() 171 if self.device(): 172 context['dev'] = self.device() 173 context['devId'] = self.device().id
174 175
176 - def manage_afterAdd(self, item, container):
177 """ 178 Device only propagates afterAdd if it is the added object. 179 """ 180 self.index_object() 181 super(DeviceComponent,self).manage_afterAdd(item, container)
182 183
184 - def manage_afterClone(self, item):
185 """ 186 Not really sure when this is called. 187 """ 188 super(DeviceComponent,self).manage_afterClone(item) 189 self.index_object()
190 191
192 - def manage_beforeDelete(self, item, container):
193 """ 194 Device only propagates beforeDelete if we are being deleted or copied. 195 Moving and renaming don't propagate. 196 """ 197 super(DeviceComponent,self).manage_beforeDelete(item, container) 198 self.unindex_object()
199
200 - def filterAutomaticCreation(self):
201 """Test if automatic creation (and anchoring into a model) is 202 appropriate for this object. Lets us ignore detectable gunk 203 that's not very interesting to model, like most processes, and 204 loopback network devices, CDROM file systems, etc. 205 206 Returns False if the object should not be added. 207 208 The object will have its full acquisition path, but will not 209 have been added to the database. 210 """ 211 return True
212 213 InitializeClass(DeviceComponent) 214