Add get_object_list in generic-munin

This commit is contained in:
Florent 2013-08-12 17:08:22 +02:00
commit edbe8b454d
3 changed files with 51 additions and 7 deletions

View file

@ -16,6 +16,7 @@ The Weboob capability to load.
Example: env.do get_balance
The Weboob command to call the capability. It can take more than one argument. With two argument, the second is used as parameter for the command. The third is used to restrict backends.
If you use get_object_list option, you can use only one argument in env.do.
==== env.import ====
Example: from weboob.capabilities.bank import ICapBank
@ -50,13 +51,18 @@ Example: env.cumulate 0 (default 1)
Display data in Area mode (default) or in line mode.
==== env.get_object_list ====
Exemple: env.get_object_list="iter_subscriptions"
Run a first time a cap's method to get a list of objects. env.do is then applied on all results.
==== env.attribid ====
Example env.attribid id
Example: env.attribid id
Munin need an id for each value. The default is to use the id of results objects, but you can configure an other attribut. Like for env.attribvalue, you can configure a hierarchical attribut with / as separator, for example "temp/id".
==== env.title ====
Example env.title a wonderful graph
Example: env.title a wonderful graph
A title for the graph (default: nothing)

View file

@ -27,6 +27,7 @@ import logging
from weboob.core import Weboob, CallErrors
from weboob.tools.browser import BrowserIncorrectPassword
class GenericMuninPlugin(object):
def __init__(self):
if 'weboob_path' in os.environ:
@ -48,6 +49,9 @@ class GenericMuninPlugin(object):
self.mimport = os.environ["import"]
exec(self.mimport)
# We can monitore only some objects
self.object_list = None
if 'get_object_list' in os.environ:
self.object_list = os.environ["get_object_list"]
self.tomonitore = None
if 'id_monitored' in os.environ:
self.tomonitore = os.environ['id_monitored'].split(' ')
@ -147,12 +151,26 @@ class GenericMuninPlugin(object):
self.cache.write('%s\n' % line)
def build_do(self):
if len(self.do) == 1:
return self.weboob.do(self.do[0])
if self.object_list:
results = []
for result in self.weboob.do(self.object_list):
results.append(result)
for backend, result in results:
try:
for i in self.weboob.do(self.do[0], result.id, backends=backend):
yield i
# Do not crash if one module does not implement the feature
except CallErrors:
pass
elif len(self.do) == 1:
for i in self.weboob.do(self.do[0]):
yield i
elif len(self.do) == 2:
return self.weboob.do(self.do[0], self.do[1])
for i in self.weboob.do(self.do[0], self.do[1]):
yield i
elif len(self.do) == 3:
return self.weboob.do(self.do[0], self.do[1], backends=self.do[2])
for i in self.weboob.do(self.do[0], self.do[1], backends=self.do[2]):
yield i
def get_value(self, result):
attribs = self.attribvalue.split('/')

View file

@ -23,7 +23,7 @@ rm banbank
export cache_expire=7200
export HOME="/home/flo"
export capa="ICapGauge"
export do="get_last_measure,501060-level"
export do="get_last_measure,501060-level,sachsen"
export import="from weboob.capabilities.gauge import ICapGauge"
export attribvalue="level"
export title="Niveau de l'elbe"
@ -75,6 +75,26 @@ echo "========= ICapBill config"
./bill config
rm bill
# Monitor all balances of all subscriptions
export cache_expire=7200
export HOME="/home/flo"
export capa="ICapBill"
export do="get_balance"
export get_object_list="iter_subscription"
export import="from weboob.capabilities.bill import ICapBill"
export attribvalue="price"
export title="Solde restant"
export vlabel="Solde"
echo "========= ICapBill2 fetch"
cp ./generic-munin ./bill
./bill
echo "========= ICapBill2 config"
./bill config
rm bill
unset get_object_list
# Monitor temperature in Rennes
export cache_expire=7200