From 4bc44e4062e31cf1189d2dfa13fd3ba46a4aeaad Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 3 Feb 2021 07:52:59 +0100 Subject: [PATCH] sensu-silence: fix json parsing of sensu API response (#1703) (#1718) * sensu-silence: fix json parsing of sensu API response * use ansible helper function to decode bytestream * add changelog fragment * Update changelogs, link to PR Co-authored-by: Felix Fontein Co-authored-by: Felix Fontein (cherry picked from commit b40a5ef09af043677b4b6e9d91d419cf29159b48) Co-authored-by: Stefan Walluhn --- .../fragments/1703-sensu_silence-fix_json_parsing.yml | 2 ++ plugins/modules/monitoring/sensu/sensu_silence.py | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/1703-sensu_silence-fix_json_parsing.yml diff --git a/changelogs/fragments/1703-sensu_silence-fix_json_parsing.yml b/changelogs/fragments/1703-sensu_silence-fix_json_parsing.yml new file mode 100644 index 0000000000..18d39b5674 --- /dev/null +++ b/changelogs/fragments/1703-sensu_silence-fix_json_parsing.yml @@ -0,0 +1,2 @@ +bugfixes: + - sensu-silence module - fix json parsing of sensu API responses on Python 3.5 (https://github.com/ansible-collections/community.general/pull/1703). diff --git a/plugins/modules/monitoring/sensu/sensu_silence.py b/plugins/modules/monitoring/sensu/sensu_silence.py index acd64f975c..12dc5d2068 100644 --- a/plugins/modules/monitoring/sensu/sensu_silence.py +++ b/plugins/modules/monitoring/sensu/sensu_silence.py @@ -97,6 +97,7 @@ RETURN = ''' import json +from ansible.module_utils._text import to_native from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.urls import fetch_url @@ -129,7 +130,7 @@ def query(module, url, check, subscription): ) try: - json_out = json.loads(response.read()) + json_out = json.loads(to_native(response.read())) except Exception: json_out = "" @@ -181,7 +182,7 @@ def clear(module, url, check, subscription): ) try: - json_out = json.loads(response.read()) + json_out = json.loads(to_native(response.read())) except Exception: json_out = "" @@ -246,7 +247,7 @@ def create( ) try: - json_out = json.loads(response.read()) + json_out = json.loads(to_native(response.read())) except Exception: json_out = ""