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