Skip to content
Snippets Groups Projects
Verified Commit 8aa53518 authored by Robotka István Adrián's avatar Robotka István Adrián
Browse files

add job definition to the templating

parent 881c3e96
Branches
Tags
1 merge request!8add job definition to the templating
Pipeline #4216 passed with warnings
...@@ -22,12 +22,13 @@ class ConfigBuilder: ...@@ -22,12 +22,13 @@ class ConfigBuilder:
for job in service['scraping']: for job in service['scraping']:
self.logger.debug("Templating: " + service['service_name'] + ' -> ' + job['template']) self.logger.debug("Templating: " + service['service_name'] + ' -> ' + job['template'])
self.load_template(job) self.load_template(job)
template = self.substitute_template_field(job, service) output = self.substitute_template_field(job, service)
# store generated prometheus job config # store generated prometheus job config
if 'ignore' in job and check_true(job['ignore']): if 'ignore' in job and check_true(job['ignore']):
job['output_yaml'] = None job['output_yaml'] = None
else: else:
job['output_yaml'] = yaml.safe_load(template) job['output_yaml'] = yaml.safe_load(output)
def load_template(self, job): def load_template(self, job):
"""Substitute 'template' field with its content""" """Substitute 'template' field with its content"""
...@@ -39,7 +40,7 @@ class ConfigBuilder: ...@@ -39,7 +40,7 @@ class ConfigBuilder:
env = jinja2.Environment(undefined=jinja2.DebugUndefined) env = jinja2.Environment(undefined=jinja2.DebugUndefined)
template = env.from_string(job['template']) template = env.from_string(job['template'])
data = service.copy() data = service.copy()
data['targets'] = job['targets'] data['job'] = job
data['snippet'] = collect_snippets(self.config.templates) data['snippet'] = collect_snippets(self.config.templates)
return template.render(data) return template.render(data)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment