Script to make sure CSC looks operational
authorMatthew McPherrin <matthew@mcpherrin.ca>
Mon, 12 Mar 2012 06:43:10 +0000 (02:43 -0400)
committerMatthew McPherrin <matthew@mcpherrin.ca>
Mon, 12 Mar 2012 06:43:10 +0000 (02:43 -0400)
README [new file with mode: 0644]
run [new file with mode: 0755]
tests.d/10_sockets.py [new file with mode: 0755]
tests.d/30_ssl.sh [new file with mode: 0755]
tests.d/50_website.py [new file with mode: 0755]

diff --git a/README b/README
new file mode 100644 (file)
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 (executable)
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 (executable)
index 0000000..44dd67e
--- /dev/null
@@ -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 (executable)
index 0000000..b3ee07a
--- /dev/null
@@ -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 (executable)
index 0000000..8300d81
--- /dev/null
@@ -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)