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

Source Code for Module 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  from Globals import DTMLFile 
 24  from Globals import InitializeClass 
 25  from Acquisition import aq_base, aq_chain 
 26  from AccessControl import ClassSecurityInfo 
 27  from Commandable import Commandable 
 28   
 29  from Products.ZenRelations.RelSchema import * 
 30   
 31  from OSComponent import OSComponent 
 32  from ZenPackable import ZenPackable 
 33   
34 -class Service(OSComponent, Commandable, ZenPackable):
35 portal_type = meta_type = 'Service' 36 37 _relations = OSComponent._relations + ZenPackable._relations + ( 38 ("serviceclass", ToOne(ToMany,"Products.ZenModel.ServiceClass","instances")), 39 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 40 ) 41 42 security = ClassSecurityInfo() 43
44 - def key(self):
45 """Return tuple (manageIp, name) for this service to uniquely id it. 46 """ 47 return (self.getManageIp(), self.name())
48 49
50 - def name(self):
51 """Return the name of this service. (short name for net stop/start). 52 """ 53 svccl = self.serviceclass() 54 if svccl: return svccl.name 55 return ""
56 57
58 - def monitored(self):
59 """Should this service be monitored or not. Use ServiceClass aq path. 60 """ 61 return self.getAqProperty("zMonitor")
62
63 - def getSeverities(self):
64 """Return a list of tuples with the possible severities 65 """ 66 return self.ZenEventManager.getSeverities()
67
68 - def getFailSeverity(self):
69 """Return the severity for this service when it fails. 70 """ 71 return self.getAqProperty("zFailSeverity")
72
73 - def getFailSeverityString(self):
74 """Return a string representation of zFailSeverity 75 """ 76 return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
77
78 - def setServiceClass(self, name="", description=""):
79 """Set the service class based on a dict describing the service. 80 Dict keys are be protocol and port 81 """ 82 srvs = self.dmd.getDmdRoot("Services") 83 srvclass = srvs.createServiceClass(name=name, description=description) 84 self.serviceclass.addRelation(srvclass)
85 86 98 99
100 - def getClassObject(self):
101 return self.serviceclass()
102 103 104 security.declareProtected('Manage DMD', 'manage_editService')
105 - def manage_editService(self,monitor=False,severity=5,msg=None,REQUEST=None):
106 """Edit a Service from a web page. 107 """ 108 if msg is None: msg=[] 109 msg.append(self.setAqProperty("zMonitor", monitor, "boolean")) 110 msg.append(self.setAqProperty("zFailSeverity", severity, "int")) 111 msg = [ m for m in msg if m ] 112 self.index_object() 113 if not msg: msg.append("No action needed") 114 if REQUEST: 115 REQUEST['message'] = ", ".join(msg) 116 return self.callZenScreen(REQUEST, redirect=True)
117 118
119 - def getUserCommandTargets(self):
120 ''' Called by Commandable.doCommand() to ascertain objects on which 121 a UserCommand should be executed. 122 ''' 123 return [self]
124 125
127 environ = Commandable.getUserCommandEnvironment(self) 128 context = self.primaryAq() 129 environ.update({'serv': context, 'service': context,}) 130 return environ
131 132
134 chain = aq_chain(self.getClassObject().primaryAq()) 135 chain.insert(0, self) 136 return chain
137 138
139 - def getUrlForUserCommands(self):
140 return self.getPrimaryUrlPath() + '/serviceManage'
141