@echo off

:: Initialize some globals

set LOGFILE=log\nvsendtrap.log
set JOBFOLDER=.\nvatrap
set DONEFOLDER=.\nvatrap\done
set JOBMASK=*.trp

if exist %JOBFOLDER% goto :_main
md %JOBFOLDER%
md %DONEFOLDER%

:_main
for /F "delims=" %%a in ('dir /b %JOBFOLDER%\%JOBMASK% 2^>NUL') do if exist %JOBFOLDER%\%%a call :_job %%a
ping -n 2 127.0.0.1 >NUL
goto :_main

:_job
echo %TIME:~,8%
>>%LOGFILE% echo %DATE% %TIME:~,8% Job %1

set DBENTRY=
set ALARMKEY=
set PHONENUMBER=
set SZENARIO=
set MESSAGE=
set MSG1=
set MSG2=
for /F "tokens=1,2 delims==" %%b in (%JOBFOLDER%\%1) do call :_param %%b "%%c"

if "%PHONENUMBER%" == "" goto :_end
echo sending trap to %PHONENUMBER% ...

snmptrap -v 1 %PHONENUMBER% public ".1.3.6.1.4.1.18118.1.1.0" "" 6 1 "" .1.3.6.1.4.1.18118.1.1.0.0.1 s "Alarm" .1.3.6.1.4.1.18118.1.1.1 s "%ALARMKEY%" .1.3.6.1.4.1.18118.1.1.2 s "%MSG1%" .1.3.6.1.4.1.18118.1.1.3 s "%MSG2%" .1.3.6.1.4.1.18118.1.1.4 s "%MESSAGE%" .1.3.6.1.4.1.18118.1.1.5 s "" 2>NUL

start nve nvawrdb 1 -i18 -i2%DBENTRY% -s2%PHONENUMBER% -s3%SZENARIO% 

move %JOBFOLDER%\%1 %DONEFOLDER%\%1
goto :_end


:_param
if "%1" == "DBEntry" set DBENTRY=%~2
if "%1" == "AlarmKey" set ALARMKEY=%~2
if "%1" == "PhoneNumber" set PHONENUMBER=%~2
if "%1" == "Szenario" set SZENARIO=%~2
if "%1" == "Message" set MESSAGE=%~2
if "%1" == "Msg1" set MSG1=%~2
if "%1" == "Msg2" set MSG2=%~2

goto :_end

:_end
