From ef36f6c5fcf8f6fef13d88e04bef3b01091221df Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Thu, 21 Sep 2023 22:04:29 -0500 Subject: [PATCH 1/2] add missing argument http_get_headers #242 --- grafana_backup/create_contact_point.py | 3 ++- grafana_backup/save_alert_rules.py | 20 +++++++++++++------- grafana_backup/save_contact_points.py | 2 +- grafana_backup/save_notification_policies.py | 2 +- grafana_backup/update_notification_policy.py | 3 ++- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/grafana_backup/create_contact_point.py b/grafana_backup/create_contact_point.py index d0a184a..ee1239e 100644 --- a/grafana_backup/create_contact_point.py +++ b/grafana_backup/create_contact_point.py @@ -6,12 +6,13 @@ def main(args, settings, file_path): grafana_url = settings.get('GRAFANA_URL') http_post_headers = settings.get('HTTP_POST_HEADERS') + http_get_headers = settings.get('HTTP_GET_HEADERS') verify_ssl = settings.get('VERIFY_SSL') client_cert = settings.get('CLIENT_CERT') debug = settings.get('DEBUG') try: - grafana_version = get_grafana_version(grafana_url, verify_ssl) + grafana_version = get_grafana_version(grafana_url, verify_ssl, http_get_headers) except KeyError as error: if not grafana_version: raise Exception("Grafana version is not set.") from error diff --git a/grafana_backup/save_alert_rules.py b/grafana_backup/save_alert_rules.py index 42a7ecb..0e705fc 100644 --- a/grafana_backup/save_alert_rules.py +++ b/grafana_backup/save_alert_rules.py @@ -17,10 +17,11 @@ def main(args, settings): log_file = 'alert_rules_{0}.txt'.format(timestamp) grafana_version_string = settings.get('GRAFANA_VERSION') if grafana_version_string: - grafana_version = version.parse(grafana_version_string) + grafana_version = version.parse(grafana_version_string) try: - grafana_version = get_grafana_version(grafana_url, verify_ssl, http_get_headers) + grafana_version = get_grafana_version( + grafana_url, verify_ssl, http_get_headers) except KeyError as error: if not grafana_version: raise Exception("Grafana version is not set.") from error @@ -32,9 +33,11 @@ def main(args, settings): if not os.path.exists(folder_path): os.makedirs(folder_path) - save_alert_rules(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print) + save_alert_rules(folder_path, log_file, grafana_url, + http_get_headers, verify_ssl, client_cert, debug, pretty_print) else: - print("Unable to save alert rules, requires Grafana version {0} or above. Current version is {1}".format(minimum_version, grafana_version)) + print("Unable to save alert rules, requires Grafana version {0} or above. Current version is {1}".format( + minimum_version, grafana_version)) def get_all_alert_rules_in_grafana(grafana_url, http_get_headers, verify_ssl, client_cert, debug): @@ -46,14 +49,17 @@ def get_all_alert_rules_in_grafana(grafana_url, http_get_headers, verify_ssl, cl alert_rules = content print("There are {0} alert rules:".format(len(alert_rules))) for alert_rule in alert_rules: - print('name: {0}'.format(to_python2_and_3_compatible_string(alert_rule['title']))) + print('name: {0}'.format( + to_python2_and_3_compatible_string(alert_rule['title']))) return alert_rules else: - raise Exception("Failed to get alert rules, status: {0}, msg: {1}".format(status, content)) + raise Exception( + "Failed to get alert rules, status: {0}, msg: {1}".format(status, content)) def save_alert_rules(folder_path, log_file, grafana_url, http_get_headers, verify_ssl, client_cert, debug, pretty_print): - alert_rules = get_all_alert_rules_in_grafana(grafana_url, http_get_headers, verify_ssl, client_cert, debug) + alert_rules = get_all_alert_rules_in_grafana( + grafana_url, http_get_headers, verify_ssl, client_cert, debug) for alert_rule in alert_rules: print_horizontal_line() print(alert_rule) diff --git a/grafana_backup/save_contact_points.py b/grafana_backup/save_contact_points.py index bd3ded6..8a95545 100644 --- a/grafana_backup/save_contact_points.py +++ b/grafana_backup/save_contact_points.py @@ -21,7 +21,7 @@ def main(args, settings): grafana_version = version.parse(grafana_version_string) try: - grafana_version = get_grafana_version(grafana_url, verify_ssl) + grafana_version = get_grafana_version(grafana_url, verify_ssl, http_get_headers) except KeyError as error: if not grafana_version: raise Exception("Grafana version is not set.") from error diff --git a/grafana_backup/save_notification_policies.py b/grafana_backup/save_notification_policies.py index 38ab281..dcf7ab8 100644 --- a/grafana_backup/save_notification_policies.py +++ b/grafana_backup/save_notification_policies.py @@ -21,7 +21,7 @@ def main(args, settings): grafana_version = version.parse(grafana_version_string) try: - grafana_version = get_grafana_version(grafana_url, verify_ssl) + grafana_version = get_grafana_version(grafana_url, verify_ssl, http_get_headers) except KeyError as error: if not grafana_version: raise Exception("Grafana version is not set.") from error diff --git a/grafana_backup/update_notification_policy.py b/grafana_backup/update_notification_policy.py index e2e7106..f438806 100644 --- a/grafana_backup/update_notification_policy.py +++ b/grafana_backup/update_notification_policy.py @@ -6,12 +6,13 @@ def main(args, settings, file_path): grafana_url = settings.get('GRAFANA_URL') http_post_headers = settings.get('HTTP_POST_HEADERS') + http_get_headers = settings.get('HTTP_GET_HEADERS') verify_ssl = settings.get('VERIFY_SSL') client_cert = settings.get('CLIENT_CERT') debug = settings.get('DEBUG') try: - grafana_version = get_grafana_version(grafana_url, verify_ssl) + grafana_version = get_grafana_version(grafana_url, verify_ssl, http_get_headers) except KeyError as error: if not grafana_version: raise Exception("Grafana version is not set.") from error From 0e5c6428abd71a1e48d0cc701d0ec3d3387312b2 Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Thu, 21 Sep 2023 22:06:18 -0500 Subject: [PATCH 2/2] uprev package and update CHANGELOG.md --- CHANGELOG.md | 9 +++++++++ grafana_backup/constants.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf26948..2ed0837 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +# [1.4.1] - 2023-09-21 + +### Added + +### Changed +- add missing argument http_get_headers #242 #243 + +### Removed + # [1.4.0] - 2023-09-20 ### Added diff --git a/grafana_backup/constants.py b/grafana_backup/constants.py index 5ff8373..8d0186c 100644 --- a/grafana_backup/constants.py +++ b/grafana_backup/constants.py @@ -7,5 +7,5 @@ homedir = os.environ["HOME"] PKG_NAME = "grafana-backup" -PKG_VERSION = "1.4.0" +PKG_VERSION = "1.4.1" JSON_CONFIG_PATH = "{0}/.grafana-backup.json".format(homedir)