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  from Products.ZenEvents.ZenEventClasses import Change_Add,Change_Remove,Change_Set 
 27   
28 -class DeviceComponent(Lockable):
29 """ 30 DeviceComponent is a mix-in class for all components of a device. 31 These include LogicalComponent, Software, and Hardware. 32 """ 33 event_key = "Component" 34 35 default_catalog = "componentSearch" 36 37 collectors = ('zenperfsnmp', 'zencommand', 'zenwinperf') 38 39 security = ClassSecurityInfo() 40 41
42 - def getParentDeviceName(self):
43 """return the name of this component's device""" 44 name = "" 45 dev = self.device() 46 if dev: name = dev.getDeviceName() 47 return name
48 hostname = getParentDeviceName 49
50 - def getParentDeviceUrl(self):
51 """return the url of this component's device""" 52 url = "" 53 dev = self.device() 54 if dev: url = dev.absolute_url() 55 return url
56 57
58 - def name(self):
59 """Return the name of this component. Default is id. 60 """ 61 return self.id
62 63
64 - def monitored(self):
65 """Return the monitored status of this component. Default is False. 66 """ 67 return self.monitor
68 69
70 - def getCollectors(self):
71 """Return list of collectors that want to monitor this component 72 """ 73 return self.collectors
74 75
76 - def getInstDescription(self):
77 """Return some text that describes this component. Default is name. 78 """ 79 return self.name()
80 81
82 - def getStatus(self, statClass=None):
83 """Return the status number for this component of class statClass. 84 """ 85 if not self.monitored() \ 86 or not self.device() \ 87 or not self.device().monitorDevice(): return -1 88 if not statClass: statClass = "/Status/%s" % self.meta_type 89 return self.getEventManager().getComponentStatus( 90 self.getParentDeviceName(), self.name(), statclass=statClass)
91 92
93 - def getStatusString(self, statClass=None):
94 return self.convertStatus(self.getStatus(statClass))
95 96
97 - def getManageIp(self):
98 """Return the manageIP of the device of this component. 99 """ 100 dev = self.device() 101 if dev: return dev.getManageIp() 102 return ""
103 104
105 - def getRRDTemplateByName(self, name):
106 """Return the closest RRDTemplate named name by walking our aq chain. 107 """ 108 try: 109 return getattr(self, name) 110 except AttributeError: 111 return super(DeviceComponent, self).getRRDTemplateByName(name)
112 113
114 - def getNagiosTemplate(self, name=None):
115 import warnings 116 warnings.warn('anything named nagios is deprecated', DeprecationWarning)
117 118
119 - def getAqProperty(self, prop):
120 """Get a property from ourself if it exsits then try serviceclass path. 121 """ 122 if getattr(aq_base(self), prop, None) is not None: 123 return getattr(self, prop) 124 classObj = self.getClassObject() 125 if classObj: 126 classObj = classObj.primaryAq() 127 return getattr(classObj, prop)
128 129
130 - def setAqProperty(self, prop, value, type):
131 """Set a local prop if nessesaary on this service. 132 """ 133 classObj = self.getClassObject() 134 if not classObj: return 135 classObj = classObj.primaryAq() 136 svcval = getattr(classObj, prop) 137 locval = getattr(aq_base(self),prop,None) 138 msg = "" 139 if svcval == value and locval is not None: 140 self._delProperty(prop) 141 msg = "Removed local %s" % prop 142 elif svcval != value and locval is None: 143 self._setProperty(prop, value, type=type) 144 msg = "Set local %s" % prop 145 elif locval is not None and locval != value: 146 setattr(self, prop, value) 147 msg = "Update local %s" % prop 148 return msg
149 150
151 - def getClassObject(self):
152 """If you are going to use acquisition up different class path 153 override this. 154 """ 155 return self.device()
156 157
158 - def manage_afterAdd(self, item, container):
159 """ 160 Device only propagates afterAdd if it is the added object. 161 """ 162 self.index_object() 163 super(DeviceComponent,self).manage_afterAdd(item, container)
164 165
166 - def manage_afterClone(self, item):
167 """Not really sure when this is called.""" 168 super(DeviceComponent,self).manage_afterClone(item) 169 self.index_object()
170 171
172 - def manage_beforeDelete(self, item, container):
173 """ 174 Device only propagates beforeDelete if we are being deleted or copied. 175 Moving and renaming don't propagate. 176 """ 177 super(DeviceComponent,self).manage_beforeDelete(item, container) 178 self.unindex_object()
179 180 InitializeClass(DeviceComponent) 181