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 $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
26 import zope.interface
27 from Products.ZenModel.interfaces import IIndexed
28 from Products.ZenModel.ZenossSecurity import ZEN_VIEW
29
30 from Lockable import Lockable
31
33 """
34 DeviceComponent is a mix-in class for all components of a device.
35 These include LogicalComponent, Software, and Hardware.
36 """
37 zope.interface.implements(IIndexed)
38 __pychecker__='no-override'
39 event_key = "Component"
40
41 default_catalog = "componentSearch"
42
43 collectors = ('zenperfsnmp', 'zencommand', 'zenwinperf')
44
45 security = ClassSecurityInfo()
46
47 perfmonInstance = None
48
57 hostname = getParentDeviceName
58
59
61 """
62 Return the url of this component's device
63 """
64 url = ""
65 dev = self.device()
66 if dev: url = dev.absolute_url()
67 return url
68
69 security.declareProtected(ZEN_VIEW, 'name')
71 """
72 Return the name of this component. Default is id.
73 """
74 return self.titleOrId()
75
76
78 """
79 Return the monitored status of this component. Default is False.
80 """
81 return self.monitor
82
83
85 """
86 Return list of collectors that want to monitor this component
87 """
88 return self.collectors
89
90
92 """
93 Return some text that describes this component. Default is name.
94 """
95 return self.name()
96
97
108
109
111 """
112 Return a text representation of this component's status
113 """
114 return self.convertStatus(self.getStatus(statClass))
115
116
118 """
119 Return the manageIP of the device of this component.
120 """
121 dev = self.device()
122 if dev: return dev.getManageIp()
123 return ""
124
125
127 import warnings
128 warnings.warn('anything named nagios is deprecated', DeprecationWarning)
129
130
132 """
133 Get a property from ourself if it exsits then try serviceclass path.
134 """
135 if getattr(aq_base(self), prop, None) is not None:
136 return getattr(self, prop)
137 classObj = self.getClassObject()
138 if classObj:
139 classObj = classObj.primaryAq()
140 return getattr(classObj, prop)
141
142
144 """
145 Set a local prop if nessesaary on this service.
146 """
147 classObj = self.getClassObject()
148 if not classObj: return
149 classObj = classObj.primaryAq()
150 svcval = getattr(classObj, prop)
151 locval = getattr(aq_base(self),prop,None)
152 msg = ""
153 if svcval == value and locval is not None:
154 self._delProperty(prop)
155 msg = "Removed local %s" % prop
156 elif svcval != value and locval is None:
157 self._setProperty(prop, value, type=type)
158 msg = "Set local %s" % prop
159 elif locval is not None and locval != value:
160 self._updateProperty(prop, value)
161 msg = "Update local %s" % prop
162 return msg
163
164
166 """
167 If you are going to use acquisition up different class path
168 override this.
169 """
170 return self.device()
171
172
174 """
175 Override the device's zProperty and return an icon based on the class
176 name
177 """
178 return "/zport/dmd/img/icons/%s.png" % self.meta_type.lower()
179
180
181 - def getRRDContextData(self, context):
182 context['comp'] = self
183 context['compId'] = self.id
184 context['compName'] = self.name()
185 if self.device():
186 context['dev'] = self.device()
187 context['devId'] = self.device().id
188
189
191 """Test if automatic creation (and anchoring into a model) is
192 appropriate for this object. Lets us ignore detectable gunk
193 that's not very interesting to model, like most processes, and
194 loopback network devices, CDROM file systems, etc.
195
196 Returns False if the object should not be added.
197
198 The object will have its full acquisition path, but will not
199 have been added to the database.
200 """
201 return True
202
203 InitializeClass(DeviceComponent)
204