1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 14:16:00 +00:00

Plugin bitcoind_: unify error output

This commit is contained in:
Lars Kruse 2019-07-24 13:48:01 +02:00
parent 88e027bebd
commit db7b2f28ab

View file

@ -99,27 +99,28 @@ def main():
bitcoin_options.rpcconnect = bitcoin_options.get('rpcconnect', '127.0.0.1') bitcoin_options.rpcconnect = bitcoin_options.get('rpcconnect', '127.0.0.1')
bitcoin_options.rpcport = bitcoin_options.get('rpcport', '8332') bitcoin_options.rpcport = bitcoin_options.get('rpcport', '8332')
error = None
if bitcoin_options.get('rpcuser') is None: if bitcoin_options.get('rpcuser') is None:
conf_file = os.getenv("bitcoin_configfile") conf_file = os.getenv("bitcoin_configfile")
if not conf_file: if not conf_file:
print("Missing environment settings (rpcuser/rcpassword or bitcoin_configfile)", error = "Missing environment settings: rpcuser/rcpassword or bitcoin_configfile"
file=sys.stderr)
return False
elif not os.path.exists(conf_file): elif not os.path.exists(conf_file):
print("Configuration file does not exist: {}".format(conf_file), file=sys.stderr) error = "Configuration file does not exist: {}".format(conf_file)
return False
else: else:
bitcoin_options = parse_conf(conf_file) bitcoin_options = parse_conf(conf_file)
if not error:
try:
bitcoin_options.require('rpcuser', 'rpcpassword') bitcoin_options.require('rpcuser', 'rpcpassword')
except KeyError as exc:
error = str(exc).strip("'")
if not error:
bitcoin = ServiceProxy('http://%s:%s' % (bitcoin_options.rpcconnect, bitcoin = ServiceProxy('http://%s:%s' % (bitcoin_options.rpcconnect,
bitcoin_options.rpcport), bitcoin_options.rpcport),
username=bitcoin_options.rpcuser, username=bitcoin_options.rpcuser,
password=bitcoin_options.rpcpassword) password=bitcoin_options.rpcpassword)
(info, connect_error) = bitcoin.getinfo() (info, connect_error) = bitcoin.getinfo()
if connect_error:
error = "Could not connect to Bitcoin server: {}".format(connect_error) error = "Could not connect to Bitcoin server: {}".format(connect_error)
if command == 'autoconf': if command == 'autoconf':
@ -194,10 +195,8 @@ class Options(dict):
if self.get(name) is None: if self.get(name) is None:
missing.append(name) missing.append(name)
if len(missing) > 0: if len(missing) > 0:
print("Missing required setting%s: %s." % ('s' if len(missing) > 1 else '', raise KeyError("Missing required setting{}: {}."
', '.join(missing)), .format('s' if len(missing) > 1 else '', ', '.join(missing)))
file=sys.stderr)
return False
class ServiceProxy: class ServiceProxy: