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 = "" pybmurl = ""
api = "" api = ""
def init_callback(): def init_callback():
global api global api
api = xmlrpclib.ServerProxy(pybmurl) api = xmlrpclib.ServerProxy(pybmurl)
collectd.info('pybitmessagestatus.py init done') collectd.info('pybitmessagestatus.py init done')
def config_callback(ObjConfiguration): def config_callback(ObjConfiguration):
global pybmurl global pybmurl
apiUsername = "" apiUsername = ""
@ -28,17 +30,19 @@ def config_callback(ObjConfiguration):
apiInterface = node.values[0] apiInterface = node.values[0]
elif key.lower() == "apiport" and node.values: elif key.lower() == "apiport" and node.values:
apiPort = node.values[0] 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') collectd.info('pybitmessagestatus.py config done')
def read_callback(): def read_callback():
try: try:
clientStatus = json.loads(api.clientStatus()) clientStatus = json.loads(api.clientStatus())
except: except (json.decoder.JSONDecodeError, TypeError()):
collectd.info("Exception loading or parsing JSON") collectd.info("Exception loading or parsing JSON")
return return
for i in ["networkConnections", "numberOfPubkeysProcessed", "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]: for i in ["networkConnections", "numberOfPubkeysProcessed",
"numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
metric = collectd.Values() metric = collectd.Values()
metric.plugin = "pybitmessagestatus" metric.plugin = "pybitmessagestatus"
if i[0:6] == "number": if i[0:6] == "number":
@ -48,10 +52,11 @@ def read_callback():
metric.type_instance = i.lower() metric.type_instance = i.lower()
try: try:
metric.values = [clientStatus[i]] metric.values = [clientStatus[i]]
except: except (NameError, KeyError):
collectd.info("Value for %s missing" % (i)) collectd.info("Value for %s missing" % (i))
metric.dispatch() metric.dispatch()
if __name__ == "__main__": if __name__ == "__main__":
main() main()
else: else: