NRPE 状态消息
我有一种方法可以返回状态消息和状态代码。 这是我的 python 脚本中的一个示例,如何返回状态代码而不是消息: def checkResults(): 如果不是 os.path.exists(jmeter_run_log) : print“状态:未知。处理 jmeter 结果文件时出错。% 路径中结果文件不存在。” % jmeter_run_log 系统.退出(3);
numberOfFailures = 0
try:
fileHandler = open(jmeter_run_log, 'r')
#Check for failing requests
for line in fileHandler :
if line.split(jmeter_result_delimiter)[7] == "false":
numberOfFailures += 1
fileHandler.close()
except IOError, (errno, strerror):
print "Status: Critical. CRITICAL - reading jmeter results file failed with error: %s" %(strerror)
sys.exit(2)
if numberOfFailures > 0 :
print "Status: Critical. Number of failure requests = %s " % numberOfFailures
#sendNotificationEmail("Status: Critical. Number of failure requests = %s " % numberOfFailures)
sys.exit(2)
else:
print "Status: OK"
sys.exit(0)
I there a way to return status message along with status code.
Here is an example in my python script how i return status code but not message:
def checkResults():
if not os.path.exists(jmeter_run_log) :
print "Status: Unknown. Error processing jmeter results file. Results file doesn't exist by % path." % jmeter_run_log
sys.exit(3);
numberOfFailures = 0
try:
fileHandler = open(jmeter_run_log, 'r')
#Check for failing requests
for line in fileHandler :
if line.split(jmeter_result_delimiter)[7] == "false":
numberOfFailures += 1
fileHandler.close()
except IOError, (errno, strerror):
print "Status: Critical. CRITICAL - reading jmeter results file failed with error: %s" %(strerror)
sys.exit(2)
if numberOfFailures > 0 :
print "Status: Critical. Number of failure requests = %s " % numberOfFailures
#sendNotificationEmail("Status: Critical. Number of failure requests = %s " % numberOfFailures)
sys.exit(2)
else:
print "Status: OK"
sys.exit(0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你到底在问什么。 NRPE 已经将您输出到 stdout 的任何内容作为返回状态消息返回,并且还发送退出代码作为检查结果状态。 0=正常,1=警告,2=严重,3=未知。
因此,您的第一个示例和代码示例都已经返回状态字符串和状态代码。我错过了什么吗?
I'm not sure exactly what you're asking. NRPE will already return both whatever you output to stdout as the return status message, and also sends along the exit code as the check result status. 0=OK, 1=WARN, 2=CRIT, 3=UNKNOWN.
So both your first example and code sample are already returning status strings along with status code. Am I missing something?