summaryrefslogtreecommitdiff
path: root/roles/monitoring/prometheus/server/filter_plugins/prometheus.py
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2021-09-21 19:34:25 +0200
committerChristian Pointner <equinox@spreadspace.org>2021-09-21 19:42:54 +0200
commita8e8cb2ed3d5e68d89edd8785ed59f0ee45f81bf (patch)
treee6457f4c46782e27c8d359e966e8afe1afca87a8 /roles/monitoring/prometheus/server/filter_plugins/prometheus.py
parentch-sensors1 add new 1-wire therm sensor and fix regexp (diff)
prometheus: simplify job config
Diffstat (limited to 'roles/monitoring/prometheus/server/filter_plugins/prometheus.py')
-rw-r--r--roles/monitoring/prometheus/server/filter_plugins/prometheus.py31
1 files changed, 11 insertions, 20 deletions
diff --git a/roles/monitoring/prometheus/server/filter_plugins/prometheus.py b/roles/monitoring/prometheus/server/filter_plugins/prometheus.py
index 5a8722c2..ab865f93 100644
--- a/roles/monitoring/prometheus/server/filter_plugins/prometheus.py
+++ b/roles/monitoring/prometheus/server/filter_plugins/prometheus.py
@@ -6,38 +6,29 @@ from functools import partial
from ansible import errors
-def prometheus_generic_job_targets(hostvars, jobs, targets):
+def prometheus_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})
+ special_config_varname = 'prometheus_special_job_' + job.replace('-', '_')
+ if special_config_varname in hostvars[target]:
+ for config in hostvars[target][special_config_varname]:
+ result.append({'job': job, 'instance': config['instance'], 'config': config, 'enabled': True})
+
+ else:
+ 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.replace('-', '_')
- if config_varname in hostvars[target]:
- for config in hostvars[target][config_varname]:
- result.append({'job': job, 'instance': config['instance'], 'config': config})
- return result
- except Exception as e:
- raise errors.AnsibleFilterError("prometheus_special_job_targets(): %s" % str(e))
+ raise errors.AnsibleFilterError("prometheus_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,
+ 'prometheus_job_targets': prometheus_job_targets,
}
def filters(self):