Page 1 of 1

Problem parsing a perl command from GUi

Posted: Thu Jan 05, 2012 11:48 pm
by dbsaust
Hi There,

I am having a problem getting the same results form the Nagios server command line to that when I am trying to parse the same command as a stored entry via the GUI.

A collague of mine has helped by editing the count_file.pl script which is available on the forum, and allowed me to parse extra information I.e. the start of a file name, the file extension and then the maximum number of seconds in which a file of this type should be in the directory.

The command which works from the command line is as follows:
./check_nrpe -H 10.215.222.35 -c check_filename_age.pl -a '"E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\" COPE2 ITF 90000'
Found a file within age 90000 secs.


I checked against a couple of different variables just to ensure validity I.e:

(minus last directory slashes)
./check_nrpe -H 10.215.222.35 -c check_filename_age.pl -a '"E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive" COPE2 ITF 90000'
Use of uninitialized value in subtraction (-) at c:\Perl\scripts\check_filename_age.pl line 42.
Use of uninitialized value in subtraction (-) at c:\Perl\scripts\check_filename_age.pl line 42.
Use of uninitialized value in subtraction (-) at c:\Perl\scripts\check_filename_age.pl line 42.
Use of uninitialized value in subtraction (-) at c:\Perl\scripts\check_filename_age.pl line 42.
Use of uninitialized value in subtraction (-) at c:\Perl\scripts\check_filename_age.pl line 42.


(changed file name to lower case):
./check_nrpe -H 10.215.222.35 -c check_filename_age.pl -a '"E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\" cope2 itf 90000'
No file(cope2*.itf) found within last 90000 secs.


All good up to here.

Now I come to create a new service via the GUI to replicate the above and I get an error which I cannot circumvent (from the servers services config file):

define service {
host_name SYDNAS1
service_description Monitor COPE Returns Manifest Files
display_name Monitor COPE Returns Manifest Files
check_command check_nrpe_directory_2!check_filename_age.pl!'"E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\" COPE ITF 90000'!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period File Age Checks
notification_interval 180
notification_period File Age Checks
contact_groups Test_Infrastructure
register 1
}


where - check_nrpe_directory_2 = $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$
where - $ARG1$ = check_filename_age.pl
where - $ARG2$ = '"E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\" COPE ITF 90000'


All that I notice different is the 6 x exclamation marks following the command, is this possibly being passed to the perl script on the server or is it an internal working of the Nagios config itself?

Error from the Nagios GUI is as follows:
Usage: "Directory name" "File Name Start" "File Extension" "Age of files in secs"
examples: c:\\Perl\\scripts\\check_filename_age.pl <dir> RFNTRCU dat 90000


If I remove the trailing slashes from the directory path from the GUI I get the following error:
Use of uninitialized value in subtraction (-) at c:\Perl\scripts\check_filename_age.pl line 42.
Use of uninitialized value in subtraction (-) at c:\\Perl\\scripts\\check_filename_age.pl line 42.

Use of uninitialized value in subtraction (-) at c:\\Perl\\scripts\\check_filename_age.pl line 42.

Use of uninitialized value in subtraction (-) at c:\\Perl\\scripts\\check_filename_age.pl line 42.

Use of uninitialized value in subtraction (-) at c:\\Perl\\scripts\\check_filename_age.pl line 42.

No file(COPE*.ITF) found within last 90000 secs.


Note the very bottom line is incorrect as the file is present as proven when running the same command from the command line, albeit with slightly different variables.

Can you please point me down the road as to where I might be going wrong, I have spent quite a lot of time chopping and changing the command but I can't get it to work correctly atall!

Many thanks

DB

Re: Problem parsing a perl command from GUi

Posted: Fri Jan 06, 2012 3:36 pm
by scottwilkerson
It took me a while to get this right but, I got it.

With exerything else how you described, lets make

Code: Select all

$ARG2$ = '\'E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\\' COPE ITF 90000'
It really doesn't like the double quote so we needed to change to single quote and escape it.

Re: Problem parsing a perl command from GUi

Posted: Sun Jan 08, 2012 10:58 pm
by dbsaust
Hi Scott, unfortunately that doesnt command seem to work for me. I tested from both the GUI and the command line and neither provided a good return code. From the command line the response I got was as if the command hadn't completed. See examples below:

Example from command line:
./check_nrpe -H 10.215.222.35 -c check_filename_age.pl -a '\'E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\\' COPE ITF 90000'
>


Response from GUI:
Usage: "Directory name" "File Name Start" "File Extension" "Age of files in secs"
examples: c:\\Perl\\scripts\\check_filename_age.pl <dir> RFNTRCU dat 90000


Kind regards

DB

Re: Problem parsing a perl command from GUi

Posted: Mon Jan 09, 2012 10:42 am
by scottwilkerson
Can you post what you have in your check command on the windows client?

I tested this on a Linux machine, so my file path and nrpe client were a little different.

Re: Problem parsing a perl command from GUi

Posted: Mon Jan 09, 2012 10:44 am
by mguthrie
The shell can interpret the \ character as a line break, and it look like it's doing that in your test above. I'd play around with the single quotes and escaping any characters that appear to be interpreted by the shell. It's probably very close to working, it's just a matter of being escaped properly. I'd try wrapping everything after -a in single quotes and see what happens.

Re: Problem parsing a perl command from GUi

Posted: Mon Jan 09, 2012 10:46 am
by agriffin
Try this one and let us know if it changes anything:

Code: Select all

\''E:\\SchenkerEDI\\SAMSUNG\\CARRIER\\COPE\\ReturnsManifest\\Archive\\'\'' COPE ITF 90000'

Re: Problem parsing a perl command from GUi

Posted: Mon Jan 09, 2012 1:58 pm
by scottwilkerson
I've dug into these deeper and believe I have the solution for you...

First, edit the top of the check_filename_age.pl and just under use strict; add
no warnings 'all';

Then, lets make your $ARG2$ read

Code: Select all

'E:/SchenkerEDI/SAMSUNG/CARRIER/COPE/ReturnsManifest/Archive/ COPE ITF 90000'
That should do it...

Re: Problem parsing a perl command from GUi

Posted: Tue Jan 10, 2012 1:04 am
by dbsaust
Hi all,

Thanks for your help, we finally got there with Scott's last suggestion of adding "no warnings "all";" to the perl script.

My colleague who is a perl developer has also now located the Nagios config guide for perl scripting so hopefully that will be able to consult that first off and not ask too many other questions.

Happy to close off this issue.

Many thanks

DB