Updated string formating, json.loads exception & white spaces changes
This commit is contained in:
parent
1dbdb0cd10
commit
066626a1ec
|
@ -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()
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user