Megaraid Nagios监视

发布于 2025-02-11 12:40:22 字数 1369 浏览 1 评论 0原文

我一直在撞墙,试图弄清楚我写的以下Nagios插件有什么问题。当我运行以下代码时:

#!/usr/bin/env python3
import paramiko
import os.path
import sys
OK = 0
WARNING = 1
CRITICAL = 2
DEPENDENT = 3
UNKNOWN = 4
active = str("Active")
online = str("Online")
optimal = str("Optimal")
k = str("OK")
degrade = str("Degraded")
fail = str("Failed")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
        hostname='<hostname>',
        username='<service account>', 
        key_filename=os.path.join(os.path.expanduser('~'), ".ssh", "id_rsa.pub")
        )
stdin,stdout,stderr = client.exec_command("sudo /opt/MegaRAID/MegaCli/MegaCli64 -ShowSummary -a0")
check = str(stdout.read().decode('ascii'))
client.close()
OK_STR = str("RAID is OK!")
WARN_STR = str("Warning! Something is wrong with the RAID!")
CRIT_STR = str("CRITICAL! THE RAID IS BROKEN")
UNK_STR = str("Uh oh! Something ain't right?")
print(check)
if (degrade) in (check):
    print(WARN_STR) and sys.exit(WARNING)
elif (fail) in (check):
    print(CRIT_STR) and sys.exit(CRITICAL)
elif str('Exit Code: 0x00') in (check):
    print(OK_STR) and sys.exit(OK) 
else:
    sys.exit(UNKNOWN) and print(UNK_STR)

我会收到我期望从CLI运行的输出。如果我更改IF语句上的逻辑,则退出代码更改,并且使用“ Echo $?”进行了验证。

但是,在我的Librenm前端,我没有收到Stdout消息和1的退出代码,这不是我的代码在终端中输出的方式。如果有人发现我的代码有问题,我确实需要帮助。

I have been beating my head against the wall, trying to figure out what is wrong with the following nagios plugin I wrote. When I run the following code:

#!/usr/bin/env python3
import paramiko
import os.path
import sys
OK = 0
WARNING = 1
CRITICAL = 2
DEPENDENT = 3
UNKNOWN = 4
active = str("Active")
online = str("Online")
optimal = str("Optimal")
k = str("OK")
degrade = str("Degraded")
fail = str("Failed")
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
        hostname='<hostname>',
        username='<service account>', 
        key_filename=os.path.join(os.path.expanduser('~'), ".ssh", "id_rsa.pub")
        )
stdin,stdout,stderr = client.exec_command("sudo /opt/MegaRAID/MegaCli/MegaCli64 -ShowSummary -a0")
check = str(stdout.read().decode('ascii'))
client.close()
OK_STR = str("RAID is OK!")
WARN_STR = str("Warning! Something is wrong with the RAID!")
CRIT_STR = str("CRITICAL! THE RAID IS BROKEN")
UNK_STR = str("Uh oh! Something ain't right?")
print(check)
if (degrade) in (check):
    print(WARN_STR) and sys.exit(WARNING)
elif (fail) in (check):
    print(CRIT_STR) and sys.exit(CRITICAL)
elif str('Exit Code: 0x00') in (check):
    print(OK_STR) and sys.exit(OK) 
else:
    sys.exit(UNKNOWN) and print(UNK_STR)

I recieve the output that I expect running it from CLI. If I change my logic on the if statement, the exit code changes and I have verified using 'echo $?'.

However, in my LibreNMS front end, I receive no stdout message and an exit code of 1, which is not how my code outputs in the terminal. If anybody can find something wrong with my code, I really need the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文