From fb18e8e3017e634f42437d0eb3a5d44e43ea44c9 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 10 Oct 2013 20:51:50 +0200 Subject: Add two more plugins ...snce the rewrite is still pending --- pellematic-burner-runtime | 132 +++++++++++++++++++++++++++++++++++++++++ pellematic-pumps | 148 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 280 insertions(+) create mode 100755 pellematic-burner-runtime create mode 100755 pellematic-pumps diff --git a/pellematic-burner-runtime b/pellematic-burner-runtime new file mode 100755 index 0000000..653c452 --- /dev/null +++ b/pellematic-burner-runtime @@ -0,0 +1,132 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8 : +# +# Munin plugin to monitor the temperature values +# of a pelletronic/pelletronic touch 2.0 +# +# Copyright 2013 Guido Guenther +# +# Licesnse: GPLv3 +# +# depends: python-requests +# +# FIXME: This currently doesn't probe the connected systems +# +#%# capabilities=autoconf +#%# family=contrib + +import requests +import os +import re +import sys +import json + +username = os.getenv('username', 'oekofen') +password = os.getenv('password', username) +debug = os.getenv('debug') + +# The items we want to plot: +items = ["CAPPL:FA[0].L_brennerlaufzeit_anzeige" + ] + +def canon(name): + return re.sub(r"[^a-zA-Z0-9_]", "_", name) + + +def print_config(url): + print """graph_title Pellematic Burning Time +graph_vlabel Burning time +graph_category Heating +graph_info This graph shows different hours of burner operation +""" + + out = fetch_raw(url) + for item in out: + if item['name'] in items: + name = item['shortText'] + print "%s.label %s" % (canon(name), name) + print "%s.type GAUGE" % canon(name) + thickness = 1 if name.endswith('soll') else 2 + print "%s.draw LINE%d" % (canon(name), thickness) + +def fetch_raw(url): + # Perform authentication and get the cookie + auth_formdata = {'language': 'en', + 'username': username, + 'password': password, + 'submit': 'Login', + } + r = requests.post(url, data=auth_formdata) + + pksession = r.cookies['pksession'] + cookies = { 'pksession': pksession, + 'language': 'en' } + params = { 'action': 'get', + 'attr': '1', + } + + # These are the headers used by the supplied application + # It mostly doesn't matter what we pass but the backend + # breaks with a lua error without a Accept-Language header: + headers = {'Accept': 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + 'Accept-Language': 'en', + } + + # The items to fetch are passed as simple json string + payload = json.dumps(items) + 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 + + if debug: + print >>sys.stderr, ret + + return ret + +def fetch_values(url): + out = fetch_raw(url) + for item in out: + if item['name'] in items: + name = canon(item['shortText']) + print "%s.value %s" % (name, item['value']) + + +def main(args): + target = os.getenv('address') + if not target: + print >>sys.stderr, "No ip address configured" + return 1 + url = 'http://%s' % target + if len(args) > 1: + if args[1] in [ 'autoconf', 'detect' ]: + try: + fetch_raw(url) + print "yes" + return 0 + except: + 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 + return 1 + return 0 + try: + fetch_values(url) + except Exception as e: + print >>sys.stderr, "Failed to fetch values: '%s'" % e + return 1 + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/pellematic-pumps b/pellematic-pumps new file mode 100755 index 0000000..e24a4b1 --- /dev/null +++ b/pellematic-pumps @@ -0,0 +1,148 @@ +#!/usr/bin/python +# vim: set fileencoding=utf-8 : +# +# Munin plugin to monitor the temperature values +# of a pelletronic/pelletronic touch 2.0 +# +# Copyright 2013 Guido Guenther +# +# Licesnse: GPLv3 +# +# depends: python-requests +# +# FIXME: This currently doesn't probe the connected systems +# +#%# capabilities=autoconf +#%# family=contrib + +import requests +import os +import re +import sys +import json + +username = os.getenv('username', 'oekofen') +password = os.getenv('password', username) +debug = os.getenv('debug') + +# The items we want to plot: +items = ["CAPPL:LOCAL.L_hk[0].pumpe", + "CAPPL:LOCAL.L_pu[0].pumpe", + ] + +def canon(name): + return re.sub(r"[^a-zA-Z0-9_]", "_", name) + +def fixup_name(item): + if ".L_pu[" in item['name']: + name = "Buffer Load Pump %d" + elif ".L_hk[" in item['name']: + name = "Heat Circuit Pump %d" + return name % (int(item['name'].split('.')[-2][-2]) + 1) + +def percent_val(item): + if item['unitText'] == '%': + return int(item['value']) + else: # assume On|Off + return int(item['value']) * 100 + +def print_config(url): + 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: + if item['name'] in items: + name = fixup_name(item) + 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) + if draw == "AREA": + draw = "STACK" + +def fetch_raw(url): + # Perform authentication and get the cookie + auth_formdata = {'language': 'en', + 'username': username, + 'password': password, + 'submit': 'Login', + } + r = requests.post(url, data=auth_formdata) + + pksession = r.cookies['pksession'] + cookies = { 'pksession': pksession, + 'language': 'en' } + params = { 'action': 'get', + 'attr': '1', + } + + # These are the headers used by the supplied application + # It mostly doesn't matter what we pass but the backend + # breaks with a lua error without a Accept-Language header: + headers = {'Accept': 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', + 'Accept-Language': 'en', + } + + # The items to fetch are passed as simple json string + payload = json.dumps(items) + 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 + + if debug: + print >>sys.stderr, ret + + return ret + +def fetch_values(url): + out = fetch_raw(url) + for item in out: + if item['name'] in items: + name = canon(fixup_name(item)) + print "%s.value %s" % (name, percent_val(item)) + + +def main(args): + target = os.getenv('address') + if not target: + print >>sys.stderr, "No ip address configured" + return 1 + url = 'http://%s' % target + if len(args) > 1: + if args[1] in [ 'autoconf', 'detect' ]: + try: + fetch_raw(url) + print "yes" + return 0 + except: + 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 + return 1 + return 0 + try: + fetch_values(url) + except Exception as e: + print >>sys.stderr, "Failed to fetch values: '%s'" % e + return 1 + return 0 + +if __name__ == "__main__": + sys.exit(main(sys.argv)) -- cgit v1.2.3