Nagios/Centreon错误:返回代码127超出界限:插件可能丢失

2024-05-29 04:59:34 发布

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

作为IT项目的一部分,我与Nagios一起工作。 为了得到温度传感器的值,我创建了一个python插件,它将读取数据库中的值,并在屏幕上打印。

问题是,当我想监视基于此插件的服务时,它在CentreonWeb界面中显示为CRITICAL,并出现错误“(Return code 127 is out of bounds) plugin may be missing”。

以下是我的安装摘要:

  • Nagios+NDOutils(+Centreon Web界面)安装在Debian 7.5上: http://fr.scribd.com/doc/239973292/1-Installation-Manuelle-de-Nagios-Centreon-Debian#scribd

  • 我创建了一个python插件“cigne_plugin.py”,它将读取数据库中的值,并在屏幕上打印。

  • /usr/local/nagios/libexec

    中添加了文件“cigne_python.py
  • 在文件/usr/local/nagios/etc/resource.cfg中,$USER1$宏定义在/usr/local/nagios/libexec

  • /usr/local/nagios/etc/checkcommands.cfg中,我添加了以下行:

    define command{
        command_name        arduino_temp_sensor
        command_line        $USER1$/cigne_plugin.py
    }
    
  • /usr/local/nagios/etc/objects/commands.cfg中,我添加了以下行:

    define command{
        command_name        arduino_temp_sensor
        command_line        $USER1$/cigne_plugin.py
    }
    
  • /usr/local/nagios/etc/objects/localhost.cfg中:

    define service{
        use             local-service
        host_name           localhost
        service_description     Arduino Temp
        check_command               arduino_temp_sensor
        notification_enabled        0
    }
    
  • 在Centreon Web界面中添加命令“arduino_temp_sensor”(配置->;命令)

  • 在Centreon Web界面中添加服务“Arduino Temp”(配置->;服务)

  • 检查文件权限

  • 检查脚本是否可以执行

  • 检查文件所有者

  • 检查用户和组

  • /usr/local/nagios/etc/services.cfg中,我的服务是为“localhost”创建的

我试过用插件版本注释所有代码,结果只返回“sys.exit(2)”,问题不是源于代码。


Tags: 文件py插件界面usrlocaletccfg
1条回答
网友
1楼 · 发布于 2024-05-29 04:59:34

让我们尝试构建test_wrapper.sh shell脚本,看看是否有一些更一般的问题,或者它是否只是与python隔离的。

[joe@joeyoung.io libexec]# pwd
/usr/local/nagios/libexec
[joe@joeyoung.io libexec]# cat <<EOF >> test_wrapper.sh
> #!/bin/sh
> echo "OK"
> exit 0
> EOF
[joe@joeyoung.io libexec]# cat test_wrapper.sh
#!/bin/sh
echo "OK"
exit 0
[joe@joeyoung.io libexec]# ls -al test_wrapper.sh
-rw-r--r-- 1 joe joe 27 Aug  6 15:48 test_wrapper.sh
[joe@joeyoung.io libexec]# chmod a+x test_wrapper.sh
[joe@joeyoung.io libexec]# ls -al test_wrapper.sh
-rwxr-xr-x 1 joe joe 27 Aug  6 15:48 test_wrapper.sh
[joe@joeyoung.io libexec]# ./test_wrapper.sh
OK

“确定”显示输出正常。

[joe@joeyoung.io libexec]# echo $?
0

返回代码显示返回代码正常。

现在让我们构建一个简单的test_wrapper.py来消除python代码内容的任何问题。

[joe@joeyoung.io libexec]# cat <<EOF >> test_wrapper.py
> import sys
>
> def main():
>         print "OK"
>         sys.exit(0)
>
> if __name__ == '__main__':
>         main()
> EOF
[joe@joeyoung.io libexec]# cat test_wrapper.py
import sys

def main():
        print "OK"
        sys.exit(0)

if __name__ == '__main__':
        main()
[joe@joeyoung.io libexec]# ls -al test_wrapper.py
-rw-r--r-- 1 joe joe 124 Aug  6 15:58 test_wrapper.py
[joe@joeyoung.io libexec]# chmod a+x test_wrapper.py
[joe@joeyoung.io libexec]# ls -al test_wrapper.py
-rwxr-xr-x 1 joe joe 124 Aug  6 15:58 test_wrapper.py
[joe@joeyoung.io libexec]# python test_wrapper.py
OK

“确定”显示输出正常。

[joe@joeyoung.io libexec]# echo $?
0

返回代码显示返回代码正常。

最后,让我们添加命令和服务定义,以便我们可以通过Nagios web接口对其进行测试。

修改/usr/local/nagios/etc/objects/commands.cfg

注意:我们只修改一个commands.cfg文件,这样就不会有重复的命令定义来混淆Nagios。我们暂时忽略checkcommands.cfg

添加:

define command {
        command_name                    sh_test_wrapper
        command_line                    $USER1$/test_wrapper.sh
        register                        1
}
define command {
        command_name                    python_test_wrapper
        command_line                    /usr/bin/python $USER1$/test_wrapper.py
        register                        1
}

修改/usr/local/nagios/etc/objects/localhost.cfg

添加:

define service{
    use             local-service
    host_name           localhost
    service_description     sh test wrapper
    check_command               sh_test_wrapper
    notification_enabled        0
    register                        1
}
define service{
    use             local-service
    host_name           localhost
    service_description     python test wrapper
    check_command               python_test_wrapper
    notification_enabled        0
    register                        1
}

让我们验证配置文件

[joe@joeyoung.io libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

重新启动Nagios。

[joe@joeyoung.io libexec]# service nagios restart

让我们看看这些非常基本的检查是否有效,看看我们能否进一步缩小问题的范围。

相关问题 更多 >

    热门问题