1
2
3
4
5
6
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
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
56 hostname = getParentDeviceName
57
66
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')
78 """
79 Return the name of this component. Default is id.
80 """
81 return self.titleOrId()
82
83
85 """
86 Return the monitored status of this component. Default is False.
87 """
88 return self.monitor
89
90
92 """
93 Return list of collectors that want to monitor this component
94 """
95 return self.collectors
96
97
99 """
100 Return some text that describes this component. Default is name.
101 """
102 return self.name()
103
104
114
116 """
117 Return a text representation of this component's status
118 """
119 return self.convertStatus(self.getStatus(statClass=statClass))
120
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
131 import warnings
132 warnings.warn('anything named nagios is deprecated', DeprecationWarning)
133
134
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
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
170 """
171 If you are going to use acquisition up different class path
172 override this.
173 """
174 return self.device()
175
176
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
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