[Mpuls-commits] r4770 - in base/trunk: . contrib/apache

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Mar 9 17:21:19 CET 2011


Author: torsten
Date: 2011-03-09 17:21:18 +0100 (Wed, 09 Mar 2011)
New Revision: 4770

Added:
   base/trunk/contrib/apache/check_connection.wsgi
Modified:
   base/trunk/ChangeLog
Log:
Added new WSGI script to check online status of DB


Modified: base/trunk/ChangeLog
===================================================================
--- base/trunk/ChangeLog	2011-03-09 16:00:36 UTC (rev 4769)
+++ base/trunk/ChangeLog	2011-03-09 16:21:18 UTC (rev 4770)
@@ -2,6 +2,8 @@
 
 	* contrib/apache/mpuls.wsgi: Updated wsgi-script
 	* contrib/apache/apache-site-wsgi.conf: Updated apache-config
+	* contrib/apache/check_connection.wsgi: New. WSGI-app to check online
+	status of db. 
 
 2011-03-08  Torsten Irlaender <torsten at intevation.de>
 

Added: base/trunk/contrib/apache/check_connection.wsgi
===================================================================
--- base/trunk/contrib/apache/check_connection.wsgi	2011-03-09 16:00:36 UTC (rev 4769)
+++ base/trunk/contrib/apache/check_connection.wsgi	2011-03-09 16:21:18 UTC (rev 4770)
@@ -0,0 +1,65 @@
+import psycopg2 as dbapi
+
+HOST = "localhost"
+PORT = "5432"
+DB   = "db_monitor"
+USER = "db_monitor"
+PASS = "pass"
+
+def check_1(con):
+    check_ok = True
+    return check_ok
+
+CHECKS = [check_1]
+
+def connect():
+    con = None
+    con = dbapi.connect(
+            database = DB,
+            host     = HOST,
+            port     = PORT,
+            user     = USER,
+            password = PASS)
+    return con
+
+def disconnect(con):
+    con.close()
+
+def application(environ, start_response):
+        status = '200 OK'
+        out = []
+	ok = True
+        try:
+            out.append('Starting Tests...')
+            con = connect()
+            out.append('Connect OK')
+            try:
+                for check in CHECKS:
+                    check(con)
+                    out.append('Check "%s" OK' % check.__name__)
+            except:
+                out.append('Check "%s" FAILED' % check.__name__)
+		ok = False
+            out.append('Finished Tests...')
+            disconnect(con)
+            out.append('Disconnect OK')
+        except:
+            out.append('Connect/Disconnect ERROR')
+	    ok = False
+
+
+        # Final output. Is all ok with the database?
+	if ok:
+            out.append('DATABASE OK')
+	else:
+            out.append('DATABASE ERROR')
+
+        output = '\n'.join(out)
+        response_headers = [
+                ('Content-type', 'text/plain'),
+                ('Content-Length', str(len(output)))]
+        start_response(status, response_headers)
+        return [output]
+
+if __name__ == '__main__':
+        print application(None, None)



More information about the Mpuls-commits mailing list