当前位置: 首页>>代码示例>>Python>>正文


Python NSCP.log函数代码示例

本文整理汇总了Python中NSCP.log函数的典型用法代码示例。如果您正苦于以下问题:Python log函数的具体用法?Python log怎么用?Python log使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了log函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_test

	def run_test(self):
		global time_to_run, check_per_second
		result = TestResult()
		start = time()
		if isinstance(time_to_run, str) and time_to_run == 'infinate':
			time_to_run = -1
		elif isinstance(time_to_run, str):
			time_to_run = 5

		if time_to_run == -1:
			total_count = -1
		else:
			total_count = check_per_second*time_to_run

		if time_to_run != -1:
			self.background = False
			last_major = 0
			while self.results_count < total_count:
				old_stress_count = self.results_count
				old_noop_count = self.check_count
				sleep(5000)
				result.add_message(True, 'Commands/second: %d/%d'%( (self.results_count-old_stress_count)/5, (self.check_count-old_noop_count)/5 ) )
				if (self.results_count*100/total_count) > last_major + 10:
					last_major = last_major + 10
					log('%d%% Complete: %d checks per second <%d/%d>'%(self.results_count*100/total_count, (self.results_count-old_stress_count)/5, self.results_count, total_count))
			elapsed = (time() - start)
			if elapsed == 0:
				elapsed = 1
			result.add_message(True, 'Summary Collected %d instance in %d seconds: %d/s'%(self.results_count, elapsed, self.results_count/elapsed))
		else:
			self.background = True
			result.add_message(True, 'Test running in background, run py_unittest_collect to collect results at any time.')
		return result
开发者ID:Vilse1202,项目名称:nscp,代码行数:33,代码来源:test_stress.py

示例2: log

 def log(self, show_all = False, prefix = '', indent = 0):
     if self.status:
         if show_all:
             log('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))
         log_debug('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))
     else:
         log_error('%s%s%s'%(prefix, ''.rjust(indent, ' '), self))
开发者ID:mickem,项目名称:nscp,代码行数:7,代码来源:test_helper.py

示例3: setup

	def setup(self, plugin_id, prefix):
		log('Loading Python unit tests')
		self.key = '_%stest_command'%prefix
		self.reg.simple_function('py_stress_noop', PythonTest.noop_handler, 'This is a simple noop command')
		self.reg.simple_subscription('py_stress_test', PythonTest.stress_handler)
		self.conf.set_string('/settings/test_scheduler', 'threads', '50')
		self.core.reload('test_scheduler')
开发者ID:Vilse1202,项目名称:nscp,代码行数:7,代码来源:test_python.py

示例4: install_module

def install_module(module):
    m = None
    try:
        m = importlib.import_module('modules.%s'%module)
    except Exception,e:
        log("Failed to load %s: %s"%(module, e))
        return
开发者ID:mickem,项目名称:nscp,代码行数:7,代码来源:icinga.py

示例5: setup

 def setup(self, plugin_id, prefix):
     self.reg = Registry.get(plugin_id)
     self.temp_path = self.core.expand_path("${temp}")
     log("Temp: %s" % self.temp_path)
     self.work_path = os.path.join(self.temp_path, "%s.txt" % uuid.uuid4())
     log("Work: %s" % self.work_path)
     create_test_data(self.work_path)
开发者ID:Fox-Alpha,项目名称:nscp,代码行数:7,代码来源:test_log_file.py

示例6: setup

	def setup(self, plugin_id, prefix):
		self.reg = Registry.get(plugin_id)
		self.temp_path = core.expand_path('${temp}')
		log('Temp: %s'%self.temp_path)
		self.work_path = os.path.join(self.temp_path, '%s'%uuid.uuid4())
		log('Work: %s'%self.work_path)
		os.mkdir(self.work_path)
开发者ID:Vilse1202,项目名称:nscp,代码行数:7,代码来源:test_w32_file.py

示例7: delete_file

	def delete_file(self, name, path = ''):
		(folder, file_name) = self.get_real_filename(name, path)
		if os.path.exists(file_name):
			try:
				os.remove(file_name)
			except OSError, (errno, strerror):
				log('Failed to delete: %s'%file_name)
开发者ID:Vilse1202,项目名称:nscp,代码行数:7,代码来源:test_w32_file.py

示例8: test_one_crypto

	def test_one_crypto(self, crypto, length=512):
		log('Testing: %s %d'%(crypto, length))
		conf = self.conf
		conf.set_string('/settings/NSCA/test_nsca_server', 'encryption', '%s'%crypto)
		conf.set_string('/settings/NSCA/test_nsca_server', 'password', 'pwd-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_server', 'payload length', length)
		self.core.reload('test_nsca_server')
		
		conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'address', 'nsca://127.0.0.1:35667')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'encryption', '%s'%crypto)
		conf.set_string('/settings/NSCA/test_nsca_client/targets/default', 'password', 'default-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_client/targets/default', 'payload length', length*3)

		conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'address', 'nsca://127.0.0.1:25667')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'encryption', 'none')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/invalid', 'password', 'invalid-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_client/targets/invalid', 'payload length', length*2)

		conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'address', 'nsca://127.0.0.1:15667')
		conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'encryption', '%s'%crypto)
		conf.set_string('/settings/NSCA/test_nsca_client/targets/valid', 'password', 'pwd-%s'%crypto)
		conf.set_int('/settings/NSCA/test_nsca_client/targets/valid', 'payload length', length)
		self.core.reload('test_nsca_client')

		
		
		result = TestResult('Testing: %s/%d'%(crypto, length))
		result.add_message(isOpen('localhost', 15667), 'Checking that port is open')
		for target in ['valid', 'test_rp', 'invalid']:
			result.add(self.test_one_crypto_full(crypto, status.UNKNOWN, 'unknown', target, length))
			result.add(self.test_one_crypto_full(crypto, status.OK, 'ok', target, length))
			result.add(self.test_one_crypto_full(crypto, status.WARNING, 'warn', target, length))
			result.add(self.test_one_crypto_full(crypto, status.CRITICAL, 'crit', target, length))
		return result
开发者ID:0000-bigtree,项目名称:nscp,代码行数:34,代码来源:test_nsca.py

示例9: simple_handler_wrapped

	def simple_handler_wrapped(self, arguments):
		log('Got simple message %s'%arguments)
		msg = self.get_response(arguments[0])
		msg.got_simple_response = True
		self.set_response(msg)
		rmsg = self.get_request(arguments[0])
		return (rmsg.status, rmsg.message, rmsg.perfdata)
开发者ID:Fox-Alpha,项目名称:nscp,代码行数:7,代码来源:test_nrpe.py

示例10: setup

	def setup(self, plugin_id, prefix):
		self.reg = Registry.get(plugin_id)
		self.temp_path = self.core.expand_path('${temp}')
		log('Temp: %s'%self.temp_path)
		self.work_path = os.path.join(self.temp_path, '%s.txt'%uuid.uuid4())
		log('Work: %s'%self.work_path)
		create_test_data(self.work_path)
开发者ID:0000-bigtree,项目名称:nscp,代码行数:7,代码来源:test_log_file.py

示例11: init

def init(pid, plugin_alias, script_alias):
    global world_status, plugin_id
    plugin_id = pid

    conf = Settings.get(plugin_id)
    conf.register_path('/settings/cool script', "Sample script config", "This is a sample script which demonstrates how to interact with NSClient++")
    conf.register_key('/settings/cool script', 'world', 'string', "A key", "Never ever change this key: or the world will break", "safe")

    world_status = conf.get_string('/settings/cool script', 'world', 'true')
    if world_status != 'safe':
        log('My god: its full of stars: %s'%world_status)
    
    log('Adding a simple function/cmd line')
    reg = Registry.get(plugin_id)
    reg.simple_cmdline('help', get_help)

    reg.simple_function('check_world', check_world, 'Check if the world is safe')
    reg.simple_function('break_world', break_world, 'Break the world')
    reg.simple_function('fix_world', fix_world, 'Fix the world')
    reg.simple_function('save_world', save_world, 'Save the world')
    
    reg.simple_function('show_metrics', fun_show_metrics, 'Enable displaying metrics or not')

    reg.submit_metrics(submit_metrics)
    reg.fetch_metrics(fetch_metrics)
开发者ID:Fox-Alpha,项目名称:nscp,代码行数:25,代码来源:sample.py

示例12: upsert

def upsert(path, data):
    r = requests.post(icinga_url+path, data=data, verify=False, headers=icinga_header, auth=icinga_auth)
    if r.status_code == 404:
        r = requests.put(icinga_url+path, data=data, verify=False, headers=icinga_header, auth=icinga_auth)
    if r.status_code == 500:
        log("Failed to upsert: %s: %s"%(path, r.text))
    return r
开发者ID:mickem,项目名称:nscp,代码行数:7,代码来源:icinga.py

示例13: check_bound

 def check_bound(self, filter, warn, crit, expected):
     alias = "%s/%s/%s" % (filter, warn, crit)
     result = TestResult("Checking %s" % alias)
     args = ["file=%s" % self.work_path, "column-split=,", "filter=%s" % filter, "warn=%s" % warn, "crit=%s" % crit]
     # log("Command: %s"%args)
     (ret, msg, perf) = self.core.simple_query("check_logfile", args)
     log("%s : %s -- %s" % (filter, msg, perf))
     result.add_message(ret == expected, "Check status", "Invalid check status: %s" % ret)
     return result
开发者ID:Fox-Alpha,项目名称:nscp,代码行数:9,代码来源:test_log_file.py

示例14: inbox_handler_wrapped

	def inbox_handler_wrapped(self, channel, request):
		message = plugin_pb2.SubmitRequestMessage()
		message.ParseFromString(request)
		command = message.payload[0].command
		log('Got message %s on %s'%(command, channel))
		
		msg = NSCAMessage(command)
		msg.got_response = True
		self.set_response(msg)
		return None
开发者ID:jkells,项目名称:nscp,代码行数:10,代码来源:test_nsca.py

示例15: check_bound

	def check_bound(self, filter, warn, crit, expected):
		alias = '%s/%s/%s'%(filter, warn, crit)
		result = TestResult('Checking %s'%alias)
		args = ['file=%s'%self.work_path, 'column-split=,', 'filter=%s'%filter, 'warn=%s'%warn, 'crit=%s'%crit]
		#log("Command: %s"%args)
		(ret, msg, perf) = self.core.simple_query('check_logfile', args)
		log("Messge: %s"%msg)
		log("Perf: %s"%perf)
		result.add_message(ret == expected, 'Check status', 'Invalid check status: %s'%ret)
		return result
开发者ID:0000-bigtree,项目名称:nscp,代码行数:10,代码来源:test_log_file.py


注:本文中的NSCP.log函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。