Checking .BATs exit code with NAGIOS

batchnagiosscriptingwindows-command-prompt

I currently have the following script on a Windows Server:

@echo off
set path=%PATH%;C:\UnxUtils\usr\local\wbin

cd /D Z:\videos

forfiles /M *_1.mkv /D +%date% > C:\mkv.txt >NUL 2>&1
FOR /F "tokens=*" %%B IN ('grep -c _1.mkv c:\mkv.txt') DO SET VIDEOS=%%B

if %VIDEOS% GEQ 1 (
echo "BAD VIDEOS!"
exit /B 0
) else (
echo "Videos OK"
exit /B 1 )

I need Nagios to check if the scripts exit code is 0 or 1 to diplay a critical alert or a ok. Is this possible?

Best Answer

Actually, that's what Nagios does. You need to return the correct return codes, though. You'll probably have to change your script like this:

if %VIDEOS% GEQ 1 (
  echo "BAD VIDEOS!"
  exit /B 2
) else (
  echo "Videos OK"
  exit /B 0
)