1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""IpService.py
15
16 IpService 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: IpService.py,v 1.10 2004/04/22 22:04:14 edahl Exp $"""
20
21 __version__ = "$Revision: 1.10 $"[11:-2]
22
23 from Globals import DTMLFile
24 from Globals import InitializeClass
25 from AccessControl import ClassSecurityInfo
26 from Products.ZenModel.ZenossSecurity import *
27
28 from Products.ZenRelations.RelSchema import *
29
30 from Service import Service
31 from Products.ZenModel.IpServiceClass import IpServiceClass
32
47
48 addIpService = DTMLFile('dtml/addIpService',globals())
49
50
53
54
56 """
57 IpService object
58 """
59
60 __pychecker__='no-override'
61
62 portal_type = meta_type = 'IpService'
63
64 protocols = ('tcp', 'udp')
65
66 ipaddresses = []
67 discoveryAgent = ""
68 port = 0
69 protocol = ""
70
71 collectors = ('zenstatus',)
72
73 _properties = (
74 {'id':'port', 'type':'int', 'mode':'', 'setter': 'setPort'},
75 {'id':'protocol', 'type':'string', 'mode':'', 'setter': 'setProtocol'},
76 {'id':'ipaddresses', 'type':'lines', 'mode':''},
77 {'id':'discoveryAgent', 'type':'string', 'mode':''},
78 )
79 _relations = Service._relations + (
80 ("os", ToOne(ToManyCont,"Products.ZenModel.OperatingSystem","ipservices")),
81 )
82
83 factory_type_information = (
84 {
85 'immediate_view' : 'ipServiceDetail',
86 'actions' :
87 (
88 { 'id' : 'status'
89 , 'name' : 'Status'
90 , 'action' : 'ipServiceDetail'
91 , 'permissions' : (ZEN_VIEW, )
92 },
93 { 'id' : 'events'
94 , 'name' : 'Events'
95 , 'action' : 'viewEvents'
96 , 'permissions' : (ZEN_VIEW, )
97 },
98 { 'id' : 'manage'
99 , 'name' : 'Administration'
100 , 'action' : 'ipServiceManage'
101 , 'permissions' : ("Manage DMD",)
102 },
103 { 'id' : 'viewHistory'
104 , 'name' : 'Modifications'
105 , 'action' : 'viewHistory'
106 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
107 },
108 )
109 },
110 )
111
112 security = ClassSecurityInfo()
113
114
116 """Return monitored state of ipservice.
117 If service only listens on 127.0.0.1 return false.
118 """
119 if self.cantMonitor(): return False
120 return super(IpService, self).monitored()
121
122
124 """
125 Return true if IpService only listens on 127.0.0.1, or if it is a UDP
126 service.
127 """
128 return self.protocol == 'udp' \
129 or ( len(self.ipaddresses) == 1
130 and "127.0.0.1" in self.ipaddresses )
131
132
133
135 """Return some text that describes this component. Default is name.
136 """
137 return "%s-%d ips:%s" % (self.protocol, self.port,
138 ", ".join(self.ipaddresses))
139
140
153
154
157
158
161
162
164 """Return a dict like one set by IpServiceMap for services.
165 """
166 svc = self.serviceclass()
167 if svc:
168 return {'protocol': self.protocol, 'port': svc.port }
169 return {}
170
171
174
176 manage_ip = Service.getManageIp(self)
177 for ip in self.ipaddresses:
178 if ip != '0.0.0.0' and ip != '127.0.0.1':
179 return ip
180 return manage_ip
181
184
187
189 sc = self.serviceclass()
190 if sc: return sc.name
191
193 sc = self.serviceclass()
194 if sc: return sc.description
195
199
200
201 security.declareProtected('Manage DMD', 'manage_editService')
202 - def manage_editService(self, id=None,
203 status=None, ipaddresses=None,
204 protocol=None, port=None,
205 description=None,
206 monitor=False, severity=5, sendString="",
207 expectRegex="", REQUEST=None):
208 """Edit a Service from a web page.
209 """
210 if id:
211 self.rename(id)
212 if status: self.status = status
213 self.ipaddresses = ipaddresses
214 self.description = description
215 self.protocol = protocol
216 self._updateProperty('port', port)
217 if protocol != self.protocol or port != self.port:
218 self.setServiceClass({'protocol':protocol, 'port':int(port)})
219
220 msg = []
221 msg.append(self.setAqProperty("sendString", sendString, "string"))
222 msg.append(self.setAqProperty("expectRegex", expectRegex, "string"))
223 self.index_object()
224
225 return super(IpService, self).manage_editService(monitor, severity,
226 msg=msg,REQUEST=REQUEST)
227
228
229 InitializeClass(IpService)
230