Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

How to detect when a server stops being pinged by another device?

My workplace has a Windows network with about 60 PCs running Windows 7.  I'm in the process of configuring a Linux-based monitoring server that will be running Nagios and Cacti.  I also have access to a cloud-based VPS running Ubuntu.

I'd like to use the VPS to monitor the monitoring server and issue an alert if the monitoring server goes down.  As it stands now, the monitoring server will not be visible outside the LAN, and I don't want to make any changes to the firewall.  My thought is to have the monitoring server continuously ping the VPS.  If the pinging stops, the VPS will send me an alert via email.

I've done some Googling, but I can't find any information about a way to issue an alert when a server stops receiving pings from another machine.

I'm a Linux newbie, and any help would be appreciated.  Thanks!
0
chernavsky
Asked:
chernavsky
  • 2
  • 2
3 Solutions
 
xtermCommented:
On the VPS just run:

tcpdump -w myfile.output icmp and host <ip address of monitoring server>

Then you can just script something else to watch myfile.output and tell you if it stops growing.
0
 
giltjrCommented:
You will want to make sure you stop the process and delete myfile.output every now and then or it will continue to grow forever.
0
 
chernavskyAuthor Commented:
xterm, I installed tcpdump, and it's detecting the pings.  Thanks for that.  What do you suggest for a script?  Something in BASH that checks the size of the myfile.output file once per minute, and then sends an email alert if the size didn't change from the previous cycle?  Or is there a simpler way?  Thanks again.
0
 
xtermCommented:
Here's a little shell script that will do what you need:

#!/bin/sh

FILE_TO_WATCH="myfile.output"
if [ ! -f $FILE_TO_WATCH ]; then
        echo "Capture file not found, please edit value FILE_TO_WATCH in this script"
        exit 1
fi

EMAILRCPT="you@youraddress.com"
OLDSIZE=0

while :;
do
        MYFILESIZE=`du -b $FILE_TO_WATCH | awk '{print $1}'`
        if [ $OLDSIZE -eq $MYFILESIZE ]; then
                mail -s "Ping capture file did not grow" $EMAILRCPT < /dev/null 
        else
                OLDSIZE=$MYFILESIZE
        fi
        sleep 30
done

Open in new window


Keep in mind though, you might want to have it exit after it mails you (add a line with "exit 0" below that line) otherwise you will get an email every 30 seconds until the pings resume again.

And of course, every once in a while you probably want to remove the output file and re-run the script because it will keep growing over time.
0
 
chernavskyAuthor Commented:
Excellent!  Works like a charm.  Thank you so much.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now