简体   繁体   English

如何在Nagios中使用Python文件?

[英]How do I use Python file in Nagios?

I'm trying to get a response from Nagios by using the following Python code and instructions: http://skipperkongen.dk/2011/12/06/hello-world-plugin-for-nagios-in-python/ 我正在尝试通过使用以下Python代码和说明来获得Nagios的响应: http : //skipperkongen.dk/2011/12/06/hello-world-plugin-for-nagios-in-python/

From some reason I never get to have OK from Nagios and it's always comes back with the message: Return code 126 is out of bounds - plugin may be missing 由于某种原因,我从Nagios那里无法获得成功,并且总是返回以下消息:返回代码126超出范围-插件可能丢失

I installed nagiosplugin 1.0.0, and still nothing seems to be working In parallel I have some other services (not python files) that work eg http check, current users, and SSH 我安装了nagiosplugin 1.0.0,但似乎仍然没有任何工作。同时,我还有一些其他服务(而非python文件)可以正常工作,例如http check,当前用户和SSH

What am I doing wrong? 我究竟做错了什么? I'm trying to solve that for few days already 我已经尝试解决了几天

Getting Nagios to utilize your new plug-in is quite easy. 让Nagios利用您的新插件非常容易。 You should make changes to three files and restart Nagios — that's all it takes. 您应该更改三个文件,然后重新启动Nagios,仅此而已。

The first file is /etc/nagios/command-plugins.cfg (leave comment please if you know path to this file or analog in ubuntu ). 第一个文件是/etc/nagios/command-plugins.cfg (如果您知道ubuntu中该文件或类似文件的路径,请留下评论)。 Assumed that plugin file is placed in /usr/lib/nagios/plugins/ directory: 假设插件文件位于/ usr / lib / nagios / plugins /目录中:

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

Drop down one directory to /etc/nagios/objects/commands.cfg (for ubuntu user should create cfg file in that dir /etc/nagios-plugins/config/ ): 将一个目录下拉到/etc/nagios/objects/commands.cfg (对于ubuntu用户,应在该目录/ etc / nagios-plugins / config /中创建cfg文件):

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

Save the file and open up /etc/nagios/objects/localhost.cfg (in ubuntu path to service definition files located in /etc/nagios3/nagios.cfg and by default cfg_dir=/etc/nagios3/conf.d . So, to define new service in ubuntu user should create cfg file in that dir, for example hello.cfg ). 保存文件并打开/etc/nagios/objects/localhost.cfg (在/etc/nagios3/nagios.cfg中的服务定义文件的ubuntu路径中,默认情况下为cfg_dir = / etc / nagios3 / conf.d。 )在ubuntu中定义新服务,用户应在该目录中创建cfg文件,例如hello.cfg )。 Locate this section: 找到此部分:

#
# SERVICE DEFINITIONS
#

and add new entry: 并添加新条目:

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
}

All that remains is to restart Nagios and to verify that plug-in is working. 剩下的就是重启Nagios并验证插件是否正常工作。 Restart Nagios by issuing the following command: 发出以下命令,重新启动Nagios:

/etc/init.d/nagios restart

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

ubuntuforums.org - Thread: My Notes for Installing Nagios on Ubuntu Server 12.04 LTS ubuntuforums.org- 线程:在Ubuntu Server 12.04 LTS上安装Nagios的我的笔记

I had to prepend the path to python2.7 even though the shebang in the file specified it. 即使文件中的shebang指定了它,我也必须在python2.7之前添加路径。

In the command definition I had this: 在命令定义中,我有以下内容:

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

Even though the top of the actual python file had: 即使实际python文件的顶部具有:

#!/usr/bin/env python2.7

Even though the script executed and returned just fine from the command line without specifying the interpreter. 即使脚本在没有指定解释器的情况下执行并从命令行返回就可以了。

Nothing else I tried seemed to work. 我尝试过的其他方法似乎都没有效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM