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

# Source Code for Module Products.ZenModel.Service

      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__="""Service.py
     15
     16  Service is a function provided by computer (like a server).  it
     17  is defined by a protocol type (udp/tcp) and a port number.
     18
     19  $Id: Service.py,v 1.15 2003/03/11 23:32:13 edahl Exp $"""
     20
     21  __version__ = "$Revision: 1.15 $"[11:-2]
     22
     23  import Globals
     24  from Acquisition import aq_chain
     25  from AccessControl import ClassSecurityInfo
     26  from Commandable import Commandable
     27
     28  from Products.ZenRelations.RelSchema import *
     29  from Products.ZenWidgets import messaging
     30
     31  from OSComponent import OSComponent
     32  from ZenPackable import ZenPackable
     33
     34 -class Service(OSComponent, Commandable, ZenPackable):
     35      """
     36      Service class
     37      """
     38      portal_type = meta_type = 'Service'
     39
     40      _relations = OSComponent._relations + ZenPackable._relations + (
     41          ("serviceclass", ToOne(ToMany,"Products.ZenModel.ServiceClass","instances")),
     42          ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')),
     43          )
     44
     45      security = ClassSecurityInfo()
     46
     47 -    def key(self):
     48          """
     49          Return tuple (manageIp, name) for this service to uniquely id it.
     50          """
     51          return (self.getManageIp(), self.name())
     52
     53
     54 -    def name(self):
     55          """
     56          Return the name of this service. (short name for net stop/start).
     57          """
     58          svccl = self.serviceclass()
     59          if svccl: return svccl.name
     60          return ""
     61
     62
     63 -    def monitored(self):
     64          """
     65          Should this service be monitored or not. Use ServiceClass aq path.
     66          """
     67          return self.monitor and self.getAqProperty("zMonitor")
     68
     69
     70 -    def getSeverities(self):
     71          """
     72          Return a list of tuples with the possible severities
     73          """
     74          return self.ZenEventManager.getSeverities()
     75
     76
     77 -    def getFailSeverity(self):
     78          """
     79          Return the severity for this service when it fails.
     80          """
     81          return self.getAqProperty("zFailSeverity")
     82
     83
     84 -    def getFailSeverityString(self):
     85          """
     86          Return a string representation of zFailSeverity
     87          """
     88          return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
     89
     90
     91 -    def setServiceClass(self, kwargs):
     92          """
     93          Set the service class based on a dict describing the service.
     94          Dict keys are be protocol and port
     95          """
     96          name = kwargs['name']
     97          description = kwargs['description']
     98          srvs = self.dmd.getDmdRoot("Services")
     99          srvclass = srvs.createServiceClass(name=name, description=description)
    100          self.serviceclass.addRelation(srvclass)
    101
    102
    103 -    def getServiceClassLink(self):
    104          """
    105          Return an a link to the service class.
    106          """
    107          svccl = self.serviceclass()
    108          if svccl:
    109              if self.checkRemotePerm("View", svccl):
    110                  return "<a href='%s'>%s</a>" % (svccl.getPrimaryUrlPath(),
    111                                                  svccl.getServiceClassName())
    112              else:
    113                  return svccl.getServiceClassName()
    114          return ""
    115
    116
    117 -    def getClassObject(self):
    118          """
    119          Return the ServiceClass for this service.
    120          """
    121          return self.serviceclass()
    122
    123
    124      security.declareProtected('Manage DMD', 'manage_editService')
    125 -    def manage_editService(self,monitor=False,severity=5,msg=None,REQUEST=None):
    126          """
    127          Edit a Service from a web page.
    128          """
    129          if msg is None: msg=[]
    130          msg.append(self.setAqProperty("zMonitor", monitor, "boolean"))
    131          msg.append(self.setAqProperty("zFailSeverity", severity, "int"))
    132          msg = [ m for m in msg if m ]
    133          self.index_object()
    134          if not msg: msg.append("No action needed")
    135          if REQUEST:
    136              messaging.IMessageSender(self).sendToBrowser(
    137                  'Service Edited',
    138                  ", ".join(msg)
    139              )
    140              return self.callZenScreen(REQUEST, redirect=True)
    141
    142
    143 -    def getUserCommandTargets(self):
    144          '''
    145          Called by Commandable.doCommand() to ascertain objects on which
    146          a UserCommand should be executed.
    147          '''
    148          return [self]
    149
    150
    151 -    def getUserCommandEnvironment(self):
    152          """
    153          Return the environment to be used when processing a UserCommand
    154          """
    155          environ = Commandable.getUserCommandEnvironment(self)
    156          context = self.primaryAq()
    157          environ.update({'serv': context,  'service': context,})
    158          return environ
    159
    160
    161 -    def getAqChainForUserCommands(self):
    162          """
    163          Setup the aq chain as appropriate for the execution of a UserCommand
    164          """
    165          chain = aq_chain(self.getClassObject().primaryAq())
    166          chain.insert(0, self)
    167          return chain
    168
    169
    170 -    def getUrlForUserCommands(self):
    171          """
    172          Return the url where UserCommands are viewed for this object
    173          """
    174          return self.getPrimaryUrlPath() + '/serviceManage'
    175