from __future__ import (absolute_import, division, print_function) __metaclass__ = type from functools import partial from ansible import errors def prometheus_generic_job_targets(hostvars, jobs, targets): try: result = [] for job in jobs: for target in targets: enabled = job in hostvars[target]['prometheus_exporters_default'] or job in hostvars[target]['prometheus_exporters_extra'] result.append({'job': job, 'instance': target, 'enabled': enabled}) return result except Exception as e: raise errors.AnsibleFilterError("prometheus_generic_job_targets(): %s" % str(e)) def prometheus_special_job_targets(hostvars, jobs, targets): try: result = [] for job in jobs: for target in targets: config_varname = 'prometheus_special_job_' + job if config_varname in hostvars[target]: result.append({'job': job, 'instance': hostvars[target][config_varname]['instance'], 'config': hostvars[target][config_varname]}) return result except Exception as e: raise errors.AnsibleFilterError("prometheus_special_job_targets(): %s" % str(e)) class FilterModule(object): ''' prometheus filters ''' filter_map = { 'prometheus_generic_job_targets': prometheus_generic_job_targets, 'prometheus_special_job_targets': prometheus_special_job_targets, } def filters(self): return self.filter_map