• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python NSCP.log函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: simple_inbox_handler_wrapped

	def simple_inbox_handler_wrapped(self, channel, source, command, status, message, perf):
		log('Got simple message %s on %s'%(command, channel))
		msg = NSCAMessage(command)
		msg.source = source
		msg.status = status
		msg.message = message
		msg.perfdata = perf
		msg.got_simple_response = True
		self.set_response(msg)
		return True
开发者ID:jkells,项目名称:nscp,代码行数:10,代码来源:test_nsca.py


示例17: submit_payload

	def submit_payload(self, alias, ssl, length, source, status, msg, perf, target):
		message = plugin_pb2.QueryRequestMessage()
		
		message.header.destination_id = target
		message.header.command = 'nrpe_forward'
		host = message.header.hosts.add()
		host.address = "127.0.0.1:15666"
		host.id = target
		if (target == 'valid'):
			pass
		else:
			enc = host.metadata.add()
			enc.key = "use ssl"
			enc.value = '%s'%ssl
			enc = host.metadata.add()
			enc.key = "payload length"
			enc.value = '%d'%length
		enc = host.metadata.add()
		enc.key = "timeout"
		enc.value = '5'

		uid = str(uuid.uuid4())
		payload = message.payload.add()
		payload.command = 'check_py_nrpe_test_s'
		payload.arguments.append(uid)
		rmsg = self.get_request(uid)
		rmsg.status = status
		rmsg.message = msg
		rmsg.perfdata = perf
		self.set_request(rmsg)
		(result_code, response) = self.core.query('ignored', message.SerializeToString())
		response_message = plugin_pb2.QueryResponseMessage()
		response_message.ParseFromString(response)
		result = TestResult('Testing NRPE: %s for %s'%(alias, target))
		
		found = False
		for i in range(0,10):
			if self.has_response(uid):
				rmsg = self.get_response(uid)
				#result.add_message(rmsg.got_response, 'Testing to recieve message using %s'%alias)
				result.add_message(rmsg.got_simple_response, 'Testing to recieve simple message using %s'%alias)
				result.add_message(len(response_message.payload) == 1, 'Verify that we only get one payload response for %s'%alias, '%s != 1'%len(response_message.payload))
				if len(response_message.payload) == 1 and len(response_message.payload[0].lines) == 1:
					result.assert_equals(response_message.payload[0].result, status, 'Verify that status is sent through %s'%alias)
					result.assert_equals(response_message.payload[0].lines[0].message, msg, 'Verify that message is sent through %s'%alias)
					#result.assert_equals(rmsg.perfdata, perf, 'Verify that performance data is sent through')
				self.del_response(uid)
				found = True
				break
			else:
				log('Waiting for %s (%s/%s)'%(uid,alias,target))
				sleep(500)
		if not found:
			result.add_message(False, 'Testing to recieve message using %s'%alias)
		return result
开发者ID:Fox-Alpha,项目名称:nscp,代码行数:55,代码来源:test_nrpe.py


示例18: cleanup_files

	def cleanup_files(self):
		for data in self.test_data:
			self.delete_file(data[0], data[3])
		for data in self.test_data:
			self.delete_file(data[0], data[3])
		if os.path.exists(self.work_path):
			try:
				os.rmdir(self.work_path)
			except OSError, (errno, strerror):
				log('Failed to delete folder: %s'%self.work_path)
				log('Failed to delete folder: %s'%errno)
开发者ID:Vilse1202,项目名称:nscp,代码行数:11,代码来源:test_w32_file.py


示例19: add_host

def add_host(server_name, address, os_version):
    payload = {
        "attrs": { 
            "address": address, 
            "check_command": "hostalive",
            "vars.os": "Windows",
            "vars.version": os_version
        }
    }
    r = upsert('/v1/objects/hosts/%s'%server_name, json.dumps(payload))
    log("Host for %s created: %d: %s"%(address, r.status_code, r.text))
开发者ID:mickem,项目名称:nscp,代码行数:11,代码来源:icinga.py


示例20: simple_inbox_handler_wrapped

	def simple_inbox_handler_wrapped(self, channel, source, command, status, message, perf):
		message = unicodedata.normalize('NFKD', message).encode('ascii','ignore')
		log('Got simple message %s on %s'%(command, channel))
		self.got_simple_response = True
		self.last_source = source
		self.last_command = command
		self.last_status = status
		self.last_message = message
		self.message_count = self.message_count + 1
		self.last_perfdata = perf
		return True
开发者ID:jkells,项目名称:nscp,代码行数:11,代码来源:test_eventlog.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python NSCP.log_debug函数代码示例发布时间:2022-05-24
下一篇:
Python NS.NS类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap