Page 1 of 2
Nagios Adding Backslashes To My Plugin (Windows Batch File)
Posted: Tue Jun 15, 2021 10:53 am
by vornado
Good morning, all.
Linux 3.10.0-1160.31.1.el7.x86_64
Nagios XI 5.8.4
Host with NCPA plugin: Windows 10 Enterprise 20H2
I deleted my post regarding a somewhat related topic. It turns out Nagios doubles up on backslashes whether they are included in the .bat file (NCPA "plugin") or, as suggested in the previous post, in an argument for a plugin.
Here is the batch file, which works as expected at the Windows command line:
Code: Select all
:: Check for new .zip files
@ECHO OFF
DIR "\\C210EIBSWEBDEV1\e$\##VNO_Web_PDs\*.ZIP" > NUL 2> NUL
if "%ERRORLEVEL%" == "0" (
ECHO NOTIFICATION - NEW ZIP FILES IN \\C210EIBSWEBDEV1\e$\##VNO_Web_PDs & EXIT /B 1
) ELSE (
ECHO OK - NO NEW ZIP FILES IN \\C210EIBSWEBDEV1\e$\##VNO_Web_PDs & ECHO \\C210EIBSWEBDEV1\e$\##VNO_Web_PDs & EXIT /B 0
)
In Nagios, the backslashes are being doubled (escaped?), resulting in an incorrect status (there *is* a file in the specified directory):
2021-06-15_11-30-26.png
Note that the backslashes are NOT doubled in the status line but after that, they ARE.
Any assistance would be appreciated.
Steve
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Tue Jun 15, 2021 4:58 pm
by gsmith
Hi,
I see what you are seeing, but the script is functioning correctly. Once I have a zip file in the directory
and the check runs it works. I altered your bat file to use IP and not hostname, is your Windows10 machine
able to resolve that hostname (C210EIBSWEBDEV1) ?
Image3.jpg
Image4.jpg
Image5.jpg
Image6.jpg
Image7.jpg
Let me know what you think
Thanks!
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 9:50 am
by vornado
Good morning, G, and thanks for your reply.
I wasn't having any luck with the IP address until I noticed yours was checking for files on your local C drive. I tried it with my C drive and it works, even with the host name. The problem is that developers are uploading their work to a network drive. Any ideas? If a permissions issue, how can it be resolved? Obviously, Nagios XI is able to run all the commands in the batch file. It only seems to be having a problem with the backslashes. Is there a log file I can check to see what's going on?
Thanks.
Steve
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 10:39 am
by gsmith
Hi,
I am a little bit confused
The machine with the bat file isn't C210EIBSWEBDEV1 correct?
Can you run
Code: Select all
DIR "\\C210EIBSWEBDEV1\e$\##VNO_Web_PDs\*.ZIP"
on the machine with the bat
file and show me the output please?
Thanks
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 10:58 am
by vornado
The machine with the .bat file is my PC which is running the NCPA agent. It is looking for .zip files uploaded to a network server by our developers.
Code: Select all
C:\Program Files (x86)\Nagios\NCPA\plugins>DIR "\\C210EIBSWEBDEV1\e$\##VNO_Web_PDs\*.ZIP"
Volume in drive \\C210EIBSWEBDEV1\e$ is DATA
Volume Serial Number is 86C5-5CC2
Directory of \\C210EIBSWEBDEV1\e$\##VNO_Web_PDs
01/07/2020 02:55 PM 30,674 19.01.00_154_Update_3_glmod_fix_sorting_Tsk21261.zip
1 File(s) 30,674 bytes
0 Dir(s) 452,400,271,360 bytes free
I added the /B switch to get less output but it still doesn't work in Nagios.
Code: Select all
C:\Program Files (x86)\Nagios\NCPA\plugins>DIR /B "\\C210EIBSWEBDEV1\e$\##VNO_Web_PDs\*.ZIP"
19.01.00_154_Update_3_glmod_fix_sorting_Tsk21261.zip
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 12:00 pm
by gsmith
So now, from the plugins directory that is on your machine, could you run the bat file and let me see
the output please? Preferably for both cases, when there is a zip file and when there isn't.
Thanks
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 12:34 pm
by vornado
Code: Select all
WITH .ZIP FILES
C:\Program Files (x86)\Nagios\NCPA\plugins>VNO_PDS.BAT
NOTIFICATION - NEW ZIP FILES IN \\10.0.11.8\e$\##VNO_Web_PDs\
WITHOUT .ZIP FILES
C:\Program Files (x86)\Nagios\NCPA\plugins>VNO_PDS.BAT
OK - NO NEW ZIP FILES IN \\10.0.11.8\e$\##VNO_Web_PDs\
Updated .bat file (works as above only at command line):
Code: Select all
@ECHO OFF
SET ZIPDIR=\\10.0.11.8\e$\##VNO_Web_PDs\
DIR /B %ZIPDIR%*.ZIP > NUL 2> NUL
if "%ERRORLEVEL%" == "0" (
ECHO NOTIFICATION - NEW ZIP FILES IN %ZIPDIR% & EXIT /B 1
) ELSE (
ECHO OK - NO NEW ZIP FILES IN %ZIPDIR% & EXIT /B 0
)
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 1:45 pm
by gsmith
OK, cool.
I need to create another windows box for the network share location. And then I can
reproduce your environment and test. Will let you know what I find.
Thx
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 16, 2021 2:17 pm
by vornado
OK, thanks.
I even tried checking a directory on the C drive of my laptop and that didn't work, so it's like it only works locally.
Let me know what you learn.
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Thu Jun 17, 2021 11:24 am
by gsmith
Yeah I had the same result.
First though I enhanced the script a little:
Code: Select all
@ECHO OFF
DIR "\\192.168.23.87\e$\temp\" > NUL 2> NUL
if ERRORLEVEL 1 (ECHO DRIVE NOT FOUND & EXIT /B 1)
DIR "\\192.168.23.87\e$\temp\*.zip" > NUL 2> NUL
rem echo %errorlevel%
IF ERRORLEVEL 1 (ECHO NOTIFICATION - NO NEW ZIP FILES IN \\192.168.23.87\e$\temp & EXIT /B 1
) ELSE (ECHO NOTIFICATION - NEW ZIP FILES IN \\192.168.23.87\e$\temp & EXIT /B 1)
I added the first bit so if the directory isn't there I would get an error.
So to deal with the local drive issue you could mount the drive with reconnect at logon on your machine,
or incorporate mounting it in the script:
Code: Select all
@ECHO OFF
DIR "Z:\" > NUL 2> NUL
if ERRORLEVEL 1 (ECHO DRIVE NOT FOUND, ATTEMPTING TO MOUNT IT )
net use z: \\C210EIBSWEBDEV1\e$\##VNO_Web_PDs user:mydomain\joe mypassword
if ERRORLEVEL 1 (ECHO CAN"T MOUNT SHARED DRIVE & EXIT /B 1)
DIR "z:\*.zip" > NUL 2> NUL
IF ERRORLEVEL 1 (ECHO NOTIFICATION - NO NEW ZIP FILES IN \\192.168.23.87\e$\temp & EXIT /B 1
) ELSE (ECHO NOTIFICATION - NEW ZIP FILES IN \\192.168.23.87\e$\temp & EXIT /B 1)
Thanks