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