[SOLVED] No output returned from plugin

Greetings,

I’ve searched this topic via google and these forums, and I tried a bunch of stuff, but I still can’t get this to work. I’m trying to write a custom plugin in python. The plugin is just a “hello world”. I’ve gotten most of the other “built-in” plugins to work correctly.

The python script looks like this:

[code]import os
import sys

def main():
print “Python file ran OK!”

if called by command line, call main method

if name==“main”:
main()[/code]

On my nagios SERVER, I created the following service definition:

# This is a service that will run a custom python file, this is testing to make sure we can do this correctly define service{ use generic-service ; Name of service template to use host_name <hostName> <---- Omitted for privacy service_description Run Python File check_command check_nrpe!run_python_file }

Then, I restarted the nagios service.

On the nagios CLIENT, I created the following command definition:

Then, I restarted the xinetd service.

On the client, I logged in as the “nagios” user, and I ran the following:
/opt/ActivePython-2.6/bin/python /temp/test.py
Python file ran OK!

On the server, I logged in as the “nagios” user, and I ran the following:
/usr/local/nagios/libexec/check_nrpe -H -c run_python_file
Python file ran OK!

So the command is able to be manually run on the remote host, as well as manually run from the server through nrpe.

So why can’t the nagios server run the command? Why do I have this error message?

I have only made plugin on windows so far…but perhaps nagios needs you to reurn an exit code (ok, warning, critical,unknown) and well formated performance data to work

I was reading the plugin developer’s guide, and it looks like all you need is an errorcode (0,1,2,3) and a line of STDOUT.

What language did you write your plugin in? What steps did you do to write it? I’m so confused since it’s working through the command line, so I don’t think I did anything wrong, but for some reason the web GUI doesn’t run it correctly.

Omg I FINALLY solved this issue:

On my server, my check_nrpe command looks like this:

# 'check_nrpe' command definition define command{ command_name check_nrpe command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ }

The problem is that my run_python_file command takes no args, and the -a switch was messing everything up.

This is a HUGE gotcha, because the logs dont complain about the extra -a. The command just doesn’t work.

LET IT BE KNOWN THAT IF YOU CREATE A CUSTOM PLUGIN THAT TAKES NO ARGS, YOU NEED TO CREATE A CUSTOM CHECK_NRPE COMMAND THAT MATCHES IT, OR IT WILL FAIL.

I had to do the following:

# 'check_nrpe' with no args define command{ command_name check_nrpe_no_args command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }

Then, I modified my service to:

# This is a service that will run a custom python file, this is testing to make sure we can do this correctly define service{ use generic-service ; Name of service template to use hostgroup_name build-machines service_description Run Python File check_command check_nrpe_no_args!run_python_file }

And everything worked just fine.

On a related note, I have a comment about plugins in general.

It seems that you don’t have to define a command on the server if you’re ONLY going to run it through NRPE.

For example, I have a command called run_python_file that I commented out of the commands.cfg on my server. It’s only called through NRPE on the server, and it’s defined on the client, and it seems to work.

Just FYI =)

Also, can anyone think of any reason you would ever call ping through NRPE? Doesn’t it just make more sense to ping the machine you’re interested in with check_ping directly?

Let’s say we have three locations: A, B and C. Nagios server is in A, the link between B and C has problems… i want B to ping C… different routings and from A i could’nt know if the B-C link is giving problems or not… i’d rather go for a check_snmp on the router probably, but hey, you wanted an example :mrgreen: