def check(self, datum): log.debug("Got check data '%s'." % datum) status = self.factory.cfg.app.state_definitions.unknown if self.isIn(datum, self.getOkThreshold()): log.debug("Status data is in 'ok' threshold.") status = self.factory.cfg.app.state_definitions.ok # The 'current status' index hasn't been updated yet, so # 'current status' is really 'last status', and 'last status' # is really the run prior to last. if self.factory.state.get('current status') not in ( self.factory.cfg.app.state_definitions.ok, self.factory.cfg.app.state_definitions.recovering): status = self.factory.cfg.app.state_definitions.recovering elif self.isIn(datum, self.getWarnThreshold()): log.debug("Status data is in 'warn' threshold.") status = self.factory.cfg.app.state_definitions.warn elif self.isIn(datum, self.getErrorThreshold()): log.debug("Status data is in 'error' threshold.") status = self.factory.cfg.app.state_definitions.error elif self.isIn(datum, self.getFailedThreshold()): log.debug("Status data is in 'failed' threshold.") status = self.factory.cfg.app.state_definitions.failed elif datum == self.factory.cfg.app.state_definitions.failed: status = self.factory.cfg.app.state_definitions.failed return status
def setFilename(self, filename=None): backupDir = self.monitor.cfg.app.admin.backups.state_dir if not filename: filename = self.monitor.uid self.filename = os.path.join(backupDir, re.sub('[^0-9A-Za-z_]', '_', filename)) self.data.filename = self.filename log.debug("Backup file named '%s'." % self.filename)
def getPingReturn(self, results, port): try: gain = self.data['gain'][port] except KeyError: gain = 0 try: loss = self.data['loss'][port] except KeyError: loss = 0 results = gain / (float(gain + loss) or 1) log.debug('Ping results: %s' % results) return results
def isIn(self, datum, threshold): ''' Generic method for checking data against thresholds ''' if self.threshold_type == 'ranged': isInFunc = isInRange elif self.threshold_type == 'listed': isInFunc = isInList elif self.threshold_type == 'exact': isInFunc = isExactly log.debug("Using method '%s'..." % isInFunc.func_name) log.debug("datum: %s" % datum) log.debug("datum type: %s" % type(datum)) log.debug("threshold: %s" % threshold) log.debug("threshold type: %s" % type(threshold)) return isInFunc(datum, threshold)
def setInterval(self, seconds=None): #import pdb;pdb.set_trace() def useDef(): interval = self.cfg.defaults.interval log.debug('Set interval from service check defaults') return interval if seconds: interval = seconds log.debug('Manually set interval') else: interval = self.cfg.check.interval if interval: log.debug('Set interval from service check config') else: interval = useDef() if not interval: interval = useDef() self._interval = int(interval)
def connectionLost(self, reason): # parse returned data log.debug(self.factory.data) parse = OutputParser(self.factory.data) loss = parse.getPingLoss() gain = parse.getPingGain() host = self.getHost() # threshold checks, messaging, and workflow self.processRules(gain, host=host, loss=loss, gain=gain) # update state information self.updateState() # dump info to log file log.info('State Data: ' + str(self.factory.state.data) + '\n') # final cleanup LocalAgentClient.connectionLost(self, reason) ClientMixin.teardown(self)
def connectionLost(self, reason): # parse returned data log.debug(self.factory.data) parse = OutputParser(self.factory.data) loss = parse.getPingLoss() gain = parse.getPingGain() host = self.getHost() # threshold checks, messaging, and workflow self.processRules(gain, host=host, loss=loss, gain=gain) # update state information self.updateState() # dump info to log file log.info('State Data: '+str(self.factory.state.data)+'\n') # final cleanup LocalAgentClient.connectionLost(self, reason) ClientMixin.teardown(self)
def _setupNullClient(self): ''' This needs to be called anytime we didn't get a connection. Rules processing occurs ''' self.status = '0' log.debug('Entered null client setup...') self.original_protocol = self.protocol log.debug('Original Protocol: %s' % self.original_protocol) self.protocol = NullClient() log.debug('New Protocol: %s' % self.protocol) self.protocol.makeConnection(self) self.protocol = self.original_protocol log.debug('Reverted Protocol: %s' % self.protocol)
def runTwistedFactoryEngine(rootService): cfg = rootService.cfg enabledServices = cfg.getEnabledServices() # iterate through the enabled services for pymonService in enabledServices: serviceName = pymonService.getName() log.debug("Service name: " + serviceName) factoryName = pymonService.default.factory # for each enabled service, iterate through the checks for that # service for check in pymonService.checks: log.debug("Service check uri: "+check.uri) factory = monitors.AbstractFactory(factoryName, serviceName, check.uri) monitor = factory.makeMonitor(cfg.configFactory(factory.uid)) # XXX this next line could be a potential memory hog globalRegistry.factories.update({monitor.uid:monitor}) interval = monitor.getInterval() log.debug("Service interval: %s" % interval) service = internet.TimerService(interval, monitor) service.setServiceParent(rootService)
def connectionLost(self, reason): results = self.factory.data log.debug(results) # push the returned data through the threshold checks status = self.rules.check(gain) self.workflow.checkTransition(status, self.factory.cfg) #self.rules.setMsg(results['gain'], self.getHost()) #self.rules.setSubj(self.getHost(), results['loss']) #if self.rules.isSendMessage(): # self.rules.sendIt() # dump info to log file log.debug('Service: %s' % self.factory.uid) log.debug("Status: %s for %s" % (self.rules.status, host)) # update state information self.updateState() # dump info to log file log.info('State Data: ' + str(self.factory.state.data) + '\n') # final cleanup ClientMixin.connectionLost(self)
def connectionLost(self, reason): results = self.factory.data log.debug(results) # push the returned data through the threshold checks status = self.rules.check(gain) self.workflow.checkTransition(status, self.factory.cfg) #self.rules.setMsg(results['gain'], self.getHost()) #self.rules.setSubj(self.getHost(), results['loss']) #if self.rules.isSendMessage(): # self.rules.sendIt() # dump info to log file log.debug('Service: %s' % self.factory.uid) log.debug("Status: %s for %s" % (self.rules.status, host)) # update state information self.updateState() # dump info to log file log.info('State Data: '+str(self.factory.state.data)+'\n') # final cleanup ClientMixin.connectionLost(self)
def errorHandlerPartialPage(self, failure): failure.trap(PartialDownloadError) log.error("Hmmm... got a partial page...") log.debug('Return status: %s' % self.status)
def connectionMade(self): ''' We never got a connection, and therefore can't get a connection lost, so we need to do the things here that would normally get done in connectionLost. ''' ClientMixin.connectionMade(self) log.debug("Factory in NullClient: %s" % self.factory) status = self.factory.cfg.app.state_definitions.failed checked_resource = self.factory.cfg.checks.uri log.debug("Starting rules processing...") self.rules.check(status) self.rules.setMsg(checked_resource, self.factory.status, self.factory.message) self.rules.setSubj(checked_resource) if self.rules.isSendMessage(): self.rules.sendIt() log.debug("Finished rules processing.") # dump info to log file log.debug('NullClient Service: %s' % self.factory.uid) log.info(self.rules.msg) log.info(self.rules.subj) log.debug("NullClient Status: %s for %s" % (status, self.getHost())) # update state information self.updateState() # dump info to log file log.debug(self.factory.state)
def getPingReturn(self, results): self.data = results log.debug("Ping results: %s" % results) self.disconnect()
def useDef(): interval = self.cfg.defaults.interval log.debug('Set interval from service check defaults') return interval
def getPingReturn(self, results): self.data = results log.debug('Ping results: %s' % results) self.disconnect()
def connectionLost(self, reason): status = self.factory.status if status: status = int(status) log.debug(str(dir(self.factory))) log.debug(str(self.factory.headers)) log.debug(str(self.factory.response_headers)) checked_resource = self.factory.checkConfig.uri # push the returned data through the threshold checks self.rules.check(status) self.rules.setMsg(checked_resource, status, self.factory.message) self.rules.setSubj(checked_resource, status) if self.rules.isSendMessage(): self.rules.sendIt() # dump info to log file log.debug("Service: %s" % self.factory.uid) log.info(self.rules.msg) log.info(self.rules.subj) log.debug("Status: %s for %s" % (status, self.getHost())) # update state information self.updateState() # dump info to log file log.debug("State Data: " + str(self.factory.state.data) + "\n")
def connectionLost(self, reason): status = self.factory.status if status: status = int(status) log.debug(str(dir(self.factory))) log.debug(str(self.factory.headers)) log.debug(str(self.factory.response_headers)) checked_resource = self.factory.checkConfig.uri # push the returned data through the threshold checks self.rules.check(status) self.rules.setMsg(checked_resource, status, self.factory.message) self.rules.setSubj(checked_resource, status) if self.rules.isSendMessage(): self.rules.sendIt() # dump info to log file log.debug('Service: %s' % self.factory.uid) log.info(self.rules.msg) log.info(self.rules.subj) log.debug("Status: %s for %s" % (status, self.getHost())) # update state information self.updateState() # dump info to log file log.debug('State Data: ' + str(self.factory.state.data) + '\n')