如何在Nagios中使用Python文件?

2024-06-09 14:08:24 发布

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

我试图使用以下Python代码和说明从Nagios获得响应: http://skipperkongen.dk/2011/12/06/hello-world-plugin-for-nagios-in-python/

由于某些原因,我从Nagios那里永远无法得到OK,它总是返回消息:返回代码126超出了界限-插件可能丢失

我安装了nagiosplugin 1.0.0,但似乎什么也没用 同时,我还有一些其他服务(不是python文件)可以工作,例如http检查、当前用户和SSH

我做错什么了?我已经试着解决了好几天了


Tags: 代码inhttp消息helloforworld原因
2条回答

让Nagios使用您的新插件非常容易。您应该更改三个文件并重新启动Nagios—仅此而已。

第一个文件是/etc/nagios/command plugins.cfg(如果您知道这个文件的路径或在ubuntu中的模拟文件,请留下注释)。假设插件文件位于/usr/lib/nagios/plugins/目录中:

command[check_hello_world]=/usr/lib/nagios/plugins/check_helloworld.py -m 'some message'

下拉一个目录到/etc/nagios/objects/commands.cfg(对于ubuntu用户应该在该目录中创建cfg文件/etc/nagios plugins/config/):

define command {
    command_name    check_hello_world
    command_line    $USER1$/check_hello_world.py -m 'some message'
}

保存文件并打开/etc/nagios/objects/localhost.cfg(位于/etc/nagios3/nagios.cfg中的服务定义文件的ubuntu路径中,默认情况下为cfg-dir=/etc/nagios3/conf.d。因此,要在ubuntu中定义新服务,用户应该在该目录中创建cfg文件,例如hello.cfg)。定位此部分:

#
# SERVICE DEFINITIONS
#

并添加新条目:

define service {
    use                 local-service ; Name of service template to use
    host_name           localhost
    service_description Check using the hello world plugin (always returns OK)
    check_command       check_hello_world
}

剩下的就是重新启动Nagios并验证插件是否正常工作。通过发出以下命令重新启动Nagios:

/etc/init.d/nagios restart

http://www.linux-mag.com/id/7706/

ubuntuforums.org-Thread: My Notes for Installing Nagios on Ubuntu Server 12.04 LTS

尽管文件中的shebang指定了python2.7的路径,但我还是必须预先设置它的路径。

在命令定义中,我有:

command_line /usr/local/bin/python2.7 $USER1$/check_rabbit_queues.py --host $HOSTADDRESS$ --password $ARG1$

即使实际python文件的顶部有:

#!/usr/bin/env python2.7

即使脚本在没有指定解释器的情况下从命令行执行并返回得很好。

我试过的其他方法都不管用。

相关问题 更多 >