Page 1 of 1

Pass in varaible to nrpe

Posted: Fri May 01, 2015 6:21 am
by djs
Hi all,

I am trying to pass in a variable to an nrpe agent through nagios.

I have a nagios server and have defined a global environment variable e.g

Code: Select all

test_var=Hi
I can manually check that this varaible can be called by doing a

Code: Select all

./check_nrpe -H 123.456.7.8 -c pass_arg -a $test_var
However when I try and pass in arguments into the command e.g

Code: Select all

define service{
    use                        test-service
    host_name                  d3t
    service_description        Pass arg 1
    check_command              pass_arg_h!$test_var
}
It displpays "$" on the nagios webpage, does anybody know why this is and how variables can be passed in?

One aditional question if variables can be defined and called, is there any way to pass in a varaible that performs an action .eg

Code: Select all

define service{
test_var=`ls -l /etc/nagios/ | wc -l`

    use                        test-service
    host_name                  d3t
    service_description        Pass arg 1
    _YahooID    john32
    check_command              pass_arg_h!$test_var
}

Thanks in advance,
djs

Re: Pass in varaible to nrpe

Posted: Fri May 01, 2015 10:43 am
by ssax
Are you defining it in /usr/local/nagios/etc/resource.cfg?

If you are you should use:

Code: Select all

define service{
    use                        test-service
    host_name                  d3t
    service_description        Pass arg 1
    check_command              pass_arg_h!$test_var$
}
Instead of:

Code: Select all

define service{
    use                        test-service
    host_name                  d3t
    service_description        Pass arg 1
    check_command              pass_arg_h!$test_var
}
As far as it performing an action you would need to write a wrapper script that would perform the action that you would want to happen and then call the check command that you would want it to run.