From b8301408c90d9e62259cb04e4ceb4685fca16d5e Mon Sep 17 00:00:00 2001 From: Matthew McPherrin Date: Mon, 12 Mar 2012 02:43:10 -0400 Subject: [PATCH] Script to make sure CSC looks operational --- README | 7 +++++++ run | 9 +++++++++ tests.d/10_sockets.py | 28 ++++++++++++++++++++++++++++ tests.d/30_ssl.sh | 7 +++++++ tests.d/50_website.py | 21 +++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 README create mode 100755 run create mode 100755 tests.d/10_sockets.py create mode 100755 tests.d/30_ssl.sh create mode 100755 tests.d/50_website.py diff --git a/README b/README new file mode 100644 index 0000000..b6b6b51 --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +CSC-Status +------------- + +A simple set of shell scripts to make sure CSC stuff is up. + +./run calls all the shell scripts in tests.d and prints stuff when a failure is +encountered. Best run as a cron job. diff --git a/run b/run new file mode 100755 index 0000000..115d336 --- /dev/null +++ b/run @@ -0,0 +1,9 @@ +#!/bin/bash + +fail=0 + +for i in "`dirname $0`"/tests.d/*; do + $i || fail=1 +done + +[[ $fail -eq 0 ]] || (echo "Failures encountered"; exit 1) diff --git a/tests.d/10_sockets.py b/tests.d/10_sockets.py new file mode 100755 index 0000000..44dd67e --- /dev/null +++ b/tests.d/10_sockets.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import sys, socket + +services = [ + ('caffeine.csclub.uwaterloo.ca', [22, 25, 80, 110, 143, 143, 443, 465, 587, 993, 995]), + ('artificial-flavours.csclub.uwaterloo.ca', [22, 389, 636]), + ('taurine.csclub.uwaterloo.ca', [22]), + ('natural-flavours.csclub.uwaterloo.ca', [22]), + ('mirror.csclub.uwaterloo.ca', [21, 22, 80, 873]), + ('denardo.csclub.uwaterloo.ca', [22]), + ('corn-syrup.csclub.uwaterloo.ca', [22]), + ('ascorbic-acid.csclub.uwaterloo.ca', [21, 22, 53, 80, 81, 443, 8000, 8080]), #all ssh + ('ginseng.csclub.uwaterloo.ca', [22, 111, 389, 464, 636, 749, 888, 2049]), + ('webauth.csclub.uwaterloo.ca', [22, 443]), + ('wiki.csclub.uwaterloo.ca', [80, 443]), +] + +for S in services: + try: + host = socket.gethostbyname(S[0]) + for port in S[1]: + s = socket.socket() + s.connect( (host , port) ) + s.close() + except socket.error, e: + print "FAIL socket connect to ", S, e + sys.exit(1) diff --git a/tests.d/30_ssl.sh b/tests.d/30_ssl.sh new file mode 100755 index 0000000..b3ee07a --- /dev/null +++ b/tests.d/30_ssl.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +curl -s "https://csclub.uwaterloo.ca" > /dev/null || (echo "FAIL on csc" && exit 2) +curl -s "https://webauth.csclub.uwaterloo.ca" > /dev/null || (echo "FAIL on webauth" && exit 3) +curl -s "https://mail.csclub.uwaterloo.ca" > /dev/null || (echo "FAIL on mail" && exit 4) + +exit 0 diff --git a/tests.d/50_website.py b/tests.d/50_website.py new file mode 100755 index 0000000..8300d81 --- /dev/null +++ b/tests.d/50_website.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +import urllib2, sys + +pages=["https://csclub.uwaterloo.ca", "http://mirror.csclub.uwaterloo.ca"] + +for page in pages: + try: + r = urllib2.urlopen(page, timeout=3) + page = r.read() + if not len(page) > 1000: + print "FAIL, didn't have enough data" + sys.exit(2) + if not"Computer Science Club" in page: + print "FAIL, homepage doesn't mention Computer Science Club" + sys.exit(3) + # So read() didn't throw an exception, nor did opening, + # and we have enough data, so likely good. + sys.exit(0) + except urllib2.URLError as e: + print "FAIL, exception ", e + sys.exit(1)