1
2
3
4
5
6
7
8
9
10
11
12 __doc__ = """zenstatus
13
14 Check the TCP/IP connectivity of IP services.
15 UDP is specifically not supported.
16 """
17
18 import logging
19
20 from twisted.internet import defer
21
22 import Globals
23 import zope.component
24 import zope.interface
25 from Products.ZenStatus.ZenTcpClient import ZenTcpClient
26 from Products.ZenCollector.daemon import CollectorDaemon
27 from Products.ZenCollector.interfaces import ICollectorPreferences,\
28 IEventService,\
29 IScheduledTask
30 from Products.ZenCollector.tasks import SimpleTaskFactory,\
31 SubConfigurationTaskSplitter,\
32 TaskStates, \
33 BaseTask
34
35
36
37
38
39 from Products.ZenUtils.Utils import unused
40 from Products.ZenCollector.services.config import DeviceProxy
41 from Products.ZenHub.services.ZenStatusConfig import ServiceProxy
42 unused(ServiceProxy)
43 unused(DeviceProxy)
44
45
46
47
48 log = logging.getLogger("zen.zenstatus")
49
50
55
56
57
58
60 zope.interface.implements(ICollectorPreferences)
61
63 """
64 Construct a new ZenStatusPreferences instance and provide default
65 values for needed attributes.
66 """
67 self.collectorName = "zenstatus"
68 self.defaultRRDCreateCommand = None
69 self.cycleInterval = 60
70 self.configCycleInterval = 20
71 self.statusCycleInterval = 60
72 self.options = None
73
74
75
76 self.configurationService = 'Products.ZenHub.services.ZenStatusConfig'
77
79 """
80 add any zenstatus specific command line options here
81 """
82 pass
83
84 - def postStartup(self):
85 """
86 process any zenstatus specific command line options here
87 """
88 pass
89
90
92 zope.interface.implements(IScheduledTask)
93
94 - def __init__(self,
95 name,
96 configId,
97 scheduleIntervalSeconds,
98 taskConfig):
99 """
100 Construct a new task for checking the status
101
102 @param deviceId: the Zenoss deviceId to watch
103 @type deviceId: string
104 @param taskName: the unique identifier for this task
105 @type taskName: string
106 @param scheduleIntervalSeconds: the interval at which this task will be
107 collected
108 @type scheduleIntervalSeconds: int
109 @param taskConfig: the configuration for this task
110 """
111 super(ZenStatusTask, self).__init__(
112 name, configId,
113 scheduleIntervalSeconds, taskConfig
114 )
115
116 self.name = name
117 self.configId = configId
118 self.interval = scheduleIntervalSeconds
119 self.state = TaskStates.STATE_IDLE
120 self.log = log
121 self.cfg = taskConfig.components[0]
122 self._devId = self.cfg.device
123 self._eventService = zope.component.queryUtility(IEventService)
124 self._preferences = zope.component.queryUtility(ICollectorPreferences,
125 "zenstatus")
126
128 log.debug("Scanning device %s (%s) port %s",
129 self._devId, ip_address, self.cfg.port)
130 job = ZenTcpClient(self.cfg, self.cfg.status)
131 return job.start(ip_address)
132
141
143 """
144 Test a connection to a device.
145
146 @parameter result: device and TCP service to test
147 @type result: ZenTcpClient object
148 """
149 evt = result.getEvent()
150 if evt:
151 if evt['severity'] != 0:
152 d = self._scan_device(self.cfg.deviceManageIp)
153 d.addCallback(self.processTest)
154 d.addErrback(self.handleExceptions)
155 return d
156 self._eventService.sendEvent(evt)
157 return defer.succeed("Connected")
158
167
169 """
170 Log internal exceptions that have occurred
171 from testing TCP services
172
173 @param reason: error message
174 @type reason: Twisted error instance
175 """
176 msg = reason.getErrorMessage()
177 evt = dict(device=self._preferences.options.monitor,
178 summary=msg,
179 severity=4,
180 component='zenstatus',
181 traceback=reason.getTraceback())
182 self._eventService.sendEvent(evt)
183 return defer.succeed("Failed due to internal error")
184
187
188
189
190
191
192 if __name__ == '__main__':
193 myPreferences = ZenStatusPreferences()
194 myTaskFactory = SimpleTaskFactory(ZenStatusTask)
195 myTaskSplitter = ServiceTaskSplitter(myTaskFactory)
196 daemon = CollectorDaemon(myPreferences, myTaskSplitter)
197 daemon.run()
198