aboutsummaryrefslogtreecommitdiff
path: root/pellematic-pumps
diff options
context:
space:
mode:
Diffstat (limited to 'pellematic-pumps')
-rwxr-xr-xpellematic-pumps35
1 files changed, 15 insertions, 20 deletions
diff --git a/pellematic-pumps b/pellematic-pumps
index 1f8cc4b..48f9ead 100755
--- a/pellematic-pumps
+++ b/pellematic-pumps
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
# vim: set fileencoding=utf-8 :
#
# Munin plugin to monitor the pumps and fan speeds
@@ -64,20 +64,20 @@ def percent_val(item):
return int(item['value']) * 100
def print_config(url):
- print """graph_title Pellematic Pumps
+ print("""graph_title Pellematic Pumps
graph_vlabel Pump power in percent
graph_category Heating
graph_info This graph shows the pumping power of the different pumps
-"""
+""")
draw = "AREA"
out = fetch_raw(url)
for item in out:
name = get_name(item)
if name:
- print "%s.label %s" % (canon(name), name)
- print "%s.type GAUGE" % canon(name)
+ print("%s.label %s" % (canon(name), name))
+ print("%s.type GAUGE" % canon(name))
thickness = 1 if name.endswith('soll') else 2
- print "%s.draw %s" % (canon(name), draw)
+ print("%s.draw %s" % (canon(name), draw))
if draw == "AREA":
draw = "STACK"
@@ -106,20 +106,15 @@ def fetch_raw(url):
}
# The items to fetch are passed as simple json string
- payload = json.dumps(items.keys())
+ payload = json.dumps(list(items.keys()))
r = requests.post(url,
data=payload,
params=params,
cookies=cookies,
headers=headers)
-
- if hasattr(r.json, '__call__'):
- ret = r.json()
- else: # in requests 0.12 json isn't a callable
- ret = r.json
-
+ ret = r.json()
if debug:
- print >>sys.stderr, ret
+ print(ret, file=sys.stderr)
return ret
@@ -130,33 +125,33 @@ def fetch_values(url):
name = get_name(item)
if name:
cname = canon(name)
- print "%s.value %s" % (cname, percent_val(item))
+ print("%s.value %s" % (cname, percent_val(item)))
def main(args):
if not url:
- print >>sys.stderr, "No url configured"
+ print("No url configured", file=sys.stderr)
return 1
if len(args) > 1:
if args[1] in [ 'autoconf', 'detect' ]:
try:
fetch_raw(url)
- print "yes"
+ print("yes")
return 0
except:
- print "no"
+ print("no")
return 1
elif args[1] == 'config':
try:
print_config(url)
except Exception as e:
- print >>sys.stderr, "Failed to fetch config: '%s'" % e
+ print("Failed to fetch config: '%s'" % e, file=sys.stderr)
return 1
return 0
try:
fetch_values(url)
except Exception as e:
- print >>sys.stderr, "Failed to fetch values: '%s'" % e
+ print("Failed to fetch values: '%s'" % e, file=sys.stderr)
return 1
return 0