Page 1 of 1

Passing arguments to Nagios NRPE commands

Posted: Wed Jun 14, 2017 6:08 am
by as300182
I'm using Nagios core v4.2.2

I have the nrpe.cfg with dont_blame_nrpe=1.

In my commands.cfg I have this:

Code: Select all

# Check NRPE Host
define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
So I am expecting this to not work:

./check_nrpe -H 10.1.10.10 -c check_mountpoint -a 'data'

However, it does. I'm a little confused as I was expecting to have to edit my commands file so that it looked like this:

Code: Select all

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

Is it possible that the check_nrpe command is overwritten somewhere else, or have I completely misunderstood the config for this command?

If it's the former, where might I expect to find the other override please? I've looked and cannot find any reference to this command anywhere else so I'm inclined to think I've missed the point somewhere!!! HELP? :(

Re: Passing arguments to Nagios NRPE commands

Posted: Wed Jun 14, 2017 8:21 am
by mcapra
Just to clarify, your Nagios object definitions (like your command definition in this case) bear absolutely no weight on what Linux is doing. Calling check_nrpe from the command line like so:

Code: Select all

./check_nrpe -H 10.1.10.10 -c check_mountpoint -a 'data'
Has absolutely nothing to do with any Nagios configurations. A command definition in Nagios only goes as far as other Nagios object definitions. For example, using your check_nrpe command definition:

Code: Select all

# Check NRPE Host
define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
This definition can be leveraged in a service definition's check_command parameter like so:

Code: Select all

define service{
...
		check_command			check_nrpe!some_arg1_value_here
...
        }
Which would then input some_arg1_value_here as the value for $ARG1$ when the command is ultimately executed.

Where you might run into trouble is, as you suspected, when you are attempting to pass arguments via a check_command when the corresponding command definition isn't accounting for them. So if you only were accepting an $ARG1$ value (as with the above command definition) and tried something like this:

Code: Select all

check_command			check_nrpe!some_arg1_value_here!some_arg2_value_here
That would be a totally valid check_command parameter for any host/service, but some_arg2_value_here would be dropped because the check_nrpe command definition is only expecting a single argument ($ARG1$).

Re: Passing arguments to Nagios NRPE commands

Posted: Wed Jun 14, 2017 10:38 am
by scottwilkerson
@mcapra is correct, when you run the following from the Linux command line it works because you have the correct settings on the remote side

Code: Select all

./check_nrpe -H 10.1.10.10 -c check_mountpoint -a 'data'
But this is NOT what Nagios will run under the hood, It will use the command definition, which you will need to change as suggested.