| Trees | Indices | Help |
|
|---|
|
|
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 Error types:
15
16 1. timeout (no connection)
17 2. connection refused - port not available on remote end
18 3. bad value - value returned did not match expectRegex
19
20 """
21 import re
22 import logging
23 log = logging.getLogger("zen.ZenTcpClient")
24
25 from twisted.internet import reactor, protocol, defer
26 from Products.ZenEvents.ZenEventClasses import Status_IpService
27 from Products.ZenUtils.Utils import unused
28
29 from socket import getfqdn
30 hostname = getfqdn()
31
32 # needed for pb/jelly
33 from Products.ZenHub.services.StatusConfig import ServiceConfig
34 unused(ServiceConfig)
35
37 """
38 Twisted class to make a TCP/IP connection to a remote IP service
39 and report back the result.
40 """
41 defer = None
42 data = ""
43
45 log.debug("Connected to %s" % self.transport.getPeer().host)
46 self.factory.msg = "pass"
47 self.cfg = self.factory.cfg
48
49 if self.cfg.sendString:
50 for line in self.cfg.sendString.split('\n'):
51 log.debug("Sending: %s" % line)
52 self.transport.write(line + '\n')
53
54 if self.cfg.expectRegex:
55 log.debug("Waiting for results to check against regex '%s'" % (
56 self.cfg.expectRegex ))
57 self.defer = reactor.callLater(self.cfg.timeout, self.expectTimeout)
58 else:
59 self.loseConnection()
60
61
63 log.debug("%s %s received data: %s" % (self.cfg.device,
64 self.cfg.component, data))
65 self.data += data
66 if self.cfg.expectRegex:
67 if re.search(self.cfg.expectRegex, data):
68 log.debug("Found %s in '%s' -- closing connection" % (
69 self.cfg.expectRegex, data))
70 self.loseConnection()
71 else:
72 log.debug("No match for %s in '%s' -- looking for more data" % (
73 self.cfg.expectRegex, data))
74
75
77 msg = "IP Service %s TIMEOUT waiting for '%s'" % (
78 self.cfg.component, self.cfg.expectRegex)
79 log.debug( "%s %s" % (self.cfg.ip, msg) )
80 self.factory.msg = msg
81 self.loseConnection()
82
83
94
95
96
98 protocol = ZenTcpTest
99 msg = "pass"
100 deferred = None
101
105
107 unused(connector)
108 log.debug("Lost connection to %s (%s) port %s : %s" % (
109 self.cfg.device, self.cfg.ip, self.cfg.port,
110 reason.getErrorMessage() ))
111 if self.deferred:
112 self.deferred.callback(self)
113 self.deferred = None
114
115
117 unused(connector)
118 log.debug("Connection to %s (%s) port %s failed: %s" % (
119 self.cfg.device, self.cfg.ip, self.cfg.port,
120 reason.getErrorMessage() ))
121 log.debug(reason.type)
122 self.msg = "IP Service %s is down" % self.cfg.component
123 if self.deferred:
124 self.deferred.callback(self)
125 self.deferred = None
126
127
129 log.debug("status:%s msg:%s", self.status, self.msg)
130 if self.msg == "pass" and self.status > 0:
131 self.status = sev = 0
132 self.msg = "IP Service %s back up" % self.cfg.component
133 log.info(self.msg)
134
135 elif self.msg != "pass":
136 self.status += 1
137 sev = self.cfg.failSeverity
138 log.warn(self.msg)
139
140 else:
141 # Don't send an event as there's no problem and
142 # nothing to clear.
143 return None
144
145 return dict(device=self.cfg.device,
146 component=self.cfg.component,
147 ipAddress=self.cfg.ip,
148 summary=self.msg,
149 severity=sev,
150 eventClass=Status_IpService,
151 eventGroup="TCPTest",
152 agent="ZenStatus",
153 manager=hostname)
154
159
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Thu May 7 11:46:35 2009 | http://epydoc.sourceforge.net |