Last active
April 19, 2016 08:15
-
-
Save xbglowx/d798da98ff9937e33862b285d0121bde to your computer and use it in GitHub Desktop.
Update Prometheus alerting rules after upgrading to 0.17.0
This file contains hidden or 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
| #!/usr/bin/python | |
| import re | |
| import os | |
| import sys | |
| for root, dirs, files in os.walk('.'): | |
| if root.find('.git') != -1 or not files: | |
| continue | |
| for kv_file in files: | |
| annotation_regex = 'SUMMARY|DESCRIPTION|RUNBOOK' | |
| with open("{}/{}".format(root, kv_file), 'r') as fh: | |
| file_contents = [] | |
| annotations = [] | |
| for line in fh: | |
| if re.search(annotation_regex, line): | |
| key, value = line.split(' ', 1) | |
| key = key.lower() | |
| line = "{} = {},\n".format(key, value.strip('\n')) | |
| annotations.append(" {}".format(line)) | |
| else: | |
| line = line.replace('WITH', 'LABELS') | |
| file_contents.append(line) | |
| if annotations: | |
| annotations.insert(0, 'ANNOTATIONS {\n') | |
| annotations.append('}\n') | |
| file_contents = file_contents + annotations | |
| try: | |
| with open("{}/{}.new".format(root, kv_file), 'w') as new_fh: | |
| new_fh.write(''.join(file_contents)) | |
| new_file = "{}/{}.new".format(root, kv_file) | |
| original_file = "{}/{}".format(root, kv_file) | |
| os.rename(new_file, original_file) | |
| except IOError as exc: | |
| print >> sys.stderr, exc | |
| sys.exit(1) | |
| sys.exit(0) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@beorn7 thanks for your contribution.