Wednesday, March 7, 2018

windows - Are there any open-source simple network monitoring applications?





I am debugging a problem with one of our systems. Every Sunday, it stops communicating with another server. If we reboot both servers, communication works again.



I was wondering if there are any small footprint apps that monitor TCP port availability and network connectivity, possibly logging any downtime. I'd also like it to be open source if possible, but if there is another solution that is proprietary, I'd like to hear about it also.


Answer




I'll buck the trend and give you a scripted solution.



Grab a copy of netcat for Windows and modify the script with the path of netcat (or just dump nc.exe in the %SystemRoot%\system32 directory and change that line to just nc.exe). Also, modify the script to store its log file wherever you want.



@echo off

SET NETCAT=c:\path-to-netcat\nc.exe
SET MONITOR_HOST=server-to-monitor
SET MONITOR_PORT=port-number-to-monitor
SET LOGFILE=C:\whatever.log


rem Use netcat to check for host answering on TCP port xxx
%NETCAT% -z %MONITOR_HOST% %MONITOR_PORT%
if errorlevel 1 goto _host_down

echo %DATE% %TIME% %MONITOR_HOST% answered on TCP port %MONITOR_PORT%>>%LOGFILE%
goto end

:_host_down
echo %DATE% %TIME% %MONITOR_HOST% did not answer on TCP port %MONITOR_PORT%>>%LOGFILE%


rem Do something to remote host here...
rem shutdown -r -t 1 -f -m %MONTIOR_HOST%

:end


There ya' go. You could run that as a "scheduled task".



This isn't fancy at all, but it would work. If you wanted to make it fancier, you could use the date or time to change the log file name such that you get a new log every day, week, etc. You could delete old logs, etc. There's a lot you could do with a simple script like this... heh heh...




Addendum:



Here's the fancier "command line arguments" version. It logs into whatever directory you specify, in the filename "MONTIOR_HOST_YYYY-MM-DD.log". Call with the syntax:



(filename) monitor_host monitor_port log-file-path
monitor.cmd test-srv01 80 "c:\monitor_logs\long filenames do work here\"


This would be suitable for calling from multiple scheduled tasks, scripts, etc, to monitor multiple servers or multiple ports.




@echo off
SET NETCAT=c:\path-to-netcat\nc.exe
SET MONITOR_HOST=%1
SET MONITOR_PORT=%2
SET LOGFILE="%~f3\%1_%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2%.LOG"

if "%1"=="" goto _syntax
if "%2"=="" goto _syntax
if "%3"=="" goto _syntax


rem Use netcat to check for host answering on TCP port xxx
%NETCAT% -z %MONITOR_HOST% %MONITOR_PORT%
if errorlevel 1 goto _host_down

echo %DATE% %TIME% %MONITOR_HOST% answered on TCP port %MONITOR_PORT%>>%LOGFILE%
goto end

:_host_down
echo %DATE% %TIME% %MONITOR_HOST% did not answer on TCP port %MONITOR_PORT%>>%LOGFILE%


rem Do something to remote host here...
rem shutdown -r -t 1 -f -m %MONTIOR_HOST%
goto end

:_syntax
echo Syntax:
echo.
echo %0 monitor_host monitor_port log-file-path


:end


I have too much fun writing scripts...


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...