Page 1 of 1

nrpe and bat file

Posted: Tue Sep 22, 2015 2:47 am
by tuumk
helo i have a problem with execution bat file via nrpe service
check_select.bat:
echo off
for /F %%i in ('sqlcmd -S "127.0.0.1" -U "nagios" -P "112345" -i C:\nagios\test.sql') do (set count=%%i)
IF %count% LSS 1000 GOTO kok
IF %count% GTR 18000 GOTO war
:err
exit /b 2
:war
IF %count% GTR 19000 goto err
exit /b 1
:kok
exit /b 0

test.sql:
declare @ile int
select @ile= COUNT (*) from [pomiar].[dbo].[POMIAR_MPK]
print @ile
go

nsclient.ini:
; SCRIPT DIRECTORY - Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)
script path = scripts
; BATCH FILE WRAPPING -
bat = scripts\\%SCRIPT% %ARGS%
[/settings/NRPE/server]
allow arguments = 1
allow nasty_meta chars = 1
use ssl = 1
; A list of aliases available. An alias is an internal command that has been "wrapped" (to add arguments). Be careful so you don't create loops (ie check_loop=check_a, check_a=check_loop)
[/settings/external scripts/alias]
x=scripts\check_select.bat

when i run command:
./check_nrpe -H x.x.x.x -p 5666
I (0,4,1,101 2013-05-18) seem to be doing fine...

but when run
./check_nrpe -H x.x.x.x -p 5666 -c x
i have error
No handler for command: scripts\check_select.bat

Re: nrpe and bat file

Posted: Tue Sep 22, 2015 10:00 am
by hsmith
Did you restart the NSClient service after changing the ini?

Re: nrpe and bat file

Posted: Tue Sep 22, 2015 10:12 am
by tuumk
yes

Re: nrpe and bat file

Posted: Tue Sep 22, 2015 10:28 am
by hsmith
Did you add/change this in the NSClient ini?

Code: Select all

[/modules]
; ...
CheckExternalScripts=enabled
Source: http://docs.nsclient.org/howto/external_scripts.html

Re: nrpe and bat file

Posted: Tue Sep 22, 2015 11:01 am
by tuumk
; Check External Scripts - A simple wrapper to run external scripts and batch files.
CheckExternalScripts = 1

Re: nrpe and bat file

Posted: Tue Sep 22, 2015 11:41 am
by hsmith
Hi tuumk,

After messing around with it a bit on my end, I am wonder how well the script path works. I was easily able to do what you're trying to accomplish by erasing the alias entry, and adding the following to the bottom of my .ini.


Code: Select all

[/settings/external scripts/scripts]
x=scripts\<yourfilename>.bat


It may not be ideal, but the script path seems to be not working that well for me.

Re: nrpe and bat file

Posted: Tue Sep 22, 2015 11:43 am
by hsmith