aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2013-10-13 10:36:35 +0200
committerGuido Günther <agx@sigxcpu.org>2013-10-13 10:36:35 +0200
commit68e028d510b2e232d5889cc457b089f0324b2f55 (patch)
treee4738e36105d2169ca4308b3dc0e9b1a600359ce
parentfb18e8e3017e634f42437d0eb3a5d44e43ea44c9 (diff)
Add plugin for to measure the negative draft
-rwxr-xr-xpellematic-draft146
1 files changed, 146 insertions, 0 deletions
diff --git a/pellematic-draft b/pellematic-draft
new file mode 100755
index 0000000..b3e7232
--- /dev/null
+++ b/pellematic-draft
@@ -0,0 +1,146 @@
+#!/usr/bin/python
+# vim: set fileencoding=utf-8 :
+#
+# Munin plugin to monitor the negative draft in the combustion chamber
+# of a pellematic
+#
+# Copyright 2013 Guido Günther <agx@sigxcpu.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# depends: python-requests
+#
+#%# 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_unterdruck"]
+
+def fixup(name):
+ return name
+
+def canon(name):
+ return re.sub(r"[^a-zA-Z0-9_]", "_", name)
+
+def print_config(url):
+ print """graph_title Pellematic Negative Draft
+graph_vlabel Temperature in Pa
+graph_category Heating
+graph_info This graph shows the negative pressure in the combustion chamber of a Pellematic by Ökofen"""
+
+ out = fetch_raw(url)
+ for item in out:
+ if item['name'] in items:
+ name = fixup(item['shortText'])
+ print "%s.label %s" % (canon(name), name)
+ print "%s.type GAUGE" % canon(name)
+ thickness = 1 if name.endswith(' Set') else 2
+ print "%s.draw LINE%d" % (canon(name), thickness)
+
+def calc(val):
+ return float(int(val['value'])) / float(val['divisor'])
+
+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(item['shortText']))
+ print "%s.value %.2f" % (name,
+ calc(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))