Hey folks,
I'm wanting to do some general query work on a custom application.
I've created a batch file that runs a custom query and parses the results back as a decimal number. (the query is a select count(*) )
The strange thing is... if I kick off the batch file script from the commandline, I get as output what I expect... the decimal value.
If I use zabbix_get function from the zabbix server terminal window I get ZBX_NotSupported.
I put in a Pause in my script and then instead of getting back:
19Press any key to continue
I get back
Press any key to continue
In other words. If Zabbix Agent service fires the item it won't give back the value I get if I run it manually from the command prompt.
The zabbix agent service runs as a local system service.
Here are the scripts provided.
aw_trans.cmd (Awaiting Transcription status query)
ZABBOSQL.CMD (general script running SQLCMD for commandline query)
Chomp.cmd (basic echo function without linefeed at the end like echo does, uses Kix32)
and finally... the SQL query being executed.
Aw_trans.sql (SQL query being called in zabbosql.cmd)
;
So basically... summing up... the scripts run the aw_trans.sql and strip the output down to just the decimal value (in this case... 19)
19 gets parsed through chomp and outputted to the screen and to the .txt file... which then gets typed back to the terminal output.
Ambitious... dunno... maybe I'm doing things inefficiently?
Basically what I want to do is run a sql query, get -just- the relevant output and parse that back to Zabbix where I can set a trigger on it.
The silly thing is, is the above thing works from the command line input on the zabbix agent windows box, but not when run from zabbix_get.
I could setup a System Task to dump a new .txt file every 5 minutes overwriting the previous one and then let zabbix use type .txt filename to retrieve the new value but that kind of defeats the purpose. I want to run it all from the zabbix server side of things.
Help... anyone?
Greets, Dennis Toepoel.
I'm wanting to do some general query work on a custom application.
I've created a batch file that runs a custom query and parses the results back as a decimal number. (the query is a select count(*) )
The strange thing is... if I kick off the batch file script from the commandline, I get as output what I expect... the decimal value.
If I use zabbix_get function from the zabbix server terminal window I get ZBX_NotSupported.
I put in a Pause in my script and then instead of getting back:
19Press any key to continue
I get back
Press any key to continue
In other words. If Zabbix Agent service fires the item it won't give back the value I get if I run it manually from the command prompt.
The zabbix agent service runs as a local system service.
Here are the scripts provided.
aw_trans.cmd (Awaiting Transcription status query)
Code:
@echo off >c:\zabbix\aw_trans.txt call c:\zabbix\zabbosql.cmd c:\zabbix\aw_trans.sql >>c:\zabbix\aw_trans.txt type c:\zabbix\aw_trans.txt pause --> added for debugging rem del c:\zabbix\aw_trans.txt ; remarked for debugging.
Code:
@echo off
setLocal EnableDelayedExpansion
set OsqlCmd="sqlcmd.exe -UNOTAREALUSER -PNOTAREALPW -SHOSTNAME -dDATABASENAME -i %1"
for /f "tokens=* delims= " %%a in ('%osqlCmd%') do (
set /a N+=1
if !N! neq 1 if !N! neq 2 if !N! neq 4 if !N! neq 5 call c:\zabbix\chomp.cmd %%a
)
Code:
@ECHO OFF
:: Command line check
IF "%1"=="" GOTO Syntax
IF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: Keep variables local
SETLOCAL
:: Strip leading space added by Windows NT 4
SET STRING=%*
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 SET STRING=%STRING:~1%
:: Create temporary Kix script
:: (Kix displays strings without carriage returns by default)
(ECHO $RC=REDIRECTOUTPUT^("%%TEMP%%.\CHOMP.DAT"^)) > %TEMP%.\CHOMP.KIX
(ECHO."%STRING%") >> %TEMP%.\CHOMP.KIX
(ECHO $RC=REDIRECTOUTPUT^(""^)) >> %TEMP%.\CHOMP.KIX
:: Call the temporary Kix script
KIX32 %TEMP%.\CHOMP.KIX
:: Display the temporary file created by the temporary Kix script
TYPE %TEMP%.\CHOMP.DAT
:: Delete the temporary files
DEL %TEMP%.\CHOMP.KIX
DEL %TEMP%.\CHOMP.DAT
:: Done
ENDLOCAL
GOTO:EOF
:Syntax
(ECHO.) 1>&2
(ECHO Chomp.bat, Version 1.01 for Windows NT 4/2000) 1>&2
(ECHO Displays command line parameters on screen) 1>&2
(ECHO ^(on StdOut^) without a carriage return.) 1>&2
(ECHO.) 1>&2
(ECHO Usage: %~n0 ^<string^>) 1>&2
(ECHO.) 1>&2
(ECHO Output: ^<string^> without carriage return on StdOut) 1>&2
(ECHO.) 1>&2
(ECHO Remarks: [1] ^<string^> should NOT contain any double quotes!) 1>&2
(ECHO [2] Windows 2000 will strip leading spaces from ^<string^>) 1>&2
(ECHO [3] This batch file uses Kix, make sure it is installed) 1>&2
(ECHO and that KIX32.EXE can be found in the PATH) 1>&2
(ECHO.) 1>&2
(ECHO Example: ^> SETDATE.BAT ECHO @ECHO OFF) 1>&2
(ECHO ^>^>SETDATE.BAT CALL %~nx0 SET DATE=) 1>&2
(ECHO ^>^>SETDATE.BAT DATE/T) 1>&2
(ECHO CALL SETDATE.BAT) 1>&2
(ECHO SET DATE) 1>&2
(ECHO will display:) 1>&2
FOR /F "tokens=*" %%A IN ('DATE/T') DO (ECHO DATE=%%A) 1>&2
(ECHO.) 1>&2
(ECHO Written by Rob van der Woude) 1>&2
(ECHO http://www.robvanderwoude.com) 1>&2
Aw_trans.sql (SQL query being called in zabbosql.cmd)
Code:
select count(*) from g2document where statusid=6
So basically... summing up... the scripts run the aw_trans.sql and strip the output down to just the decimal value (in this case... 19)
19 gets parsed through chomp and outputted to the screen and to the .txt file... which then gets typed back to the terminal output.
Ambitious... dunno... maybe I'm doing things inefficiently?
Basically what I want to do is run a sql query, get -just- the relevant output and parse that back to Zabbix where I can set a trigger on it.
The silly thing is, is the above thing works from the command line input on the zabbix agent windows box, but not when run from zabbix_get.
I could setup a System Task to dump a new .txt file every 5 minutes overwriting the previous one and then let zabbix use type .txt filename to retrieve the new value but that kind of defeats the purpose. I want to run it all from the zabbix server side of things.
Help... anyone?
Greets, Dennis Toepoel.
Comment