don't send tags to the Grafana annotations API if none are specified

see: https://github.com/ansible/awx/issues/6580
This commit is contained in:
Ryan Petrello
2020-04-06 14:11:52 -04:00
parent 592043fa70
commit 771ca2400a
2 changed files with 7 additions and 6 deletions

View File

@@ -89,7 +89,8 @@ class GrafanaBackend(AWXBaseEmailBackend, CustomNotificationBase):
grafana_data['isRegion'] = self.isRegion grafana_data['isRegion'] = self.isRegion
grafana_data['dashboardId'] = self.dashboardId grafana_data['dashboardId'] = self.dashboardId
grafana_data['panelId'] = self.panelId grafana_data['panelId'] = self.panelId
grafana_data['tags'] = self.annotation_tags if self.annotation_tags:
grafana_data['tags'] = self.annotation_tags
grafana_data['text'] = m.subject grafana_data['text'] = m.subject
grafana_headers['Authorization'] = "Bearer {}".format(self.grafana_key) grafana_headers['Authorization'] = "Bearer {}".format(self.grafana_key)
grafana_headers['Content-Type'] = "application/json" grafana_headers['Content-Type'] = "application/json"

View File

@@ -18,7 +18,7 @@ def test_send_messages():
requests_mock.post.assert_called_once_with( requests_mock.post.assert_called_once_with(
'https://example.com/api/annotations', 'https://example.com/api/annotations',
headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'}, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'},
json={'tags': [], 'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': None, 'time': 60000, 'dashboardId': None}, json={'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': None, 'time': 60000, 'dashboardId': None},
verify=True) verify=True)
assert sent_messages == 1 assert sent_messages == 1
@@ -36,7 +36,7 @@ def test_send_messages_with_no_verify_ssl():
requests_mock.post.assert_called_once_with( requests_mock.post.assert_called_once_with(
'https://example.com/api/annotations', 'https://example.com/api/annotations',
headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'}, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'},
json={'tags': [], 'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': None,'time': 60000, 'dashboardId': None}, json={'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': None,'time': 60000, 'dashboardId': None},
verify=False) verify=False)
assert sent_messages == 1 assert sent_messages == 1
@@ -54,7 +54,7 @@ def test_send_messages_with_dashboardid():
requests_mock.post.assert_called_once_with( requests_mock.post.assert_called_once_with(
'https://example.com/api/annotations', 'https://example.com/api/annotations',
headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'}, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'},
json={'tags': [], 'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': None, 'time': 60000, 'dashboardId': 42}, json={'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': None, 'time': 60000, 'dashboardId': 42},
verify=True) verify=True)
assert sent_messages == 1 assert sent_messages == 1
@@ -72,7 +72,7 @@ def test_send_messages_with_panelid():
requests_mock.post.assert_called_once_with( requests_mock.post.assert_called_once_with(
'https://example.com/api/annotations', 'https://example.com/api/annotations',
headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'}, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'},
json={'tags': [], 'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': 42, 'time': 60000, 'dashboardId': None}, json={'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': 42, 'time': 60000, 'dashboardId': None},
verify=True) verify=True)
assert sent_messages == 1 assert sent_messages == 1
@@ -90,7 +90,7 @@ def test_send_messages_with_bothids():
requests_mock.post.assert_called_once_with( requests_mock.post.assert_called_once_with(
'https://example.com/api/annotations', 'https://example.com/api/annotations',
headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'}, headers={'Content-Type': 'application/json', 'Authorization': 'Bearer testapikey'},
json={'tags': [], 'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': 42, 'time': 60000, 'dashboardId': 42}, json={'text': 'test subject', 'isRegion': True, 'timeEnd': 120000, 'panelId': 42, 'time': 60000, 'dashboardId': 42},
verify=True) verify=True)
assert sent_messages == 1 assert sent_messages == 1