Created
April 24, 2019 22:47
-
-
Save niedbalski/a1bfe062468bbc1f489eea49665b26c5 to your computer and use it in GitHub Desktop.
transcript yaml based (https://github.com/openstack/openstack-helm-infra/blob/master/prometheus-alertmanager/values.yaml) to prometheus alert format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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