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  from Products.ZenModel.ZenossSecurity import ZEN_VIEW
     29
     30  from Lockable import Lockable
     31
     32 -class DeviceComponent(Lockable):
     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
     49 -    def getParentDeviceName(self):
     50          """
     51          Return the name of this component's device
     52          """
     53          name = ""
     54          dev = self.device()
     55          if dev: name = dev.getDeviceName()
     56          return name
     57      hostname = getParentDeviceName
     58
     59
     60 -    def getParentDeviceUrl(self):
     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')
     70 -    def name(self):
     71          """
     72          Return the name of this component.  Default is id.
     73          """
     74          return self.titleOrId()
     75
     76
     77 -    def monitored(self):
     78          """
     79          Return the monitored status of this component. Default is False.
     80          """
     81          return self.monitor
     82
     83
     84 -    def getCollectors(self):
     85          """
     86          Return list of collectors that want to monitor this component
     87          """
     88          return self.collectors
     89
     90
     91 -    def getInstDescription(self):
     92          """
     93          Return some text that describes this component.  Default is name.
     94          """
     95          return self.name()
     96
     97
     98 -    def getStatus(self, statClass=None):
     99          """
    100          Return the status number for this component of class statClass.
    101          """
    102          if not self.monitored() \
    103              or not self.device() \
    104              or not self.device().monitorDevice(): return -1
    105          if not statClass: statClass = "/Status/%s" % self.meta_type
    106          return self.getEventManager().getComponentStatus(
    107                  self.getParentDeviceName(), self.name(), statclass=statClass)
    108
    109
    110 -    def getStatusString(self, statClass=None):
    111          """
    112          Return a text representation of this component's status
    113          """
    114          return self.convertStatus(self.getStatus(statClass))
    115
    116
    117 -    def getManageIp(self):
    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
    126 -    def getNagiosTemplate(self, unused=None):
    127          import warnings
    128          warnings.warn('anything named nagios is deprecated', DeprecationWarning)
    129
    130
    131 -    def getAqProperty(self, prop):
    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
    143 -    def setAqProperty(self, prop, value, type):
    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
    165 -    def getClassObject(self):
    166          """
    167          If you are going to use acquisition up different class path
    168          override this.
    169          """
    170          return self.device()
    171
    172
    173 -    def getIconPath(self):
    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
    190 -    def filterAutomaticCreation(self):
    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