From abdeb7ec6500b14bd833f8afbd262a9d24bc16d8 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Fri, 24 Aug 2018 21:52:34 +0200 Subject: [PATCH] Plugin bitcoind_: introduce explicit configuration file path The home directory of the currently effective UID cannot be easily inferred in python via os.path.expanduser. Since there is no other simple way for reaching this goal, an explicit environemnt setting is introduced. --- plugins/currency/bitcoin/bitcoind_ | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/currency/bitcoin/bitcoind_ b/plugins/currency/bitcoin/bitcoind_ index 142382ce..293b72cc 100755 --- a/plugins/currency/bitcoin/bitcoind_ +++ b/plugins/currency/bitcoin/bitcoind_ @@ -14,8 +14,10 @@ This plugin supports two ways to do that: [bitcoind_*] user your-username + env.bitcoin_configfile /home/your-username/.bitcoin/bitcoin.conf - Then be sure your $HOME/.bitcoin/bitcoin.conf has the correct authentication info: + Then be sure that the file referenced above (typically: $HOME/.bitcoin/bitcoin.conf) + has the correct authentication info: rpcconnect, rpcport, rpcuser, rpcpassword 2) Place your bitcoind authentication directly in /etc/munin/plugin-conf.d/bitcoin.conf @@ -97,8 +99,16 @@ def main(): bitcoin_options.rpcport = bitcoin_options.get('rpcport', '8332') if bitcoin_options.get('rpcuser') is None: - conf_file = os.path.join(os.path.expanduser('~/.bitcoin'), 'bitcoin.conf') - bitcoin_options = parse_conf(conf_file) + conf_file = os.getenv("bitcoin_configfile") + if not conf_file: + print("Missing environment settings (rpcuser/rcpassword or bitcoin_configfile)", + file=sys.stderr) + sys.exit(1) + elif not os.path.exists(conf_file): + print("Configuration file does not exist: {}".format(conf_file), file=sys.stderr) + sys.exit(1) + else: + bitcoin_options = parse_conf(conf_file) bitcoin_options.require('rpcuser', 'rpcpassword')