Skip to content

Commit

Permalink
Merge pull request #243 from acjohnson/242fix
Browse files Browse the repository at this point in the history
add missing argument http_get_headers (resolves #242)
  • Loading branch information
acjohnson authored Sep 22, 2023
2 parents 48e96d7 + 0e5c642 commit 3732370
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion grafana_backup/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 2 additions & 1 deletion grafana_backup/create_contact_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions grafana_backup/save_alert_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion grafana_backup/save_contact_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion grafana_backup/save_notification_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion grafana_backup/update_notification_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3732370

Please sign in to comment.