aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2013-11-03 18:54:48 +0100
committerGuido Günther <agx@sigxcpu.org>2013-11-03 18:55:37 +0100
commit156503bebddf753662c3d6e15cc8f2695252e54e (patch)
tree1edf6007c0116a4b22d7b808e9e8776689a73e6c
parent56eaaacd26dfebb629c5bf02b37df7f7f048133e (diff)
Add runtime coefficient plugin
Simple plugin to see changes in on time vs. off time
-rwxr-xr-xpellematic-time135
1 files changed, 135 insertions, 0 deletions
diff --git a/pellematic-time b/pellematic-time
new file mode 100755
index 0000000..03df3d9
--- /dev/null
+++ b/pellematic-time
@@ -0,0 +1,135 @@
+#!/usr/bin/python
+# vim: set fileencoding=utf-8 :
+#
+# Munin plugin to monitor the runtime vs. the off time of a
+# pelletronic/pelletronic touch 2.0
+#
+# Copyright 2013 Guido Guenther <agx@sigxcpu.org>
+#
+# 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 fetch:
+items = { "off": "CAPPL:FA[0].L_sillstandszeit",
+ "on": "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 runtime coefficent
+graph_vlabel Coefficient
+graph_category Heating
+graph_info This graph shows the amount of time the oven did not run versus the time the oven did run
+graph_period hour
+
+coefficient.label runtime coefficient
+coefficient.type GAUGE
+coefficient.draw LINE1
+"""
+
+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.values())
+ 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)
+ on = 0.0
+ off = 1.0
+
+ for item in out:
+ if item['name'] == items['off']:
+ off = float(item['value'])
+ if item['name'] == items['on']:
+ on = float(item['value'])
+
+ print "coefficient.value %f" % (on/off)
+
+
+
+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))