Update code quality function spacing, bare except & long line changes
This commit is contained in:
parent
579a3d2143
commit
1dbdb0cd10
|
@ -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 = ""
|
||||||
|
@ -31,14 +33,16 @@ def config_callback(ObjConfiguration):
|
||||||
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:
|
||||||
|
|
Reference in New Issue
Block a user