2009
12.24

Nothing revolutionary here, but this is a super quick and simple way to monitor the availability of your network nodes via ICMP.

Prerequisites:
- Ability to send mail from the server running the script
- ICMP connectivity to each target node
- DNS provider that does NOT rewrite domain errors (NXDOMAIN redirect)

1. Create a file with a list of nodes (I used ‘nodes.list’) and make it relative to your script. Use IP addresses or FQDNs if you always trust DNS….

nodes.list:

monitor02.t3ch.com
monitor03.t3ch.com
10.10.0.72
www.t3ch.com
mail.t3ch.com

2. Create the following BASH script, tweak $SOURCE and $TO.

#!/bin/bash

SOURCE="monitor01.t3ch.com"
SUBJECT="Network Alert: Node unreachable"
TO="youremail@t3ch.com"
MESSAGE="/tmp/network_monitor-message.txt"

for ipaddr in `cat nodes.list`;
    do
        if ! ping -c 1 $ipaddr
            then
                echo "Node: $ipaddr" > $MESSAGE
                echo "When: `date`" >> $MESSAGE
                echo "Source: $SOURCE" >> $MESSAGE
                /usr/bin/mail -s "$SUBJECT" "$TO" < $MESSAGE
                rm $MESSAGE
        fi
done

3. Create a cron job. Here is an example that performs the checks every 5 minutes:

*/5 * * * * /opt/apps/network_monitor/network_monitor.sh >> /dev/null 2>&1

4. Test out the script by adding a few bogus IP addresses to the nodes.list source file. Then remove them.

5. Sit back and relax, then begin troubleshooting when you get your first alert :)

1 comment so far

Add Your Comment
  1. that’s easy, thanks :)