Page 2 of 2
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Fri Jun 18, 2021 9:24 am
by vornado
It looks like you're using the same IP address as before, so that's why it works. During my troubleshooting, I mapped X: to the remote directory and it did not work. I tried again this morning just to make sure.
When I add additional ECHO commands to my batch file, you can see in Nagios that the backslashes have been unnecessarily escaped.
2021-06-18_9-44-26.png
Somewhere along the line backslashes are being doubled. Maybe in check_ncpa.py? Maybe in this code?:
Code: Select all
try:
urlencode = urllib.parse.urlencode
except AttributeError:
urlencode = urllib.urlencode
Just guessing

. I've tried lots of things, nothing's working. Anyway, thanks for trying. If you come up with something where DIR works on a remote machine, please let me know.
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Fri Jun 18, 2021 11:00 am
by gsmith
Hi
OK will dig around some more.
Thanks
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Mon Jun 21, 2021 12:49 pm
by vornado
I figured I'd give porting my .bat plugin to .vbs a shot to see if that would work. It didn't.
I'm pointing to it in Nagios like this:
Code: Select all
check_xi_ncpa!-t 'faKEpaSSwoRD' -P 5693 -M 'plugins/zipdir.vbs'
Again, the backslashes are being doubled (why???) so that the script returns "path not found", although it runs perfectly fine in Windows.
2021-06-21_14-11-06.png
Here is the script. It gets an error at line 4 when it encounters a variable with the specified directory:
Code: Select all
function zipExists()
zipFolder = "\\10.0.11.8\e$\##VNO_Web_PDs\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoFolder = fso.GetFolder(zipFolder)
Set fsoFiles = fsoFolder.Files
zipExists = false
For Each fsoFile in fsoFiles
If instr(UCase(fsoFile.Name),".ZIP") Then
zipExists = true
Exit For
End If
Next
End Function
if zipExists() then
wscript.echo "Zip files exist"
wscript.quit(1)
else
wscript.echo "There are no zip files"
wscript.quit(0)
end if
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Mon Jun 21, 2021 4:47 pm
by gsmith
Hi,
I found a plugin called "check_smb_share" on
https://exchange.nagios.org//
It works from the nagios server, you need to install the samba client. It's pretty basic, it
just looks for a shared directory. There may be another plugin on the Exchange that does
exactly what you want, but I don't have time to look today. Even if there isn't one you could
modify this one to suit your purpose.
Let me know where you are at in the morning and I can help out then.
Thanks
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Tue Jun 22, 2021 7:59 am
by vornado
Ok, I'll take a look at the check_smb_share. I'm kind of hoping to do something in
Windows, though.
I've been looking at other plugins in the
Nagios Exchange. There's one PowerShell script that looks promising but I don't know PowerShell at all and it looks like it has a steep learning curve. Since this script (
check_windows_files.ps1) does way more than I need it to, I could probably just extract the 'checkFileExists' parts and work with that.
With the .bat and .vbs plugins I created, Nagios is able to display the "\\server\directory" fine in the status line, but it doubles the backslashes everywhere else including when it's used with the DIR command (anywhere but the local C drive).
This is clearly a bug that should be addressed. I would think it's very common to include such an address in a plugin. Also, I wonder why the plugin isn't just executed "as is" with Nagios using nothing but the output text and the exit code.
One more thing: the sample NCPA plugins here:
https://support.nagios.com/kb/article/n ... a-722.html
aren't very useful. With these, it's like you have to get the answer first and then give it to the plugin (./check_dummy.sh 2 Something_is_CRITICAL).
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Tue Jun 22, 2021 2:57 pm
by gsmith
Hi
I got it!
zip.jpg
no_zip.jpg
Here's the script I used:
Code: Select all
@ECHO OFF
net use z: /delete > NUL 2> NUL
if ERRORLEVEL 0 (
net use z: "\\DESKTOP-AFV42G4\temp" /user:DESKTOP-AFV42G4\gsmith bn7999hd)
DIR "\\DESKTOP-AFV42G4\temp" > NUL 2> NUL
if ERRORLEVEL 1 (ECHO DRIVE NOT FOUND & EXIT /B 1)
DIR "\\DESKTOP-AFV42G4\temp\*.zip" > NUL 2> NUL
if ERRORLEVEL 1 (ECHO NOTIFICATION - NO NEW ZIP FILES IN \\DESKTOP-AFV42G4\temp & EXIT /B 1
) ELSE (
ECHO NOTIFICATION - NEW ZIP FILES IN \\DESKTOP-AFV42G4\temp & EXIT /B 1)
The share is \\DESKTOP-AFV42G4\temp. gs-win10-23-87 is another Windows10 box with NCPA installed and the above script
in the C:\Program Files (x86)\Nagios\NCPA\plugins directory.
Try it out and let me know please.
Thanks
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 23, 2021 11:44 am
by vornado
Thanks for not giving up -- it works!!!
For whatever reason, mapping a drive with "net use" makes a difference, even if you don't use the drive letter in your command.
My version of the script is optimistic -- it assumes the connection was made. I replaced the status message "The command completed successfully" with the result text followed by a list of the .zip files, if found. Also, my script disconnects the mapping when it's done.
2021-06-23_14-21-09.png
Code: Select all
@ECHO OFF
net use X: /delete > NUL 2> NUL
net use X: "\\10.0.11.8\e$\##VNO_Web_PDs" /user:mydomain\myusername mYp@sSw0rD > NUL 2> NUL
SET ZIPDIR=\\10.0.11.8\e$\##VNO_Web_PDs\
DIR /B "%ZIPDIR%*.ZIP" > %0.LOG 2> %0.ERR
if "%ERRORLEVEL%" == "0" (
ECHO NOTIFICATION - NEW *PD* .ZIP FILES IN \\10.0.11.8\e$\##VNO_Web_PDs\ & net use X: /delete > NUL 2> NUL & TYPE %0.LOG & EXIT /B 1
) ELSE (
ECHO OK - NO NEW ZIP FILES IN \\10.0.11.8\e$\##VNO_Web_PDs\ - %ERRORLEVEL% & net use X: /delete > NUL 2> NUL & EXIT /B 0
)
I tried to omit the password. It seemed to be working at the command prompt and from Nagios...until my account got locked out. We're forced to change our password periodically, so I'll have to remember to update the script.
Thanks again for all your help -- I truly appreciate it.
Steve
Re: Nagios Adding Backslashes To My Plugin (Windows Batch Fi
Posted: Wed Jun 23, 2021 1:40 pm
by gsmith
Hi
Yeah, establishing a connection with "net use: " was the key. We both learned something.
Glad you are up and running.
Have a good one.