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 or (at your
      8  # option) any later version as published by 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  """
     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
     33 -class DeviceComponent(Lockable):
     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
     51 -    def getParentDeviceName(self):
     52          """
     53          Return the name of this component's device
     54          """
     55          name = ""
     56          dev = self.device()
     57          if dev: name = dev.getDeviceName()
     58          return name
     59      hostname = getParentDeviceName
     60
     61 -    def getParentDeviceTitle(self):
     62          """
     63          Return the title of this component's device
     64          """
     65          title = ""
     66          dev = self.device()
     67          if dev: title = dev.titleOrId()
     68          return title
     69
     70 -    def getParentDeviceUrl(self):
     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')
     80 -    def name(self):
     81          """
     82          Return the name of this component.  Default is id.
     83          """
     84          return self.titleOrId()
     85
     86
     87 -    def monitored(self):
     88          """
     89          Return the monitored status of this component. Default is False.
     90          """
     91          return self.monitor
     92
     93
     94 -    def getCollectors(self):
     95          """
     96          Return list of collectors that want to monitor this component
     97          """
     98          return self.collectors
     99
    100
    101 -    def getInstDescription(self):
    102          """
    103          Return some text that describes this component.  Default is name.
    104          """
    105          return self.name()
    106
    107
    108 -    def getStatus(self, statClass=None):
    109          """
    110          Return the status number for this component of class statClass.
    111          """
    112          if not self.monitored() \
    113              or not self.device() \
    114              or not self.device().monitorDevice(): return -1
    115          if not statClass: statClass = "/Status/%s" % self.meta_type
    116          return EventView.getStatus(self, statClass)
    117
    118 -    def getStatusString(self, statClass=None):
    119          """
    120          Return a text representation of this component's status
    121          """
    122          return self.convertStatus(self.getStatus(statClass=statClass))
    123
    124 -    def getManageIp(self):
    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
    133 -    def getNagiosTemplate(self, unused=None):
    134          import warnings
    135          warnings.warn('anything named nagios is deprecated', DeprecationWarning)
    136
    137
    138 -    def getAqProperty(self, prop):
    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
    150 -    def setAqProperty(self, prop, value, type):
    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
    172 -    def getClassObject(self):
    173          """
    174          If you are going to use acquisition up different class path
    175          override this.
    176          """
    177          return self.device()
    178
    179
    180 -    def getIconPath(self):
    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
    195 -    def filterAutomaticCreation(self):
    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
    208 -    def getSubComponentsNoIndexGen(self):
    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