Python nagiosplugin:如何根据值显示不同的fmt_度量?

Python nagiosplugin:如何根据值显示不同的fmt_度量?,python,plugins,nagios,Python,Plugins,Nagios,我正在编写一个Nagios插件,它使用来自的xml输出计算SSL分数 这是我的代码: 如果certificateMatchesServerHostname='True'并在.days>0过期,validationResult='ok': ... 最终评分=协议评分*0.3+关键评分*0.3+密码评分*0.4 返回[nap.Metric('sslscore',最终分数,最小值=0,最大值=100] elif证书匹配服务器主机名!='是的: 返回[nap.Metric('serverHostname

我正在编写一个Nagios插件,它使用来自的xml输出计算SSL分数

这是我的代码:

如果certificateMatchesServerHostname='True'并在.days>0过期,validationResult='ok':
...
最终评分=协议评分*0.3+关键评分*0.3+密码评分*0.4
返回[nap.Metric('sslscore',最终分数,最小值=0,最大值=100]
elif证书匹配服务器主机名!='是的:
返回[nap.Metric('serverHostname',hostnameValidation[0].attrib['serverHostname'])]

在朋友的帮助下,我终于解决了这个问题

关于第一个问题,我们可以使用模块更改状态行,如下所示:

SSLCONFIGURATION CRITICAL - The certificate does not match the host name a.b.c.d (outside range 0:)
critical: The certificate does not match the host name a.b.c.d (outside range 0:)
| serverHostname=a.b.c.d
类SSL配置(nap.Resource):
定义初始化(自身、主机、端口):
self.host=host
self.port=端口
def检查(自我):
...
如果hostname\u validation.startswith('OK')并在\u.days>0过期,并且\u受信任=='OK':
最终评分=协议评分*0.3+关键评分*0.3+密码评分*0.4
其他:
最终得分=0
返回(主机名验证、受信任、过期天数、最终分数)
def探头(自身):
如果self.check()[3]>0:
返回[nap.Metric('sslscore',self.check()[3])]
elif not self.check()[0]。开始使用('OK'):
返回[nap.Metric('sslscore',0,context='serverHostname')]
elif self.check()[1]!='好的:
返回[nap.Metric('sslscore',0,context='validationResult')]

elif self.check()[2]子类化
nagiosplugin.Summary
是正确的方法,但我认为您的Summary类不应该创建新的资源对象。
SSLCONFIGURATION CRITICAL - final_score is 0 (The certificate does not match the host name a.b.c.d) | sslscore=0;@65:80;@65;0;100
critical: The certificate does not match the host name a.b.c.d (outside range 0:)
check_ssl_configuration.py -H google.com
SSLCONFIGURATION OK - sslscore is 87 | sslscore=87.0;@65:80;@65

check_ssl_configuration.py -H 173.194.127.169
SSLCONFIGURATION CRITICAL - sslscore is 0 (FAILED - Certificate does NOT match 173.194.127.169) | sslscore=0;@65:80;@65