1

Machine A = nagios master, Machine B = edge machine.

In machine A's host.cfg I have:

define command {
        command_name    check_tok
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_tok 123
}

define service
        use bg-service
        hostgroup_name  test_oob1
        service_description Recall12
        check_command   check_tok
        servicegroups   nrpe
}

In Machine B's commands.cfg in /etc/nrpe.d I have:

command[check_tok]=/usr/lib64/nagios/plugins/check_test.sh

In machine's B's /usr/lib64/nagios/plugins, I have check_test.py and check_test.sh.

check.test.sh looks like the following:

#!/bin/sh
/usr/bin/sudo /usr/lib64/nagios/plugins/check_test.py
exit $?

and check_test.py looks like the following:

#!/usr/bin/env python
import sys


if __name__ == "__main__":
        if sys.argv == '123'
            print("this ok")
            sys.exit(0)
        else: 
            print('this is not 123')
            sys.exit(2)

In machine's B /etc/sudoers.d/nrpe nrpe ALL = (ALL) NOPASSWD: /usr/lib64/nagios/plugins/check_test.py

As you can see, the argument i am pasting to check_test.py is '123' and it should result in a sys.exit(0). however, in my nagios mon it said " NRPE: Unable to read output "

  • Change command[check_tok]=/usr/lib64/nagios/plugins/check_test to command[check_tok]=/usr/lib64/nagios/plugins/check_test.sh. – jordanm Dec 22 '15 at 0:44
  • Oh, i did a typo in the post, I did actually made that change. It's till doesn't work tho. – user3331457 Dec 22 '15 at 1:13
2

By default nrpe doesn't allow arguments. You may bypass this by setting dont_blame_nrpe=1 in nrpe configuration. Also your nrpe must be built with --enable-command-args. However please note that:

*** ENABLING THIS OPTION IS A SECURITY RISK! ***

That being said, you really should hardcode your arguments to nrpe command in client side.

Also you must pass arguments from your shell script to python interpreter. Adding "$@" should do the trick:

#!/bin/sh
/usr/bin/sudo /usr/lib64/nagios/plugins/check_test.py "$@"
exit $?

And sys.argv in your python script is a list, so you should write sys.argv[1] instead.

I suggest you first test your scripts locally before trying to connect from nagios side.

  • yea i tested my script locally already, there are some typoes in the post, thanks tho., – user3331457 Dec 22 '15 at 9:51
0

You need to use -a to pass args to NRPE.

Also, make the -c command call $ARG1$ so you don't have to write a separate command object for every different NRPE call.

For example:

define command {
    command_name    check_nrpe_arg
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
}

and the service def:

define service {
    use bg-service
    hostgroup_name  test_oob1
    service_description Recall12
    check_command   check_nrpe_arg!check_tok!123
    servicegroups   nrpe
}

You also need the command on the NRPE daemon side to do something with the argument (It doesn't just magically get it):

command[check_tok]=/usr/lib64/nagios/plugins/check_test.sh $ARG1$

You would then have a separate check_nrpe for calls that don't take any arguments, without the -a $ARG2$1 on the end. (This is a similar concept as the commands in Debian/Ubuntu packages, except the other way around.)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.