| 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
28 from socket import getfqdn
29 hostname = getfqdn()
30
31 from Products.ZenHub.services.StatusConfig import ServiceConfig
32
34
35 defer = None
36 data = ""
37
39 log.debug("connect to: %s" % self.transport.getPeer().host)
40 self.factory.msg = "pass"
41 self.cfg = self.factory.cfg
42 if self.cfg.sendString:
43 log.debug("sending: %s" % self.cfg.sendString)
44 self.transport.write(self.cfg.sendString)
45 if self.cfg.expectRegex:
46 self.defer = reactor.callLater(self.cfg.timeout, self.expectTimeout)
47 else:
48 self.loseConnection()
49
50
52 log.debug("data: %s", data)
53 self.data += data
54 if self.cfg.expectRegex and re.search(self.cfg.expectRegex, data):
55 self.loseConnection()
56
57
59 msg = "IP Service %s TIMEOUT waiting for '%s'" % (
60 self.cfg.component, self.cfg.expectRegex)
61 self.factory.msg = msg
62 self.loseConnection()
63
64
73
74
75
77 protocol = ZenTcpTest
78 msg = "pass"
79 deferred = None
80
84
86 log.debug("lost: %s", reason.getErrorMessage())
87 if self.deferred:
88 self.deferred.callback(self)
89 self.deferred = None
90
91
93 log.debug("failed: %s", reason.getErrorMessage())
94 log.debug(reason.type)
95 self.msg = "IP Service %s is down" % self.cfg.component
96 if self.deferred:
97 self.deferred.callback(self)
98 self.deferred = None
99
100
102 log.debug("status:%s msg:%s", self.status, self.msg)
103 if self.msg == "pass" and self.status > 0:
104 self.status = sev = 0
105 self.msg = "IP Service %s back up" % self.cfg.component
106 log.info(self.msg)
107 elif self.msg != "pass":
108 self.status += 1
109 sev = self.cfg.failSeverity
110 log.warn(self.msg)
111 else:
112 return None
113 return dict(device=self.cfg.device,
114 component=self.cfg.component,
115 ipAddress=self.cfg.ip,
116 summary=self.msg,
117 severity=sev,
118 eventClass=Status_IpService,
119 eventGroup="TCPTest",
120 agent="ZenStatus",
121 manager=hostname)
122
127
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:38 2007 | http://epydoc.sourceforge.net |