user2314782
user2314782

Reputation: 23

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/

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

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 e.g. http check, current users, and SSH

What am I doing wrong? I'm trying to solve that for few days already

Upvotes: 2

Views: 8651

Answers (2)

Joshua Grigonis
Joshua Grigonis

Reputation: 768

I had to prepend the path to python2.7 even though the shebang in the file specified it.

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:

#!/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.

Upvotes: 0

ndpu
ndpu

Reputation: 22561

Getting Nagios to utilize your new plug-in is quite easy. You should make changes to three files and restart Nagios — that’s all it takes.

The first file is /etc/nagios/command-plugins.cfg (leave comment please if you know path to this file or analog in ubuntu). Assumed that plugin file is placed in /usr/lib/nagios/plugins/ directory:

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/):

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). 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. Restart Nagios by issuing the following command:

/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

Upvotes: 1

Related Questions