Allow to get attributs on more than one levels
Add an example for that And fix minors bugs
This commit is contained in:
parent
ea46631f0a
commit
78bea66884
2 changed files with 37 additions and 8 deletions
|
|
@ -151,6 +151,23 @@ class GenericMuninPlugin(object):
|
||||||
elif len(self.do) == 3:
|
elif len(self.do) == 3:
|
||||||
return self.weboob.do(self.do[0], self.do[1], backends=self.do[2])
|
return self.weboob.do(self.do[0], self.do[1], backends=self.do[2])
|
||||||
|
|
||||||
|
def get_value(self, result):
|
||||||
|
attribs = self.attribvalue.split('/')
|
||||||
|
for attrib in attribs:
|
||||||
|
result = getattr(result, attrib)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def monitored(self, result):
|
||||||
|
return not self.tomonitore or ('%s@%s' % (getattr(result, self.attribid), result.backend)) in self.tomonitore
|
||||||
|
|
||||||
|
def result2id(self, result):
|
||||||
|
attribs = self.attribid.split('/')
|
||||||
|
id = result
|
||||||
|
for attrib in attribs:
|
||||||
|
id = getattr(id, attrib)
|
||||||
|
return '%s_%s' % (result.backend, id)
|
||||||
|
|
||||||
|
|
||||||
def config(self):
|
def config(self):
|
||||||
if self.check_cache('%s-config' % self.name):
|
if self.check_cache('%s-config' % self.name):
|
||||||
return
|
return
|
||||||
|
|
@ -167,7 +184,7 @@ class GenericMuninPlugin(object):
|
||||||
d = {}
|
d = {}
|
||||||
for backend, result in self.build_do():
|
for backend, result in self.build_do():
|
||||||
if self.monitored(result):
|
if self.monitored(result):
|
||||||
d['%s@%s' % (getattr(value, self.attribid), result.backend)] = result
|
d['%s@%s' % (self.result2id(result), result.backend)] = result
|
||||||
|
|
||||||
for id in self.tomonitore:
|
for id in self.tomonitore:
|
||||||
try:
|
try:
|
||||||
|
|
@ -193,12 +210,6 @@ class GenericMuninPlugin(object):
|
||||||
else:
|
else:
|
||||||
self.flush_cache()
|
self.flush_cache()
|
||||||
|
|
||||||
def monitored(self, result):
|
|
||||||
return not self.tomonitore or ('%s@%s' % (getattr(value, self.attribid), result.backend)) in self.tomonitore
|
|
||||||
|
|
||||||
def result2id(self, result):
|
|
||||||
return '%s_%s' % (result.backend, getattr(result, self.attribid))
|
|
||||||
|
|
||||||
def print_errors(self, errors):
|
def print_errors(self, errors):
|
||||||
for backend, err, backtrace in errors:
|
for backend, err, backtrace in errors:
|
||||||
print >>sys.stderr, (u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace')
|
print >>sys.stderr, (u'%s(%s): %s' % (type(err).__name__, backend.name, err)).encode(sys.stdout.encoding or locale.getpreferredencoding(), 'replace')
|
||||||
|
|
@ -214,7 +225,7 @@ class GenericMuninPlugin(object):
|
||||||
try:
|
try:
|
||||||
for backend, result in self.build_do():
|
for backend, result in self.build_do():
|
||||||
if self.monitored(result):
|
if self.monitored(result):
|
||||||
value = getattr(result, self.attribvalue)
|
value = self.get_value(result)
|
||||||
self.write_output('%s.value %d' % (self.result2id(result), value))
|
self.write_output('%s.value %d' % (self.result2id(result), value))
|
||||||
except CallErrors, errors:
|
except CallErrors, errors:
|
||||||
self.print_errors(errors)
|
self.print_errors(errors)
|
||||||
|
|
|
||||||
|
|
@ -54,4 +54,22 @@ echo "========= ICapBill config"
|
||||||
./bill config
|
./bill config
|
||||||
rm bill
|
rm bill
|
||||||
|
|
||||||
|
# Monitor temperature in Rennes
|
||||||
|
|
||||||
|
export cache_expire=7200
|
||||||
|
export HOME="/home/flo"
|
||||||
|
export capa="ICapWeather"
|
||||||
|
export do="get_current,619163,yahoo"
|
||||||
|
export import="from weboob.capabilities.weather import ICapWeather"
|
||||||
|
export attribvalue="temp/value"
|
||||||
|
export attribid="temp/id"
|
||||||
|
export title="Température à Rennes"
|
||||||
|
export vlabel="Température"
|
||||||
|
|
||||||
|
echo "========= ICapWeather fetch"
|
||||||
|
cp ./generic-munin ./rennes
|
||||||
|
./rennes
|
||||||
|
echo "========= ICapWeather config"
|
||||||
|
./rennes config
|
||||||
|
rm rennes
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue