diff --git a/build.py b/build.py index 69e7e2b696873d127815ce732cce253cf2b29cfc..061455f64fa3fde5b3e88a3b777436f0a7256802 100644 --- a/build.py +++ b/build.py @@ -6,7 +6,7 @@ import yaml from config import Config from constants import APP_LOG_TAG, TEMPLATE_PREFIX -from helper import collect_snippets +from helper import collect_snippets, check_true class ConfigBuilder: @@ -24,7 +24,10 @@ class ConfigBuilder: self.load_template(job) template = self.substitute_template_field(job, service) # store generated prometheus job config - job['output_yaml'] = yaml.safe_load(template) + if 'ignore' in job and check_true(job['ignore']): + job['output_yaml'] = None + else: + job['output_yaml'] = yaml.safe_load(template) def load_template(self, job): """Substitute 'template' field with its content""" diff --git a/generator.py b/generator.py index 2cf67bcecb96bd1a5d82d899af5605829f7c2462..873e12e9a5c5bc46a5adacde122f9836078034bc 100644 --- a/generator.py +++ b/generator.py @@ -59,7 +59,8 @@ class Generator: data = [] for service in self.config.service_definitions: for job in service['scraping']: - data.append(job['output_yaml']) + if job['output_yaml'] is not None: + data.append(job['output_yaml']) output['scrape_configs'] = yaml.dump( {'scrape_configs': data}, explicit_start=False, diff --git a/helper.py b/helper.py index 35f2e164f24da99e8e41fbc40d59dbd29f1a2246..48c3064feb007488f8c05e76ffdf57276ae849aa 100644 --- a/helper.py +++ b/helper.py @@ -18,6 +18,15 @@ def is_snippet_file(file_identifier: str) -> bool: return file_identifier.startswith(SNIPPET_PREFIX) +def check_true(s: str) -> bool: + """Hmm, is it a true-ish string""" + return s.lower() in [ + 'true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh', + 'i', 'igen', 'aha', 'ja', 'jaja', 'nosza', 'mibajlehet', 'miƩrt ne', # Hungarian extension + 'temp', 'temporary', 'ideiglenesen' # other extension + ] + + def collect_snippets(templates): """Get snippets from templates""" snippets = {}