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

use print_function

This commit is contained in:
Nils 2017-06-27 21:53:16 +02:00
parent 67746dcced
commit 60c8aba7bc

View file

@ -16,68 +16,55 @@
# ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f # ln -s /usr/share/munin/plugins/etherscan_balance_ /etc/munin/plugins/etherscan_balance_0x3257bde8cf067ae6f1ddc0e4b140fe02e3c5e44f
# #
from __future__ import print_function
import os import os
import sys import sys
import urllib2 import urllib2
import socket import socket
import json import json
OPTIONS = sys.argv[0].split('_')
command = '' command = ''
if len(sys.argv) > 1: if len(sys.argv) > 1:
command = sys.argv[1] command = sys.argv[1]
try: try:
OPTIONS[2] eth_address = sys.argv[0].split("_")[1:]
except IndexError: except ValueError:
print "Ethereum address missing!" print("The filename of this plugin (or its symlink) should follow this pattern: "
sys.exit(9) "'<YOUR_PUBLIC_ethEREUM_ADDRESS>'", file=sys.stderr)
ETH_ADDRESS = OPTIONS[2]
if ETH_ADDRESS == "":
print "Ethereum address missing!"
sys.exit(9) sys.exit(9)
if command == 'config': if command == 'config':
print "graph_title ETH " + ETH_ADDRESS print("graph_title eth {}".format(eth_address))
print "graph_info Ethereum Address " + ETH_ADDRESS print("graph_title Ethereum Address {}".format(eth_address))
print "graph_vlabel Ethereum Balance" print("graph_info Ethereum Account Balance for Address {}".format(eth_address))
print "graph_category htc" print("graph_title Ethereum Balance")
print ETH_ADDRESS + ".label ETH" print("graph_title htc")
print("{}label eth".format(eth_address))
sys.exit(0) sys.exit(0)
ethercan_balance_api_url = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest&address=' + eth_address
URL = 'https://api.etherscan.io/api?module=account&action=balance&tag=latest' etherscan_req = urllib2.Request(ethercan_balance_api_url)
STATS = URL + '&address=' + ETH_ADDRESS etherscan_req.add_header('User-Agent', 'Mozilla/5.0')
mining_req = urllib2.Request(STATS)
mining_req.add_header('User-Agent', 'Mozilla/5.0')
try: try:
mining_stats_raw = urllib2.urlopen(mining_req, None, 1.5 ) etherscan_balance_raw = urllib2.urlopen(etherscan_req, timeout=1.5 )
except urllib2.HTTPError: except IOError as exc:
print "HTTP Error!" print("Failed to request etherscan.io API: {}".format(exc), file=sys.stderr)
sys.exit(9)
except urllib2.URLError: try:
print "HTTP URL Error!" etherscan_balance = json.load(etherscan_balance_raw)
sys.exit(9) except ValueError:
except socket.timeout: print("Failed to parse JSON responce.", file=sys.stderr);
print "HTTP Timed out!"
sys.exit(9) sys.exit(9)
try: try:
mining_stats = json.load(mining_stats_raw) float(etherscan_balance['result'])
except: except:
print "JSON Error!" print("Result Error!", file=sys.stderr);
sys.exit(9) sys.exit(9)
try: eth = float(etherscan_balance['result']) / 1000000000000000000
float(mining_stats['result']) print("{}_{}.value %.2f".format(eth_address, eth));
except:
print "Result Error!"
sys.exit(9)
ETH = float(mining_stats['result']) / 1000000000000000000
print ETH_ADDRESS + ".value %.2f" % ETH