Introduce env.exclude

This commit is contained in:
Florent 2013-03-01 23:50:59 +01:00 committed by Romain Bignon
commit cee13a9be8
2 changed files with 13 additions and 2 deletions

View file

@ -36,6 +36,10 @@ If the attribut is itself one object, it is possible the use a hierarchical call
Example: env.id_monitored account1@backend1 account2@backend2 Example: env.id_monitored account1@backend1 account2@backend2
A list of object (space as separator). Only there objects are diplayed. A list of object (space as separator). Only there objects are diplayed.
==== env.exclude ====
Example: env.exclude 550810@sachsen
Same as env.id_monitored, but to exclude an object of results
==== env.cache_expire ==== ==== env.cache_expire ====
Example: env.cache_expire 7200 (default 3600) Example: env.cache_expire 7200 (default 3600)
@ -129,6 +133,7 @@ env.attribvalue sensors/lastvalue/level
env.title Niveau de l'elbe en Saxe env.title Niveau de l'elbe en Saxe
env.label name env.label name
env.vlabel Hauteur du fleuve (cm) env.vlabel Hauteur du fleuve (cm)
env.exclude 550810@sachsen
# Temperature in Rennes # Temperature in Rennes
[temprennes] [temprennes]

View file

@ -51,6 +51,9 @@ class GenericMuninPlugin(object):
self.tomonitore = None self.tomonitore = None
if 'id_monitored' in os.environ: if 'id_monitored' in os.environ:
self.tomonitore = os.environ['id_monitored'].split(' ') self.tomonitore = os.environ['id_monitored'].split(' ')
self.exclude = None
if 'exclude' in os.environ:
self.exclude = os.environ['exclude'].split(' ')
# Attribut of object to use as ID (default: id) # Attribut of object to use as ID (default: id)
self.attribid = "id" self.attribid = "id"
if 'attribid' in os.environ: if 'attribid' in os.environ:
@ -160,7 +163,10 @@ class GenericMuninPlugin(object):
return result return result
def monitored(self, result): def monitored(self, result):
return not self.tomonitore or ('%s@%s' % (getattr(result, self.attribid), result.backend)) in self.tomonitore id = '%s@%s' % (getattr(result, self.attribid), result.backend)
if self.exclude and id in self.exclude:
return False
return not self.tomonitore or id in self.tomonitore
def result2id(self, result): def result2id(self, result):
attribs = self.attribid.split('/') attribs = self.attribid.split('/')
@ -182,7 +188,7 @@ class GenericMuninPlugin(object):
self.write_output('graph_args -l 0') self.write_output('graph_args -l 0')
try: try:
objects = [] objects = []
if self.tomonitore is not None: if self.tomonitore is not None or self.exclude is not None:
d = {} d = {}
for backend, result in self.build_do(): for backend, result in self.build_do():
if self.monitored(result): if self.monitored(result):