Saturday, May 29, 2010

network monitor

Took me some time to find the right components, finally got it to work and this will help me a lot!

The dependencies are:
1. The mail program, best one (or only one) I found is HERE (more info and alternate download), get the one with STARTTLS (if using gmail), I saved it under %systemroot%\system32 and renamed to mail.exe for ease of use but you can leave the name (change in script) and place in same folder as script if there are security concerns.

2. Sleep command found HERE.

checkServer.bat
============================================
@echo off

SET ip=192.168.1.100
SET wait=300

echo Checking if server (%IP%) online...
ping %IP%

if not errorlevel 1 goto :eof

echo.

echo Attempting to start VMware...
start vmware -x "D:\vmware\server\server.vmx"

echo Retry in %wait% seconds
sleep %wait%
ping %IP%

if not errorlevel 1 goto :eof

mail -f my@gmail.com -d gmail.com -smtp smtp.gmail.com -port 587 -t my@gmail.com -sub "SERVER DOWN!" -from my@gmail.com -cc techsupport@gmail.com +bcc -v -starttls -auth -user USERNAME -pass PASSWORD -M "Please check server (%IP%) now!"

pause
=============================================

substitute the IP, emails, NAME and PASS to your gmail username and password.
Also which actions you want to do, if vmware check your location... etc.

Test it, and now all that's left is to schedule the script... those and more coming up in next posts.

Let me know how it goes!

No comments: