Nagios中的插件在使用paramiko时不起作用?

2024-09-26 22:52:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我们在Nagios上遇到了一些奇怪的问题。我们用Python编写了一个脚本,它使用paramiko、httplib和re。当我们注释掉为使用paramiko而编写的代码时,脚本在Nagios中返回OK。当我们取消注释脚本时,状态只返回(null)。在

这是我们的密码

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#ssh.connect(self.get('hostname'),int(self.get('port')),self.get('username'),allow_agent=True)
ssh.connect('192.168.56.102' , 22 , 'oracle' ,allow_agent=True)
link = '127.0.0.1:4848'
stdin,stdout,stderr = ssh.exec_command('wget --no-proxy ' + link + ' 2>&1 | grep -i "failed\|error"')
result = stdout.readlines()
result = " ".join(result)

if result == "":
    return MonitoringResult(MonitoringResult.OK,'Webservice up')
else:
    return MonitoringResult(MonitoringResult.CRITICAL,'Webservice down %s' % result)

所以当我们把上面的部分注释掉的时候

^{pr2}$

在if上面添加result=“”后,它将在Nagios中返回'Webservice up'。当我们启用上面的代码时,如果它只返回(null)。和帕拉米科有冲突吗?在

在终端中运行代码时,它只返回正确的状态,但在Nagios中实现时不会显示


Tags: 代码self脚本webparamikoget状态connect
1条回答
网友
1楼 · 发布于 2024-09-26 22:52:42

我发现尽管nagios以有效用户"nagios"的身份运行,但它使用用户"root"的环境设置,无法读取根私钥来建立连接。在

key_filename='/nagiosuserhomedir/.ssh/id_dsa'添加到ssh.connect()的选项中为我解决了同样的问题(在代码中显式地传递nagios用户的私钥)。在

相关问题 更多 >

    热门问题