Solved

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

Posted on 2013-12-06
5
512 Views
Last Modified: 2013-12-06
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
Comment
Question by:chernavsky
  • 2
  • 2
5 Comments
 
LVL 19

Assisted Solution

by:xterm
xterm earned 325 total points
ID: 39701396
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
 
LVL 57

Assisted Solution

by:giltjr
giltjr earned 25 total points
ID: 39701419
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
 

Author Comment

by:chernavsky
ID: 39701531
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
 
LVL 19

Accepted Solution

by:
xterm earned 325 total points
ID: 39701655
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
 

Author Closing Comment

by:chernavsky
ID: 39702276
Excellent!  Works like a charm.  Thank you so much.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Even if you have implemented a Mobile Device Management solution company wide, it is a good idea to make sure you are taking into account all of the major risks to your electronic protected health information (ePHI).
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now