Update code quality function spacing, bare except & long line changes

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-09-29 17:27:46 +05:30
parent 579a3d2143
commit 1dbdb0cd10
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A

View File

@ -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 = ""
@ -31,14 +33,16 @@ def config_callback(ObjConfiguration):
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: