Page 1 of 1

Command's creation

Posted: Mon Sep 19, 2016 9:12 am
by nagios_aws
Hello,

I want to create a command using NSclient++ agent and run a Perl script of my own.

My Perl binaries are in NSClient ++ folder, without any links to Windows (not in path ...)

I currently have this in "commands" page in NagiosXI :

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -c ""perl\bin\perl.exe" "check_flex.pl"" -a $ARG1$
andh this in NCS.ini file :

Code: Select all

check_flex_windows=perl\bin\perl.exe check_flex.pl -a $ARG1$
and also a lot of options activated regarding arguments.

How can I run my Perl script in this configuration ? I have to specify the Perl path but I can't manage to make it work.

any ideas ?

Thank you

Re: Command's creation

Posted: Mon Sep 19, 2016 10:41 am
by gormank
What's the output when you run the perl script from the windows box?
What's the output when you run the service from Nagios, or the Nagios server shell as nagios?

Re: Command's creation

Posted: Mon Sep 19, 2016 4:34 pm
by rkennedy
gormank wrote:What's the output when you run the perl script from the windows box?
What's the output when you run the service from Nagios, or the Nagios server shell as nagios?
Thanks @gormank! This will be needed as well.

One thing I do notice, is your command passing to NRPE looks invalid -

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -c ""perl\bin\perl.exe" "check_flex.pl"" -a $ARG1$
Should just be -

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_flex_windows -a $ARG1$
The reason, is because once we call to check_flex_windows, it's calling directly to the command defined in your NSC.ini. You might need to adjust this -

Code: Select all

check_flex_windows=perl\bin\perl.exe check_flex.pl -a $ARG1$
to be a direct path to PERL as well. Based on your answers to what @gormank asked this will all help as well.

Re: Command's creation

Posted: Tue Sep 20, 2016 3:55 am
by nagios_aws
Hello,

thanks for your answers

the output is like this when I run it from my Windows Server ( C:\Program Files\NSClient++>perl\bin\perl.exe check_flex.pl 7250 ):

UP v11.9 MASTER

a simple text output from a Perl script.

I set this in Nagios portal :

Code: Select all

$USER1$/check_nrpe -H $HOSTADDRESS$ -c check_flex_windows -a $ARG1$
and this in NSC.ini :

Code: Select all

[External Scripts]
check_flex_windows=C:\Program Files\NSClient++\perl\bin\perl.exe check_flex.pl -a $ARG1$
I got this in Nagios webportal :

Code: Select all

UNKNOWN: No handler for that command
everything seems to be defined, am I missing something ?

Re: Command's creation

Posted: Tue Sep 20, 2016 11:13 am
by rkennedy
Can you post your NSClient++ configuration file for us to look at? If it's not finding the command usually it's just in the wrong place. NSClient++ is pretty set on where variables / fields need to be defined.

EDIT: This is applicable to 0.4.3. (lmiltchev should have 0.3.9 covered below)
For example -

Code: Select all

[/settings/external scripts/scripts]
check_flex_windows=C:\Program Files\NSClient++\perl\bin\perl.exe check_flex.pl -a $ARG1$
It'll need to be under -

Code: Select all

[/settings/external scripts/scripts]

Re: Command's creation

Posted: Tue Sep 20, 2016 11:20 am
by lmiltchev
Under the [External Scripts] section, set your command as:

Code: Select all

check_flex_windows=perl\bin\perl.exe check_flex.pl $ARG1$
Under the [External Script] section, set the following lines:

Code: Select all

command_timeout=60
allow_arguments=1
allow_nasty_meta_chars=1
Save, exit, and restart NSClient++ service on the Windows box.

Test your command by running the following command on the Nagios server:

Code: Select all

/usr/local/nagios/libexec/check_nrpe -H <client ip> -c check_flex_windows -a '7250'
Note: Modify the path to "check_nrpe" if different on your system.

Re: Command's creation

Posted: Wed Sep 21, 2016 4:17 am
by nagios_aws
Hello everyone,

Thank you for all your replies, it works now !

I used lmiltchev's last post and it finally did the trick :)

Here is my last NSC.ini without comments, can you please tell me what is really needed just to execute my script ?

I want to keep this file clean as possible.

For example, does the options in "[NRPE]" section are mandatory ? or the ones in "[External Script]" are enough ?

Thank you

Re: Command's creation

Posted: Wed Sep 21, 2016 10:57 am
by lmiltchev
For example, does the options in "[NRPE]" section are mandatory ? or the ones in "[External Script]" are enough ?
You call the external scripts via check_nrpe, so both sections NRPE and External Script are needed.

I am glad your issue has been resolved. Is it OK if we close this topic. Thanks!