[ previous ] [ next ] [ threads ]
 
 From:  "Norman H. Azadian" <norman at azadian dot ch>
 To:  =?ISO-8859-1?Q?Mathias_Bur=E9n?= <mathias dot buren at gmail dot com>
 Cc:  andy dash choi at uiowa dot edu, m0n0wall at lists dot m0n0 dot ch
 Subject:  Re: [m0n0wall] Feature Request
 Date:  Thu, 24 Mar 2005 12:13:42 +0100
Here's a script which I'm running on my server to do just that, if 
anybody's interested.  If I ever have problems with my ISP, I'll have a 
complete log to prove exactly how much service I lost.  Only problem is 
that there's no way to distinguish between the times the ISP is at fault, 
and the times I'm messing about with my network.  As my network stabilizes, 
that's less of a problem.

NHA
---
Norman H. Azadian    Taegerishalde 13    CH-3110 Muensingen    Switzerland
norman at azadian dot ch      tel: +41 31 721 7855      fax: +41 31 55 898 55



> Haha, great idea! Like, pinging some host once every hour or so perhaps.
> 
> 
> On Thu, 24 Mar 2005 02:02:47 -0600, Andy Choi <andyiowalist at mchsi dot com> wrote:
> 
>>So why not include some sort of uptime percentage with m0n0wall? I'd
>>love to see how unreliable my cable modem provider truly is!
>>--
>>Andy Choi
>>Management Information Systems (MIS)
>>Lead Web Developer - Delta Sigma Pi
>>Henry B. Tippie College of Business
>>University of Iowa
>>andy dash choi at uiowa dot edu
>>(319) 530-9966
>>
>>NOTICE:  This e-mail and any attachments hereto, is intended only
>>for use by the addressee(s) named herein and may contain legally
>>privileged and/or confidential information.  If you are not  the
>>intended recipient of this e-mail, you are hereby warned that
>>dissemination, distribution or copying of this e-mail, or any
>>attachments hereto, is strictly prohibited.  If you have received
>>this e-mail or any attachment in error, please notify the sender
>>by replying to this message, and permanently delete the original,
>>and copy or printout hereof immediately.
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: m0n0wall dash unsubscribe at lists dot m0n0 dot ch
>>For additional commands, e-mail: m0n0wall dash help at lists dot m0n0 dot ch
>>
>>
> 
> 
> 
#!/bin/sh
# /usr/local/sbin/internet	20030524	NHA
# Run this in the background to monitor the state of our internet connection.
# It automatically re-schedules itself periodically, even
# across system restarts.   Invoked with option -1, there is no re-scheduling.
# We assume that the link is up initially.
# Records internet downtime to $LOGFILE and to syslog.
# $TMPFILE always has the most recent interesting info, and $TMPFILE.bak
# has a record of the latest downtime info.
# NOTE that it would be possible to use "mtr --report --report-cycles 2" instead
# of ping.  This works with most every host.  The output can be discarded
# because the exit status says it all.
# NOTE that netstream.ch can also be pinged, but we don't use that because
# it doesn't really prove that we can reach the outside world.
# NOTE to check that this is properly scheduled, use the 'atq' command.
# NOTE polling interval can now be dynamic, based on the number of sites reached

typeset -r UP_INTERVAL=5	#how often to poll, in minutes, when link is up
typeset -r DOWN_INTERVAL=10	#how often to poll, in seconds, when link down
typeset -r NOT_ENOUGH_SITES=3	#complain unless more than this many sites rspnd
typeset -r LOGFILE=/var/log/internet.log
typeset -r TMPFILE=/var/tmp/internet.tmp
typeset -r SITES="netstream.ch www.bzonline.ch www.ldlc.com mauto.com serverbeach.com www.debian.org
zoneedit.com ns1.granitecanyon.com"
typeset -i OKcount



test 1 -le ${DEBUG:=0}  &&  logger -p user.info -t internet "$0 starting with debug level $DEBUG"
test 1 -le $DEBUG  &&  echo $(date '+%Y%m%d %H%M%S') " $0 starting with debug level $DEBUG" | tee -a
$LOGFILE
missing=''
OKcount=0
date >$TMPFILE
for site in $SITES ;do
    test 3 -le $DEBUG  &&  echo "internet: Pinging $site (OKcount = $OKcount)"
    if ping -c2 $site >>$TMPFILE 2>&1  &&  ((OKcount += 1)) ;then
	test 4 -le $DEBUG  &&  echo internet: OK response from $site
    else
	test 1 -le $DEBUG  &&  echo internet: No response from $site
	#logger -p user.notice -t internet " No response from $site"
	if expr $site :  '.*\..*\..*' >/dev/null ;then
	    site=${site#*.}
	fi
	missing="$missing ${site%.*}"
    fi
    # stop polling as soon as more than $NOT_ENOUGH_SITES sites are reached
    # note that has an influence on polling interval under dynamic polling
    if test $NOT_ENOUGH_SITES -lt $OKcount ;then
	break
    fi
done
date >>$TMPFILE
test 2 -le $DEBUG  &&  echo internet: final OKcount = $OKcount


if test 0 -eq $OKcount ;then
    logger -p user.err -t internet " internet connection down since $(head -1 $TMPFILE)"
    echo $(date '+%Y%m%d %H%M%S') " internet connection down since $(head -1 $TMPFILE)" >>$LOGFILE
    ##Note that this next line will disappear
    ##when we are connect to the internet over ethernet instead of over wireless
    #/sbin/iwpriv eth1 card_reset		#maybe the wireless is hosed
    while sleep $DOWN_INTERVAL ;do
	date >>$TMPFILE
	for site in $SITES ;do
	    test 3 -le $DEBUG  &&  echo internet: Pinging $site
	    ping -c2 $site >>$TMPFILE 2>&1  &&  ((OKcount += 1))
	done
	if test 0 -ne $OKcount ;then
	    mmss="$(expr $SECONDS / 60):$(expr $SECONDS % 60)"
	    logger -p user.err -t internet " internet connection up after $mmss"
	    echo $(date '+%Y%m%d %H%M%S') " internet connection up after $mmss" >>$LOGFILE
	    mv $TMPFILE $TMPFILE.bak		#a record of the last downtime
	    break
	fi
    done

elif test $OKcount -le $NOT_ENOUGH_SITES ;then

    #echo $(date '+%Y%m%d %H%M%S') " only $OKcount sites responded" >>$LOGFILE
    logger -p user.warning -t internet " only $OKcount sites responded"

else
    if test 2 -le $DEBUG ;then
	echo $(date '+%Y%m%d %H%M%S') " $OKcount sites responded" >>$LOGFILE
    fi
    if test -n "$missing" ;then
	logger -p user.notice -t internet "No response from $missing"
    fi
fi


if test '-1' != "$1" ;then			#option -1 inhibits re-schedule
    # schedule next invocation
    #NOTE that $0 will normally be sh, not the name of the shell script to run
    at -f /usr/local/sbin/internet now + $UP_INTERVAL minutes 2>/dev/null
    ##make the polling interval dynamic
    #at -f /usr/local/sbin/internet now + $OKcount minutes 2>/dev/null
fi