Package Products :: Package ZenModel :: Module DeviceComponent |
[hide private]
[frames] | no frames]

# Source Code for Module Products.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
     26  import zope.interface
     27  from Products.ZenModel.interfaces import IIndexed
     28
     29  from Lockable import Lockable
     30
     31 -class DeviceComponent(Lockable):
     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
     48 -    def getParentDeviceName(self):
     49          """
     50          Return the name of this component's device
     51          """
     52          name = ""
     53          dev = self.device()
     54          if dev: name = dev.getDeviceName()
     55          return name
     56      hostname = getParentDeviceName
     57
     58
     59 -    def getParentDeviceUrl(self):
     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
     69 -    def name(self):
     70          """
     71          Return the name of this component.  Default is id.
     72          """
     73          return self.titleOrId()
     74
     75
     76 -    def monitored(self):
     77          """
     78          Return the monitored status of this component. Default is False.
     79          """
     80          return self.monitor
     81
     82
     83 -    def getCollectors(self):
     84          """
     85          Return list of collectors that want to monitor this component
     86          """
     87          return self.collectors
     88
     89
     90 -    def getInstDescription(self):
     91          """
     92          Return some text that describes this component.  Default is name.
     93          """
     94          return self.name()
     95
     96
     97 -    def getStatus(self, statClass=None):
     98          """
     99          Return the status number for this component of class statClass.
    100          """
    101          if not self.monitored() \
    102              or not self.device() \
    103              or not self.device().monitorDevice(): return -1
    104          if not statClass: statClass = "/Status/%s" % self.meta_type
    105          return self.getEventManager().getComponentStatus(
    106                  self.getParentDeviceName(), self.name(), statclass=statClass)
    107
    108
    109 -    def getStatusString(self, statClass=None):
    110          """
    111          Return a text representation of this component's status
    112          """
    113          return self.convertStatus(self.getStatus(statClass))
    114
    115
    116 -    def getManageIp(self):
    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
    125 -    def getNagiosTemplate(self, unused=None):
    126          import warnings
    127          warnings.warn('anything named nagios is deprecated', DeprecationWarning)
    128
    129
    130 -    def getAqProperty(self, prop):
    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
    142 -    def setAqProperty(self, prop, value, type):
    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
    164 -    def getClassObject(self):
    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
    181 -    def filterAutomaticCreation(self):
    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