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.CMFCore.utils import getToolByName 
 29  from Products.ZenRelations.RelSchema import * 
 30  from Products.ZenWidgets import messaging 
 31   
 32  from OSComponent import OSComponent 
 33  from ZenPackable import ZenPackable 
 34   
35 -class Service(OSComponent, Commandable, ZenPackable):
36 """ 37 Service class 38 """ 39 portal_type = meta_type = 'Service' 40 41 _relations = OSComponent._relations + ZenPackable._relations + ( 42 ("serviceclass", ToOne(ToMany,"Products.ZenModel.ServiceClass","instances")), 43 ('userCommands', ToManyCont(ToOne, 'Products.ZenModel.UserCommand', 'commandable')), 44 ) 45 46 security = ClassSecurityInfo() 47
48 - def key(self):
49 """ 50 Return tuple (manageIp, name) for this service to uniquely id it. 51 """ 52 return (self.getManageIp(), self.name())
53 54
55 - def name(self):
56 """ 57 Return the name of this service. (short name for net stop/start). 58 """ 59 svccl = self.serviceclass() 60 if svccl: return svccl.name 61 return ""
62 63
64 - def monitored(self):
65 """ 66 Should this service be monitored or not. Use ServiceClass aq path. 67 """ 68 return self.monitor and self.getAqProperty("zMonitor")
69 70
71 - def isMonitored(self):
72 """ 73 Returns the same as "monitored" but from the catalog instead of from 74 the service class. 75 """ 76 try: 77 index_dict = self.dmd.Devices.componentSearch.getIndexDataForUID( 78 self.getPrimaryId()) 79 except KeyError: 80 return self.monitored() 81 82 return index_dict.get('monitored', self.monitored())
83 84
85 - def getStatus(self, statClass=None):
86 """ 87 Return the status number for this component of class statClass. 88 """ 89 if not self.isMonitored() \ 90 or not self.device() \ 91 or not self.device().monitorDevice(): return -1 92 if not statClass: statClass = "/Status/%s" % self.meta_type 93 return self.getEventManager().getComponentStatus( 94 self.getParentDeviceName(), self.name(), statclass=statClass)
95 96
97 - def getSeverities(self):
98 """ 99 Return a list of tuples with the possible severities 100 """ 101 return self.ZenEventManager.getSeverities()
102 103
104 - def getFailSeverity(self):
105 """ 106 Return the severity for this service when it fails. 107 """ 108 return self.getAqProperty("zFailSeverity")
109 110
111 - def getFailSeverityString(self):
112 """ 113 Return a string representation of zFailSeverity 114 """ 115 return self.ZenEventManager.severities[self.getAqProperty("zFailSeverity")]
116 117
118 - def setServiceClass(self, kwargs):
119 """ 120 Set the service class based on a dict describing the service. 121 Dict keys are be protocol and port 122 """ 123 name = kwargs['name'] 124 description = kwargs['description'] 125 srvs = self.dmd.getDmdRoot("Services") 126 srvclass = srvs.createServiceClass(name=name, description=description) 127 self.serviceclass.addRelation(srvclass)
128 129 142 143
144 - def getClassObject(self):
145 """ 146 Return the ServiceClass for this service. 147 """ 148 return self.serviceclass()
149 150 151 security.declareProtected('Manage DMD', 'manage_editService')
152 - def manage_editService(self,monitor=False,severity=5,msg=None,REQUEST=None):
153 """ 154 Edit a Service from a web page. 155 """ 156 if msg is None: msg=[] 157 msg.append(self.setAqProperty("zMonitor", monitor, "boolean")) 158 msg.append(self.setAqProperty("zFailSeverity", severity, "int")) 159 msg = [ m for m in msg if m ] 160 self.index_object() 161 if not msg: msg.append("No action needed") 162 if REQUEST: 163 messaging.IMessageSender(self).sendToBrowser( 164 'Service Edited', 165 ", ".join(msg) 166 ) 167 return self.callZenScreen(REQUEST, redirect=True)
168 169
170 - def getUserCommandTargets(self):
171 ''' 172 Called by Commandable.doCommand() to ascertain objects on which 173 a UserCommand should be executed. 174 ''' 175 return [self]
176 177
179 """ 180 Return the environment to be used when processing a UserCommand 181 """ 182 environ = Commandable.getUserCommandEnvironment(self) 183 context = self.primaryAq() 184 environ.update({'serv': context, 'service': context,}) 185 return environ
186 187
189 """ 190 Setup the aq chain as appropriate for the execution of a UserCommand 191 """ 192 chain = aq_chain(self.getClassObject().primaryAq()) 193 chain.insert(0, self) 194 return chain
195 196
197 - def getUrlForUserCommands(self):
198 """ 199 Return the url where UserCommands are viewed for this object 200 """ 201 return self.getPrimaryUrlPath() + '/serviceManage'
202