示例#1
0
    def __call__(self, *args, **kwargs):

        now = int(time())

        exception_dict = args[0]
        exception_class = exception_dict.get('exception_class', '')
        url = exception_dict.get('url', '')
        backtrace = exception_dict.get('backtrace', '')

        message = exception_dict.get('message', '')
        enviroment = exception_dict.get('enviroment', '')
        data = exception_dict.get('data', '')

        exception_string = "{0}{1}{2}".format(exception_class, url, backtrace)
        exception_id = md5(exception_string).hexdigest()

        additional_data = {'occurrence': now}

        if message: additional_data['message'] = message
        if enviroment: additional_data['enviroment'] = enviroment
        if data: additional_data['data'] = data

        exceptions_collection = backend.get_collection(self.collection)
        exception_in_db = exceptions_collection.find_one(
            {"exception_id": exception_id})

        if exception_in_db is not None:
            exception_in_db['last_occurrence'] = now
            exception_in_db['additional_data'].insert(0, additional_data)
            exception_in_db[
                'total_occurrences'] = exception_in_db['total_occurrences'] + 1

            exceptions_collection.update({'_id': exception_in_db['_id']},
                                         exception_in_db)
        else:
            entry = {
                'last_occurrence': now,
                'exception_id': exception_id,
                'exception_class': exception_class,
                'url': url,
                'backtrace': backtrace,
            }

            entry['additional_data'] = [additional_data]
            entry['total_occurrences'] = 1

            backend.store_entry(entry, self.collection)

        unread = backend.get_collection('unread')
        unread_counter = unread.find({"id": 1}).count()

        if unread_counter == 0:
            _counter = {'id': 1, 'exceptions': 1, 'logs': 0}
            unread.save(_counter)
        else:
            unread.update({"id": 1}, {"$inc": {"exceptions": 1}})
示例#2
0
文件: exception.py 项目: d1on/amon
	def __call__(self, *args, **kwargs):
		
		now = int(time())

		exception_dict = args[0]
		exception_class = exception_dict.get('exception_class', '')
		url = exception_dict.get('url', '')
		backtrace = exception_dict.get('backtrace', '')
		
		message= exception_dict.get('message', '')
		enviroment = exception_dict.get('enviroment', '')
		data = exception_dict.get('data', '')
		
		
		exception_string = "{0}{1}{2}".format(exception_class, url, backtrace)
		exception_id = md5(exception_string).hexdigest()
		
		additional_data = {'occurrence': now}

		if message: additional_data['message'] = message
		if enviroment: additional_data['enviroment'] = enviroment
		if data: additional_data['data'] = data

		exceptions_collection = backend.get_collection(self.collection)
		exception_in_db = exceptions_collection.find_one({"exception_id" : exception_id})

		if exception_in_db is not None:
			exception_in_db['last_occurrence'] = now
			exception_in_db['additional_data'].insert(0, additional_data)
			exception_in_db['total_occurrences']  = exception_in_db['total_occurrences']+1

			exceptions_collection.update({'_id' : exception_in_db['_id']}, exception_in_db)
		else:
			entry = {'last_occurrence': now,
					 'exception_id': exception_id,
					 'exception_class': exception_class,
					 'url': url,
					 'backtrace' : backtrace,
					 }

			entry['additional_data'] = [additional_data]
			entry['total_occurrences'] = 1
			
			backend.store_entry(entry, self.collection)
			
		
		unread = backend.get_collection('unread')
		unread_counter = unread.find({"id": 1}).count()

		if unread_counter == 0:
			_counter = {'id':1, 'exceptions': 1, 'logs': 0}
			unread.save(_counter)
		else:
			unread.update({"id": 1}, {"$inc": {"exceptions": 1}})
示例#3
0
文件: log.py 项目: d1on/amon
	def __call__(self, *args, **kwargs):

		log_dict = args[0]

		try:
			level = log_dict.get('level')
			if level not in self.levels:
				level = 'notset'
		except: 
			level = 'notset'
		
		message = log_dict.get('message', '')

		now = int(time())

		entry = {'time': now, 'message': message, 'level': level}
		
		# Add the data to a separate field, for easy searching 
		if isinstance(message, dict):
			_searchable = ":".join(message.keys())
		elif isinstance(message, list):
			_searchable = ":".join(["%s" % el for el in message])
		else:
			_searchable = message
		
		entry['_searchable'] = _searchable
		

		backend.store_entry(entry, 'logs')


		# TODO - refactor it at some point, when expanding the API
		unread = backend.get_collection('unread')
		unread_counter = unread.find({"id": 1}).count()

		if unread_counter == 0:
			_counter = {'id':1, 'exceptions': 0, 'logs': 1}
			unread.save(_counter)
		else:
			unread.update({"id": 1}, {"$inc": {"logs": 1}})
示例#4
0
    def __call__(self, *args, **kwargs):

        log_dict = args[0]

        try:
            level = log_dict.get('level')
            if level not in self.levels:
                level = 'notset'
        except:
            level = 'notset'

        message = log_dict.get('message', '')

        now = int(time())

        entry = {'time': now, 'message': message, 'level': level}

        # Add the data to a separate field, for easy searching
        if isinstance(message, dict):
            _searchable = ":".join(message.keys())
        elif isinstance(message, list):
            _searchable = ":".join(["%s" % el for el in message])
        else:
            _searchable = message

        entry['_searchable'] = _searchable

        backend.store_entry(entry, 'logs')

        # TODO - refactor it at some point, when expanding the API
        unread = backend.get_collection('unread')
        unread_counter = unread.find({"id": 1}).count()

        if unread_counter == 0:
            _counter = {'id': 1, 'exceptions': 0, 'logs': 1}
            unread.save(_counter)
        else:
            unread.update({"id": 1}, {"$inc": {"logs": 1}})