示例#1
0
	def test_system(self):
		system_info = runner.system()
		
		cpu = backend.get_collection('cpu')
		cpu.remove()
		
		memory = backend.get_collection('memory')
		memory.remove()
		
		loadavg = backend.get_collection('loadavg')
		loadavg.remove()
		
		disk = backend.get_collection('disk')
		disk.remove()
		
		network = backend.get_collection('network')
		network.remove()
		
		backend.store_entries(system_info)

		eq_(1, cpu.count())
		eq_(1, memory.count())
		eq_(1, loadavg.count())
		eq_(1, disk.count())
		if sys.platform != 'darwin':
			eq_(1, network.count())
示例#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
	def test_processes(self):
		process_info = runner.processes()
		process_checks = settings.PROCESS_CHECKS
		
		
		for process in process_checks:
			db = backend.get_collection(process)
			db.remove()
		
		backend.store_entries(process_info)

		for process in process_checks:
			db = backend.get_collection(process)
			eq_(1, db.count())
示例#4
0
文件: log_test.py 项目: d1on/amon
	def test_log_contents(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"message":"test"})

		entry = db.find_one()
		eq_(entry['message'], 'test')
示例#5
0
文件: log_test.py 项目: d1on/amon
	def test_log_searchable_dict(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"message": {"dict_key": "value", "dict_key2": "value_2"}})
		
		entry = db.find_one()
		eq_(entry['_searchable'], 'dict_key:dict_key2')
示例#6
0
文件: log_test.py 项目: d1on/amon
	def test_log_searchable_list(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"message": ['test', 'more']})
		
		entry = db.find_one()
		eq_(entry['_searchable'], 'test:more')
示例#7
0
文件: log_test.py 项目: d1on/amon
	def test_log_dict(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"message": {"dict_key": "value", "dict_key2": "value_2"}})

		entry = db.find_one()
		eq_(entry['message'], {u'dict_key': u'value', u'dict_key2': u'value_2'})
示例#8
0
文件: log_test.py 项目: d1on/amon
	def test_log_searchable_string(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"message": "test_message"})
		
		entry = db.find_one()
		eq_(entry['_searchable'], 'test_message')
示例#9
0
文件: mongodb_test.py 项目: d1on/amon
	def test_store_entries(self):
	  db = backend.get_collection('cpu')
	  db.remove()
	  
	  entries_list = {'cpu': {'time': 1313096288, 'idle': 93, 'wait': 0, 'user': 2, 'system': 5}}

	  backend.store_entries(entries_list)


	  total_entries = db.count()
	  eq_(1, total_entries)
示例#10
0
文件: log_test.py 项目: d1on/amon
	def test_unread_counter(self):
		unread = backend.get_collection('unread')
		unread.remove()
		
		log({"message":"", "level": "dummy_level"})
		
		eq_(unread.count(), 1)

		log({"message":"", "level": "dummy_level"})
		log({"message":"", "level": "dummy_level"})

		eq_(unread.count(), 1)
示例#11
0
	def test_unread_counter(self):
		unread = backend.get_collection('unread')
		unread.remove()
		
		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})
		
		eq_(unread.count(), 1)

		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})
		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})

		eq_(unread.count(), 1)
示例#12
0
文件: mongodb_test.py 项目: d1on/amon
	def test_store_entry(self):
		db = backend.get_collection('logs')
		db.remove()
		
		db.insert({})

		total_entries = db.count()
		eq_(1, total_entries)

		db.insert({})
		total_entries = db.count()
		eq_(2, total_entries)
示例#13
0
	def test_exception_id(self):
		db = backend.get_collection('exceptions')
		db.remove()

		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test"})

		exception_string = "{0}{1}{2}".format('test', 'url_test', 'backtrace_test')
		exception_id = md5(exception_string).hexdigest()

		entry = db.find_one()
		eq_(entry['exception_id'], exception_id)
示例#14
0
文件: log_test.py 项目: d1on/amon
	def test_undefined_log_levels(self):
		db = backend.get_collection('logs')
		db.remove()

		
		log({"message":"", "level": "dummy_level"})
		log({"message":"", "level": "and_another_one"})
		log({"message":"", "level": "and_even_more"})


		entries = db.find()
		for entry in entries:
			eq_(entry['level'], 'notset')
示例#15
0
	def test_exception_grouping(self):
		db = backend.get_collection('exceptions')
		db.remove()
		
		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test",\
					"data":"data"})
		
		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test",\
					"data":"more data"})

		eq_(1, db.count())
示例#16
0
	def test_unread_counter_values(self):
		unread = backend.get_collection('unread')
		unread.remove()
		
		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})

		unread_dict = unread.find_one()
		eq_(unread_dict['exceptions'],1)

		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})
		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})
		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})
		exception({"exception_class":"test","url": "url_test", "backtrace": "backtrace_test"})

		unread_dict = unread.find_one()
		eq_(unread_dict['exceptions'],5)
示例#17
0
文件: log_test.py 项目: d1on/amon
	def test_log_levels(self):
		db = backend.get_collection('logs')
		db.remove()
		
		levels = ('warning', 'error', 'info', 'critical', 'debug')
		
		log({"message":"", "level": "warning"})
		log({"message":"", "level": "info"})
		log({"message":"", "level": "debug"})
		log({"message":"", "level": "critical"})
		log({"message":"", "level": "error"})

		eq_(5, db.count())

		entries = db.find()
		for entry in entries:
			self.assertTrue(entry['level'] in levels)
示例#18
0
	def test_exception_occurences_counter(self):
		db = backend.get_collection('exceptions')
		db.remove()
		
		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test"})
		
		exc = db.find_one()
		eq_(1, exc['total_occurrences'])

		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test"})
		
		exc = db.find_one()
		eq_(2, exc['total_occurrences'])
示例#19
0
	def test_exception_contents(self):
		db = backend.get_collection('exceptions')
		db.remove()
		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test",\
					"message": "message_test",\
					"enviroment": "enviroment",\
					"data":"data"})

		entry = db.find_one()
		eq_(entry['exception_class'], 'test')
		eq_(entry['url'], 'url_test')
		eq_(entry['backtrace'], 'backtrace_test')
		eq_(entry['additional_data'][0]['message'], 'message_test')
		eq_(entry['additional_data'][0]['enviroment'], 'enviroment')
		eq_(entry['additional_data'][0]['data'], 'data')
示例#20
0
文件: log_test.py 项目: d1on/amon
	def test_unread_counter_values(self):
		unread = backend.get_collection('unread')
		unread.remove()
		
		log({"message":"", "level": "dummy_level"})

		unread_dict = unread.find_one()
		eq_(unread_dict['logs'],1)


		log({"message":"", "level": "dummy_level"})
		log({"message":"", "level": "dummy_level"})
		log({"message":"", "level": "dummy_level"})
		log({"message":"", "level": "dummy_level"})


		unread_dict = unread.find_one()
		eq_(unread_dict['logs'],5)
示例#21
0
	def test_exception_additional_data(self):
		db = backend.get_collection('exceptions')
		db.remove()

		exception({"exception_class":"test",\
					"url": "url_test",\
					"backtrace": "backtrace_test"})


		exc = db.find_one()
		additional_data = exc['additional_data'][0]
		eq_(1, len(additional_data)) # Only occurrence should be here

		valid_keys = ['occurrence']
		keys = additional_data.keys()
		
		for key in keys:
			assert key in valid_keys
示例#22
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}})
示例#23
0
 def test_process_collection(self):
     for setting in settings.PROCESS_CHECKS:
         collection = Collection(Database(Connection(u'127.0.0.1', 27017), u'amon_test'), u'amon_{0}'.format(setting))
         eq_(backend.get_collection(setting), collection)
示例#24
0
文件: mongodb_test.py 项目: d1on/amon
	def test_get_false_collection(self):
		self.assertFalse(inspect.isclass(backend.get_collection('test_me')))
		self.assertFalse(inspect.isclass(backend.get_collection('test_me_again')))
示例#25
0
文件: mongodb_test.py 项目: d1on/amon
	def test_system_colllection(self):
		for setting in settings.SYSTEM_CHECKS:
			self.assertTrue(inspect.isclass(backend.get_collection(setting)))
示例#26
0
文件: mongodb_test.py 项目: d1on/amon
	def test_process_collection(self):
		for setting in settings.PROCESS_CHECKS:
			self.assertTrue(inspect.isclass(backend.get_collection(setting)))
示例#27
0
文件: log_test.py 项目: d1on/amon
	def test_log(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"bar":"baz"})
		eq_(1, db.count())
示例#28
0
	def test_exception(self):
		db = backend.get_collection('exceptions')
		db.remove()
		exception({"bar":"baz"})
		eq_(1, db.count())
示例#29
0
文件: mongodb_test.py 项目: d1on/amon
	def test_get_collection(self):
		self.assertTrue(inspect.isclass(backend.get_collection('logs')))
		self.assertTrue(inspect.isclass(backend.get_collection('exceptions')))
示例#30
0
文件: log_test.py 项目: d1on/amon
	def test_log_list_integers(self):
		db = backend.get_collection('logs')
		db.remove()
		log({"message": [1,2,3,4]})
		
		eq_(1, db.count())