From 1dbdb0cd1009306fcb9d8fd3a5299b84387f0e7f Mon Sep 17 00:00:00 2001
From: "kuldeep.k@cisinlabs.com" <kuldeep.k@cisinlabs.com>
Date: Wed, 29 Sep 2021 17:27:46 +0530
Subject: [PATCH] Update code quality function spacing, bare except & long line
 changes

---
 packages/collectd/pybitmessagestatus.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/packages/collectd/pybitmessagestatus.py b/packages/collectd/pybitmessagestatus.py
index 1db9f5b1..8e24998a 100644
--- a/packages/collectd/pybitmessagestatus.py
+++ b/packages/collectd/pybitmessagestatus.py
@@ -7,11 +7,13 @@ import xmlrpclib
 pybmurl = ""
 api = ""
 
+
 def init_callback():
     global api
     api = xmlrpclib.ServerProxy(pybmurl)
     collectd.info('pybitmessagestatus.py init done')
 
+
 def config_callback(ObjConfiguration):
     global pybmurl
     apiUsername = ""
@@ -28,17 +30,19 @@ def config_callback(ObjConfiguration):
             apiInterface = node.values[0]
         elif key.lower() == "apiport" and node.values:
             apiPort = node.values[0]
-    pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface+ ":" + str(int(apiPort)) + "/"
+    pybmurl = "http://" + apiUsername + ":" + apiPassword + "@" + apiInterface + ":" + str(int(apiPort)) + "/"
     collectd.info('pybitmessagestatus.py config done')
 
+
 def read_callback():
     try:
         clientStatus = json.loads(api.clientStatus())
-    except:
+    except (json.decoder.JSONDecodeError, TypeError()):
         collectd.info("Exception loading or parsing JSON")
         return
 
-    for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
+    for i in ["networkConnections", "numberOfPubkeysProcessed", 
+              "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
         metric = collectd.Values()
         metric.plugin = "pybitmessagestatus"
         if i[0:6] == "number":
@@ -48,10 +52,11 @@ def read_callback():
         metric.type_instance = i.lower()
         try:
             metric.values = [clientStatus[i]]
-        except:
+        except (NameError, KeyError):
             collectd.info("Value for %s missing" % (i))
         metric.dispatch()
 
+
 if __name__ == "__main__":
     main()
 else: