| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # Internet Connection Wrapper From Cron
|
|---|
| 4 | #
|
|---|
| 5 | # a) Disable lvrouted if the internet is down.
|
|---|
| 6 | # b) Re-enable lvrouted if the internet is back up.
|
|---|
| 7 | #
|
|---|
| 8 | # XXX: Do we need build an fail-save for flapping states?
|
|---|
| 9 | # XXX: Do we need to manage state, like DHCP here?
|
|---|
| 10 | # XXX: Check if page output is actually the output expected and not some weird captive portal somewhere.
|
|---|
| 11 | # XXX: For effiently reasons this should be combined with the nagios check_inet check
|
|---|
| 12 | #
|
|---|
| 13 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
|---|
| 14 | #
|
|---|
| 15 |
|
|---|
| 16 | TAG=`basename $0`
|
|---|
| 17 | INET_STATUS=down
|
|---|
| 18 | service lvrouted onestatus > /dev/null && LVROUTED_STATUS="running" || LVROUTED_STATUS="stopped"
|
|---|
| 19 |
|
|---|
| 20 | check_http() {
|
|---|
| 21 | fetch -o /dev/null -q $* 2>/dev/null
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | # Main I-net check
|
|---|
| 25 | check_http http://proxy-test.wirelessleiden.nl && INET_STATUS=up
|
|---|
| 26 |
|
|---|
| 27 | if [ $INET_STATUS = "down" ]; then
|
|---|
| 28 | # Failback internet check
|
|---|
| 29 | check_http http://ams-ix.net && INET_STATUS=up
|
|---|
| 30 | fi
|
|---|
| 31 |
|
|---|
| 32 | if [ $LVROUTED_STATUS = "stopped" ] && [ $INET_STATUS = "up" ]; then
|
|---|
| 33 | service lvrouted start | logger -t "$TAG"
|
|---|
| 34 | elif [ $LVROUTED_STATUS = "running" ] && [ $INET_STATUS = "down" ]; then
|
|---|
| 35 | service lvrouted stop | logger -t "$TAG"
|
|---|
| 36 | fi
|
|---|
| 37 |
|
|---|
| 38 | # Retrieve proxy status
|
|---|
| 39 | export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
|
|---|
| 40 | PROXY_STATUS=down
|
|---|
| 41 | check_http http://proxy-test.wirelessleiden.nl && PROXY_STATUS=down
|
|---|
| 42 |
|
|---|
| 43 | if [ $INET_STATUS = "down" ]; then
|
|---|
| 44 | # Failback internet check
|
|---|
| 45 | check_http http://ams-ix.net && PROXY_STATUS=up
|
|---|
| 46 | fi
|
|---|
| 47 |
|
|---|
| 48 | echo -e "internet=$INET_STATUS\nproxy=$PROXY_STATUS" > /tmp/network.status
|
|---|