def __init__(self): ZCmdBase.__init__(self) self.current = IDLE self.currentStart = 0 self.numCalls = 0 try: self.log.debug("establishing SIGUSR2 signal handler") signal.signal(signal.SIGUSR2, self.sighandler_USR2) except ValueError: # If we get called multiple times, this will generate an exception: # ValueError: signal only works in main thread # Ignore it as we've already set up the signal handler. pass self.zem = self.dmd.ZenEventManager loadPlugins(self.dmd) self.pid = os.getpid() self.services = {} factory = ReconnectingPBClientFactory() self.log.debug("Connecting to %s:%d", self.options.hubhost, self.options.hubport) reactor.connectTCP(self.options.hubhost, self.options.hubport, factory) self.log.debug("Logging in as %s", self.options.username) c = credentials.UsernamePassword(self.options.username, self.options.password) factory.gotPerspective = self.gotPerspective def stop(*args): reactor.callLater(0, reactor.stop) factory.clientConnectionLost = stop factory.startLogin(c)
def connect(self): pingInterval = self.options.zhPingInterval factory = ReconnectingPBClientFactory( connectTimeout=60, pingPerspective=self.options.pingPerspective, pingInterval=pingInterval, pingtimeout=pingInterval * 5) self.log.info("Connecting to %s:%d" % (self.options.hubhost, self.options.hubport)) factory.connectTCP(self.options.hubhost, self.options.hubport) username = self.options.hubusername password = self.options.hubpassword self.log.debug("Logging in as %s" % username) c = credentials.UsernamePassword(username, password) factory.gotPerspective = self.gotPerspective factory.connecting = self.connecting factory.setCredentials(c) def timeout(d): if not d.called: self.connectTimeout() self._connectionTimeout = reactor.callLater(self.options.hubtimeout, timeout, self.initialConnect) return self.initialConnect
def __init__(self): signal.signal(signal.SIGUSR2, signal.SIG_IGN) ZCmdBase.__init__(self) if self.options.profiling: self.profiler = ContinuousProfiler('zenhubworker', log=self.log) self.profiler.start() self.current = IDLE self.currentStart = 0 self.numCalls = Metrology.meter("zenhub.workerCalls") try: self.log.debug("establishing SIGUSR1 signal handler") signal.signal(signal.SIGUSR1, self.sighandler_USR1) self.log.debug("establishing SIGUSR2 signal handler") signal.signal(signal.SIGUSR2, self.sighandler_USR2) except ValueError: # If we get called multiple times, this will generate an exception: # ValueError: signal only works in main thread # Ignore it as we've already set up the signal handler. pass self.zem = self.dmd.ZenEventManager loadPlugins(self.dmd) self.pid = os.getpid() self.services = {} factory = ReconnectingPBClientFactory(pingPerspective=False) self.log.debug("Connecting to %s:%d", self.options.hubhost, self.options.hubport) reactor.connectTCP(self.options.hubhost, self.options.hubport, factory) self.log.debug("Logging in as %s", self.options.username) c = credentials.UsernamePassword(self.options.username, self.options.password) factory.gotPerspective = self.gotPerspective def stop(*args): reactor.callLater(0, reactor.stop) factory.clientConnectionLost = stop factory.setCredentials(c) self.log.debug("Creating async MetricReporter") daemonTags = { 'zenoss_daemon': 'zenhub_worker_%s' % self.options.workernum, 'zenoss_monitor': self.options.monitor, 'internal': True } def stopReporter(): if self.metricreporter: return self.metricreporter.stop() # Order of the shutdown triggers matter. Want to stop reporter first, calling metricWriter() below # registers shutdown triggers for the actual metric http and redis publishers. reactor.addSystemEventTrigger('before', 'shutdown', stopReporter) self.metricreporter = TwistedMetricReporter( metricWriter=metricWriter(), tags=daemonTags) self.metricreporter.start()
def connect(self): factory = ReconnectingPBClientFactory(connectTimeout=60) self.log.info("Connecting to %s:%d" % (self.options.hubhost, self.options.hubport)) factory.connectTCP(self.options.hubhost, self.options.hubport) username = self.options.hubusername password = self.options.hubpassword self.log.debug("Logging in as %s" % username) c = credentials.UsernamePassword(username, password) factory.gotPerspective = self.gotPerspective factory.connecting = self.connecting factory.startLogin(c) def timeout(d): if not d.called: self.connectTimeout() self._connectionTimeout = reactor.callLater( self.options.hubtimeout, timeout, self.initialConnect) return self.initialConnect