def eb(failure): self.debug( 'parse: eb: failure %s' % log.getFailureMessage(failure)) # Nagios exceptions have already got their feedback covered if not failure.check(util.NagiosException): util.unknown(log.getFailureMessage(failure)) reactor.callLater(0, reactor.stop)
def eb(f): self.debug( 'parse: eb: failure %s' % log.getFailureMessage(f)) # Nagios exceptions have already got their feedback covered if not f.check(util.NagiosException): util.unknown(log.getFailureMessage(f)) reactor.callLater(0, reactor.stop)
def do(self, args): if not args: return util.unknown('Please specify a log file to check.') if len(args) > 1: return util.unknown('Please specify only one log file to check.') command = "grep '%s' %s | tail -n 1" % (self.options.string, " ".join(args)) self.debug('executing %s' % command) output = commands.getoutput(command) self.debug('output: %s' % output) if not output: return util.unknown('Could not find string %s in log file' % self.options.string) level = output[:5].strip() if level not in ['ERROR', 'WARN', 'INFO', 'DEBUG', 'LOG']: return util.unknown("Last line is not a log line: '%s'" % output) # matches flumotion.extern.log.log # level pid object cat time # 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1 + 15 == 80 position = 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1 # log timestrings are currently in local time, which might be a mistake timestring = output[position:position + 15] timetuple = time.strptime(timestring, "%b %d %H:%M:%S") now = time.time() nowtuple = time.localtime(now) # since the year does not get logged, assume the log line is from this # year, or last year if the delta becomes negative timelist = list(timetuple) timelist[0] = nowtuple[0] if time.mktime(tuple(timelist)) > time.mktime(nowtuple): self.debug('timestamp is past now, so assume it is from last year') timelist[0] = nowtuple[0] - 1 # mktime also works in local time, which hopefully matches the log's # local time timestamp = time.mktime(tuple(timelist)) delta = now - int(timestamp) msg = 'Last log line%s is %s old.' % ( self.options.string and " with '%s'" % self.options.string or '', formatting.formatTime(delta, fractional=2)) if delta > int(self.options.critical): return util.critical(msg) elif delta > int(self.options.warning): return util.warning(msg) else: return util.ok(msg)
def do(self, args): if not args: return util.unknown('Please specify a log file to check.') if len(args) > 1: return util.unknown('Please specify only one log file to check.') command = "grep '%s' %s | tail -n 1" % ( self.options.string, " ".join(args)) self.debug('executing %s' % command) output = commands.getoutput(command) self.debug('output: %s' % output) if not output: return util.unknown('Could not find string %s in log file' % self.options.string) level = output[:5].strip() if level not in ['ERROR', 'WARN', 'INFO', 'DEBUG', 'LOG']: return util.unknown("Last line is not a log line: '%s'" % output) # matches flumotion.extern.log.log # level pid object cat time # 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1 + 15 == 80 position = 5 + 1 + 7 + 1 + 32 + 1 + 17 + 1 # log timestrings are currently in local time, which might be a mistake timestring = output[position:position + 15] timetuple = time.strptime(timestring, "%b %d %H:%M:%S") now = time.time() nowtuple = time.localtime(now) # since the year does not get logged, assume the log line is from this # year, or last year if the delta becomes negative timelist = list(timetuple) timelist[0] = nowtuple[0] if time.mktime(tuple(timelist)) > time.mktime(nowtuple): self.debug('timestamp is past now, so assume it is from last year') timelist[0] = nowtuple[0] - 1 # mktime also works in local time, which hopefully matches the log's # local time timestamp = time.mktime(tuple(timelist)) delta = now - int(timestamp) msg = 'Last log line%s is %s old.' % ( self.options.string and " with '%s'" % self.options.string or '', formatting.formatTime(delta, fractional=2)) if delta > int(self.options.critical): return util.critical(msg) elif delta > int(self.options.warning): return util.warning(msg) else: return util.ok(msg)
def _connectedEb(self, f): if f.check(errors.ConnectionFailedError): # switch the failure and return an UNKNOWN status msg = "Unable to connect to manager." f = failure.Failure(util.NagiosUnknown(msg)) util.unknown(msg) if f.check(errors.ConnectionRefusedError): # switch the failure and return a CRITICAL status msg = "Manager refused connection." f = failure.Failure(util.NagiosCritical(msg)) util.critical(msg) # all other failures get forwarded to the managerDeferred errback as-is self.managerDeferred.errback(f)
def gotPlanetStateCb(result): self.debug("gotPlanetStateCb") c = util.findComponent(result, self._component) if not c: return util.unknown("Could not find component %s" % self._component) moodValue = c.get("mood") moodName = planet.moods.get(moodValue).name if moodName in self._critical: return util.critical("Component %s is %s" % (self._component, moodName)) if moodName in self._warning: return util.warning("Component %s is %s" % (self._component, moodName)) return util.ok("Component %s is %s" % (self._component, moodName))
def gotPlanetStateCb(result): self.debug('gotPlanetStateCb') c = util.findComponent(result, self._component) if not c: return util.unknown('Could not find component %s' % self._component) moodValue = c.get('mood') moodName = planet.moods.get(moodValue).name if moodName in self._critical: return util.critical('Component %s is %s' % (self._component, moodName)) if moodName in self._warning: return util.warning('Component %s is %s' % (self._component, moodName)) return util.ok('Component %s is %s' % (self._component, moodName))
def unknown(self, message): return util.unknown('%s: %s [dump at %s]' % (self._url, message, self._tmpfile))
def _got_planet_state(self, planet_state): c = util.findComponent(planet_state, self.component_id) if not c: return util.unknown('Could not find component %s' % self.component_id) return self._detect_flipflops(c)
def _connectedEb(self, failure): if failure.check(errors.ConnectionFailedError): util.unknown("Unable to connect to manager.") if failure.check(errors.ConnectionRefusedError): util.critical("Manager refused connection.") self.managerDeferred.errback(failure)