SIP test script to quickly check all prod servers
authorBill Erickson <berickxx@gmail.com>
Thu, 28 Sep 2017 16:54:50 +0000 (12:54 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Read-only script that makes SIP request to all production SIP servers
plus the production load balancer host.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/test-scripts/sip/sip-prod-check.py [new file with mode: 0755]

diff --git a/KCLS/test-scripts/sip/sip-prod-check.py b/KCLS/test-scripts/sip/sip-prod-check.py
new file mode 100755 (executable)
index 0000000..912c56a
--- /dev/null
@@ -0,0 +1,89 @@
+#!/usr/bin/python3
+# -----------------------------------------------------------------------
+# Copyright (C) 2015 King County Library System
+# Bill Erickson <berickxx@gmail.com>
+# 
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# -----------------------------------------------------------------------
+
+# -----------------------------------------------------------------------
+# Sends a series of read-only requests (item info, patron info, etc.)
+# to the configured SIP server.  It does not send any requests which 
+# modify data on the server (checkouts, etc.)
+# -----------------------------------------------------------------------
+import sys, logging, logging.config, getopt, configparser
+import pysip2.client
+
+logging.config.fileConfig('pysip2-client.ini')
+config = configparser.ConfigParser()
+config.read('pysip2-client.ini')
+logging.getLogger().setLevel('INFO')
+
+server = config['client']['server']
+port = config['client']['port']
+institution = config['client']['institution']
+username = config['client']['username']
+password = config['client']['password']
+location_code = config['client']['location_code']
+
+servers = ['10.1.10.61', '10.1.10.62', '10.1.10.63', 'evgsip2.kcls.org']
+
+for server in servers:
+    logging.info("Connecting to server " + server)
+
+    client = pysip2.client.Client(server, int(port))
+    client.default_institution = institution
+
+    logging.info("connecting to " + server)
+    try:
+        client.connect()
+    except Exception as err:
+        logging.error("Unable to connect to server %s : %s" % (server, str(err)))
+        sys.exit(1)
+
+    logging.info("logging in as " + username)
+    if not client.login(username, password, location_code):
+        logging.error("Login failed for %s @ %s" % (username, server))
+        sys.exit(1)
+
+    stat = client.sc_status()
+    if stat.fixed_fields[0].value == 'Y':
+        logging.info("SIP server is online")
+    else:
+        logging.info("Status message reports SIP server is NOT online")
+
+    # item information requests
+    for barcode in config['test-data']['item_info_barcodes'].split(','):
+        resp = client.item_info_request(barcode)
+        logging.info("item info completed for %s => %s" % (
+            resp.get_field('AB').value,
+            resp.get_field('AJ').value
+        ))
+
+    # patron information requests
+    for barcode in config['test-data']['patron_info_barcodes'].split(','):
+
+        resp = client.patron_info_request(barcode)
+        logging.info("patron info completed for [valid=%s] %s => %s" % (
+            resp.get_field('BL').value,
+            resp.get_field('AA').value,
+            resp.get_field('AE').value,
+        ))
+
+        resp = client.patron_status_request(barcode)
+        logging.info("patron stat completed for [valid=%s] %s => %s" % (
+            resp.get_field('BL').value,
+            resp.get_field('AA').value,
+            resp.get_field('AE').value
+        ))
+
+    client.disconnect()
+    client.log_summary()