[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [monit] Monitor network connection
From: |
KevinF |
Subject: |
Re: [monit] Monitor network connection |
Date: |
Fri, 17 Apr 2009 20:29:19 -0700 (PDT) |
Emil Natan wrote:
>
> On Wed, Mar 11, 2009 at 7:30 AM, Gilad Benjamini
> <address@hidden>wrote:
> Check connectivity to you gateway using ip address, check protocol dns to
> you dns server ...
>
How might you do this if you don't know the gateway ahead of time?
I have a script that I run on a scheduled basis. The idea is that I always
want to use my preferred interface, but when that is not possible, I have a
fall back interface to use. If the preferred is working, I want the
fallback to turn off, if its not working, I want the fallback to come up.
Since I am using monit to monitor the local (same box) DHCP and DNS
(non-authoritative) servers, I would like to somehow get this into monit.
The biggest problem is that this device is portable, and I never know what
network it will get plugged into. The interface is designed to use DHCP
itself, so I will not know ahead of time what the gateway address is. Once
we set this up, and connect our equipment, since there won't always be an IT
Engineer around, I don't want to then have to configure the monitoring... I
want it to "just work".
Here is the script I am using now:
<code>
#!/usr/bin/env bash
PREFINT=eth0
FAILINT=wlan0
GW=$(route -n | awk -v iface=$PREFINT '($4~/G/) && ($8~iface) {print $2}')
PREFADDR=$(ifconfig $PREFINT | awk '/inet addr/ {print $2}' | awk -F':'
'{print $2}')
FAILADDR=$(ifconfig $FAILINT | awk '/inet addr/ {print $2}' | awk -F':'
'{print $2}')
if [ ! -z $GW ];then
ping -c 4 -w 2 -I $PREFINT -i 0.25 $GW > /dev/null
if [ $? == 0 ]; then
if [ ! -z $FAILADDR ];then
ifdown $FAILINT
fi
exit 0
fi
fi
if [ -z $FAILADDR ];then
ifup $FAILINT
ifdown $PREFINT && ifup $PREFINT
fi
</code>
--
View this message in context:
http://www.nabble.com/-monit--Monitor-network-connection-tp22449060p23082112.html
Sent from the monit-general mailing list archive at Nabble.com.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [monit] Monitor network connection,
KevinF <=