Skip to content

Instantly share code, notes, and snippets.

@niedbalski
Created April 24, 2019 22:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niedbalski/a1bfe062468bbc1f489eea49665b26c5 to your computer and use it in GitHub Desktop.
Save niedbalski/a1bfe062468bbc1f489eea49665b26c5 to your computer and use it in GitHub Desktop.
from jinja2 import Environment
import yaml
import sys
RULE_TPL = """
ALERT {{ alert }}
IF {{ expr }}
FOR {{ for }}
LABELS {
severity="page"
}
ANNOTATIONS {
SUMMARY = "{{ annotations.summary }}",
DESCRIPTION = "{{ annotations.description }}"
}
"""
def load_template(template, **data):
return Environment().from_string(template).render(**data)
def main(component):
with open("./values.yaml") as fd:
config = yaml.load(fd.read())
for name, config in config.get('conf').get('prometheus').get('rules').items():
if name in component:
rule_configs = config['groups'][0].get('rules')
for rule in rule_configs:
print(load_template(RULE_TPL, **rule))
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment