Page 2 of 2

Re: Monitoring a Windows Directory Config Issue

Posted: Sun Oct 23, 2011 6:47 pm
by dbsaust
Hi Nichlolas,

Unfortunately still no luck after trying the following and restarting the NSCLIENT++:

Uncommented:
[NRPE]
;# COMMAND ARGUMENT PROCESSING
; This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed.
allow_arguments=1
;
;# COMMAND ALLOW NASTY META CHARS
; This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow_nasty_meta_chars=1
;
;# SCRIPT DIRECTORY
; All files in this directory will become check commands.
; *WARNING* This is undoubtedly dangerous so use with care!
script_dir=C:\Perl\scripts
;
; Script to check external scripts and/or internal aliases.
CheckExternalScripts.dll

[External Script]
;# COMMAND ARGUMENT PROCESSING
; This option determines whether or not the NRPE daemon will allow clients to specify arguments to commands that are executed.
allow_arguments=1
;
;# COMMAND ALLOW NASTY META CHARS
; This option determines whether or not the NRPE daemon will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow_nasty_meta_chars=1
;
;# SCRIPT DIRECTORY
; All files in this directory will become check commands.
; *WARNING* This is undoubtedly dangerous so use with care!
script_dir=C:\Perl\scripts

I noticed an issue with qualifying the directory in the logs after trying this, so made ammendments to the command as follows:
./check_nrpe -H 10.215.222.217 -c count_file.pl -a 'c:\documents and settings\sqladmin\desktop\test 0 0'

Here's the new (debug) log output, but still an issue with the handler...
2011-10-24 11:05:22: debug:NSClient++.cpp:863: No shared session: ignoring change event!
2011-10-24 11:05:45: debug:NSClient++.cpp:1144: Injecting: count_file.pl: c:\documents and settings\sqladmin\desktop\test 0 0
2011-10-24 11:05:45: message:NSClient++.cpp:1195: No handler for command: 'count_file.pl'
2011-10-24 11:05:45: message:include\NSCHelper.cpp:238: No handler for command 'count_file.pl'.

Any ideas?

Kind regards

DB

Re: Monitoring a Windows Directory Config Issue

Posted: Mon Oct 24, 2011 10:06 am
by mguthrie
./check_nrpe -H 10.215.222.217 -c count_file.pl -a 'c:\documents and settings\sqladmin\desktop\test 0 0'
Right now you're telling NSClient to run a script, when you need to tell it to execute a defined command. For security reasons it won't let you execute something on the windows side unless there's a receiving command defined for it.

Here's the NSClient documentation on executing external scripts on the windows side:
http://www.nsclient.org/nscp/wiki/CheckExternalScripts

Re: Monitoring a Windows Directory Config Issue

Posted: Mon Oct 24, 2011 7:38 pm
by dbsaust
Thanks for the link Nicholas, I've tweaked the nsc.ini file to allow for the script in question, it goes as such:

[External Scripts]
;check_es_long=scripts\long.bat
;check_es_ok=scripts\ok.bat
;check_es_nok=scripts\nok.bat
;check_vbs_sample=cscript.exe //T:30 //NoLogo scripts\check_vb.vbs
;check_powershell_warn=cmd /c echo scripts\powershell.ps1 | powershell.exe -command -
count_file.pl=c:\Perl\bin\perl.exe c:\Perl\scripts\count_file.pl $ARG1$

(Initially the logs were suggesting I need to start by qualifying where perl.exe is, so that's why that's now there)

Since then I've reworked my syntax from the command line as follows to get the result I was after (single quote followed by double_quote):

./check_nrpe -H 10.215.222.217 -c count_file.pl -a '"C:\documents and settings\sqladmin\desktop\test" 0 0'

Now I just need to get this to work from the Nagios GUI!

Many thanks

DB

Re: Monitoring a Windows Directory Config Issue

Posted: Tue Oct 25, 2011 11:28 am
by mguthrie
Very cool. Let us know if you have any more questions.

Re: Monitoring a Windows Directory Config Issue

Posted: Tue Oct 25, 2011 7:40 pm
by dbsaust
Hi Nicholas/mguthrie,

I'm stumbling at the last hurdle with creating this service through the GUI. I have the service set up through the GUI as follows (exert from the services config file for this server following a config push):

define service {
host_name AUITSUPPORT01
service_description Monitor Test Directory
use xiwizard_windowsserver_nsclient_service
hostgroup_name Test_Infrastructure
display_name Monitor Test Directory for Files
servicegroups Test
check_command count_file!'"C:\documents and settings\sqladmin\desktop\test" 0 0'!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period workhours
notification_interval 60
notification_period workhours
contact_groups Test_Infrastructure
_xiwizard windowsserver
register 1
}

Here's a generic service setup via the Wizard from the same config file for comparison:
define service {
host_name AUITSUPPORT01
service_description Ping
use xiwizard_windowsserver_ping_service
servicegroups Test
max_check_attempts 5
check_interval 5
retry_interval 1
check_period xi_timeperiod_24x7
notification_interval 60
notification_period xi_timeperiod_24x7
contact_groups admins
_xiwizard windowsserver
register 1
}

However after trying a number of variations of the syntax and config of the service I still can't seem to get this to run remotely, in fact there is no show in the remote server's log file to suggest that this command is running atall, even though it is showing in the GUI as a service and me having ran the "schedule an immediate check" facility on numerous occasions today. The only way I see any trace in the log is if I run the command myself from the command line on the Nagios server. Is there somewhere else I need to include any relational service config files so that it will trigger the command on the remote server?

Last seen log trace of the command being run:
2011-10-25 16:50:53: debug:NSClient++.cpp:1144: Injecting: count_file.pl: "C:\documents and settings\sqladmin\desktop\test" 0 0
2011-10-25 16:50:53: debug:NSClient++.cpp:1180: Injected Result: CRITICAL 'Critical: Filecount of 'C:\documents and settings\sqladmin\desktop\test' too large 1 > 0.'
2011-10-25 16:50:53: debug:NSClient++.cpp:1181: Injected Performance Result: ''

I've tried to read up various parts of the admin guide for assistance but nothing is striking out at me on where to go next... any ideas what is going wrong?

Many thanks

DB

Re: Monitoring a Windows Directory Config Issue

Posted: Fri Oct 28, 2011 9:27 am
by mguthrie
Ok, I think I see the issue. When you run this on the command-line

Code: Select all

./check_nrpe -H 10.215.222.217 -c count_file.pl -a '"C:\documents and settings\sqladmin\desktop\test" 0 0'
What you need to execute this through NRPE is something like this:

- set your "check command" for that service to the check_nrpe.

For $ARG1$ use the name of the defined command on the windows machine, which should be count_file.pl
For $ARG2$, try passing this:
-a " 'C:\documents and settings\sqladmin\desktop\test' 0 0"

Note that the directory location is in single quotes. This is just to be safe so that the shell doesn't try to interpret the backslashes.

Re: Monitoring a Windows Directory Config Issue

Posted: Sun Oct 30, 2011 7:17 pm
by dbsaust
Hi mguthrie,

Thanks for your help again, I've finally cracked it! As soon as you mentioned running check_nrpe check as the check command it all made perfect sense! For the record I had to tweak the argument a little, so for reference if anyone else needs to use this command and is having issues, the final command as $ARG2$ worked only when set to:

-a '"C:\\documents and settings\\sqladmin\\desktop\\test" 0 0'
(Double backslashes required)

Thanks again for your assistance, happy to close this down.

Many thanks

DB