Updated string formating, json.loads exception & white spaces changes

This commit is contained in:
kuldeep.k@cisinlabs.com 2021-10-01 15:39:02 +05:30
parent 1dbdb0cd10
commit 066626a1ec
No known key found for this signature in database
GPG Key ID: AF4FB299BF7C7C2A

View File

@ -30,18 +30,21 @@ 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://{}:{}@{}:{}/".format(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 (json.decoder.JSONDecodeError, TypeError()): except (ValueError, TypeError):
collectd.info("Exception loading or parsing JSON")
return
except: # noqa:E722
collectd.info("Exception loading or parsing JSON") collectd.info("Exception loading or parsing JSON")
return return
for i in ["networkConnections", "numberOfPubkeysProcessed", for i in ["networkConnections", "numberOfPubkeysProcessed",
"numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]: "numberOfMessagesProcessed", "numberOfBroadcastsProcessed"]:
metric = collectd.Values() metric = collectd.Values()
metric.plugin = "pybitmessagestatus" metric.plugin = "pybitmessagestatus"
@ -52,7 +55,7 @@ def read_callback():
metric.type_instance = i.lower() metric.type_instance = i.lower()
try: try:
metric.values = [clientStatus[i]] metric.values = [clientStatus[i]]
except (NameError, KeyError): except (TypeError, KeyError):
collectd.info("Value for %s missing" % (i)) collectd.info("Value for %s missing" % (i))
metric.dispatch() metric.dispatch()