Command's creation

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
nagios_aws
Posts: 76
Joined: Wed May 18, 2016 3:34 am

Command's creation

Post 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
You do not have the required permissions to view the files attached to this post.
gormank
Posts: 1114
Joined: Tue Dec 02, 2014 12:00 pm

Re: Command's creation

Post 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?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Command's creation

Post 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.
Former Nagios Employee
nagios_aws
Posts: 76
Joined: Wed May 18, 2016 3:34 am

Re: Command's creation

Post 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 ?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Command's creation

Post 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]
Former Nagios Employee
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command's creation

Post 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.
Be sure to check out our Knowledgebase for helpful articles and solutions!
nagios_aws
Posts: 76
Joined: Wed May 18, 2016 3:34 am

Re: Command's creation

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command's creation

Post 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!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked