log alarm rest notifier response
Currently we do nothing after post the rest action, so we don't know the actual result of it, except it raises exception. This is not right because there is no exception even for 400 and 500 error code. This patch adds a log message at info level to enable cloud administrator track and audit the alarm notify result. like: Notifying alarm <537944be-1dfd-48fe-b272-2ae0b04e04e1> gets response: 500 Internal Server Error. Change-Id: I56ab6256260697d2e9fe66dfc30e0adbb4024814
This commit is contained in:
parent
c93768cc68
commit
94c4c52012
@ -22,7 +22,7 @@ from oslo_serialization import jsonutils
|
||||
import requests
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from aodh.i18n import _
|
||||
from aodh.i18n import _LI
|
||||
from aodh import notifier
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
@ -63,7 +63,7 @@ class RestAlarmNotifier(notifier.AlarmNotifier):
|
||||
headers['x-openstack-request-id'] = b'req-' + str(
|
||||
uuid.uuid4()).encode('ascii')
|
||||
|
||||
LOG.info(_(
|
||||
LOG.info(_LI(
|
||||
"Notifying alarm %(alarm_name)s %(alarm_id)s with severity"
|
||||
" %(severity)s from %(previous)s to %(current)s with action "
|
||||
"%(action)s because %(reason)s. request-id: %(request_id)s ") %
|
||||
@ -99,4 +99,8 @@ class RestAlarmNotifier(notifier.AlarmNotifier):
|
||||
session = requests.Session()
|
||||
session.mount(action.geturl(),
|
||||
requests.adapters.HTTPAdapter(max_retries=max_retries))
|
||||
session.post(action.geturl(), **kwargs)
|
||||
resp = session.post(action.geturl(), **kwargs)
|
||||
LOG.info(_LI('Notifying alarm <%(id)s> gets response: %(status_code)s '
|
||||
'%(reason)s.'), {'id': alarm_id,
|
||||
'status_code': resp.status_code,
|
||||
'reason': resp.reason})
|
||||
|
@ -105,7 +105,8 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
notification['actions'] = [action]
|
||||
return notification
|
||||
|
||||
def test_notify_alarm_rest_action_ok(self):
|
||||
@mock.patch('aodh.notifier.rest.LOG')
|
||||
def test_notify_alarm_rest_action_ok(self, m_log):
|
||||
action = 'http://host/action'
|
||||
|
||||
with mock.patch.object(requests.Session, 'post') as poster:
|
||||
@ -124,6 +125,11 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
||||
},
|
||||
kwargs['headers'])
|
||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||
self.assertEqual(2, len(m_log.info.call_args_list))
|
||||
expected = mock.call('Notifying alarm <%(id)s> gets response: '
|
||||
'%(status_code)s %(reason)s.',
|
||||
mock.ANY)
|
||||
self.assertEqual(expected, m_log.info.call_args_list[1])
|
||||
|
||||
def test_notify_alarm_rest_action_with_ssl_client_cert(self):
|
||||
action = 'https://host/action'
|
||||
|
Loading…
x
Reference in New Issue
Block a user