forums.meulie.net

check_nrpe with args in command

Hi. I am trying to define a command for notifications that uses an insert in a database. I have done this via a script that does a osql command to the db, and this works when I run the script via nrpe from the commandline.

[email protected]:~$ sudo -u nagios /usr/lib/nagios/plugins/check_nrpe -H 192.168.0.53 -c dbinsert -a 98123 \""dbins test from cli"\" (1 row affected)
But when I get a notification from nagios (triggered, in nagios log), nothing happens and I can’t see it in NSC.log. I tried another command that calls alias_disk and that ran ok.
I suppose I haven’t correctly defined the command but I have tried many variations and am starting to wonder what it should look like…

NSC.ini[code];# NSCLIENT++ MODULES

[modules]
NRPEListener.dll

[Settings]
use_file=1
allowed_hosts=192.168.0.63
password=pw

[NRPE]
;# COMMAND ALLOW NASTY META CHARS
allow_nasty_meta_chars=1

[External Script]
;# COMMAND ALLOW NASTY META CHARS
allow_nasty_meta_chars=1

[Script Wrappings]
bat=scripts%SCRIPT% %ARGS%

[External Scripts]
dbinsert=scripts\dbinsert.bat $ARG1$ $ARG2$
[/code]
the script, defined in “external scripts”

[code]
set textFromNagios=%1
set secFromNagios=%2

for /f “tokens=*” %%a in (
‘cscript //NoLogo “C:\Program Files\NSClient++\scripts\uuid.vbs”"’
) do (
set UUID=%%a
)

set target=“ia_submit_v001(id, text, sec)“
set values=”(’%UUID%’, ‘%textFromNagios%’, ‘secFromNagios’)”

rem remove quotation marks
set target=%target:"=%
set values=%values:"=%

set SQLcmd="INSERT INTO %target% VALUES %values%“
set SQLcmd=%SQLcmd:”=%

osql -U sa -P pw-d dbins -D nagios_to_db_ins -Q “%SQLcmd%”[/code]
My notify command, with the earlier tries and notes[code]# ‘notify-X-by-db_ins’ command definition

uses a bat file at server2: %PROGRAMFILES%\NSClient++\scripts\dbinsert.bat, via nrpe External Scripts

server2 has a 32-bit (64 bit not visible to NSClient++) ODBC defined that is used by the bat when calling dbins via osql

the bat-file needs to recieve the text string as one argument, so it is needed to escape extra quotation marks (also for check_nrpe?)

(uses bat file since dirct use of sqsh here from linux didn’t work, as user nagios does not have a shell)

define command{
command_name notify-service-by-db_ins

command_line check_nrpe -H 192.168.0.53 -c dbinsert -a txt1 ““Icinga $NOTIFICATIONTYPE$ etc.””

command_line $USER1$/check_nrpe!dbinsert!txt1!“Icinga $NOTIFICATIONTYPE$ etc.”"

command_line check_nrpe!dbinsert!txt1!"“Icinga $NOTIFICATIONTYPE$ etc.”"

    command_line    $USER1$/check_nrpe -H 192.168.0.53 -p 5666 -c dbinsert -a txt1 \""Icinga $NOTIFICATIONTYPE$; etc."\"

command_line /usr/lib/nagios/plugins/check_nrpe -H 192.168.0.53 -c dbinsert -a txt1 ““Icinga $NOTIFICATIONTYPE$; etc.””

command_line sqsh -S dev2db2 -D dbins -U sa -P pw -C txt1 ""Icinga\nNot. Type: $NOTIFICATIONTYPE$ etc. “”

    }[/code]

I suppose it should work, it does when run from cli, as I noted. I need to get the command_line right. Any ideas?

Just to close the thread, I got this to work a while back by writing the script locally on the linux machine… I guess I had gotten on the wrong track by trying to run it from a command directly and then going the nrpe route. This is of course much better as it doesn’t rely on an external server. [SOLVED, sort of]