Add the resource to the alarm in the message

that the alarm notifier receive from the graph.
Blueprint : Add to alarm notification the resource

Change-Id: Iaf970a4629ae607e61d577a39b579f04919d6e3e
This commit is contained in:
Eylon Malin 2016-08-18 07:55:54 +00:00
parent 962853469e
commit 7a8df27338
7 changed files with 19 additions and 9 deletions

View File

@ -36,6 +36,8 @@ class VertexProperties(object):
INFO = 'info'
GRAPH_INDEX = 'graph_index'
RAWTEXT = 'rawtext'
RESOURCE_ID = 'resource_id'
RESOURCE = 'resource'
class EdgeProperties(object):

View File

@ -47,7 +47,7 @@ class GraphNotifier(object):
def enabled(self):
return self.oslo_notifier is not None
def notify_when_applicable(self, before, current, is_vertex):
def notify_when_applicable(self, before, current, is_vertex, graph):
"""Callback subscribed to driver.graph updates
:param is_vertex:
@ -56,11 +56,18 @@ class GraphNotifier(object):
:param current: The graph element (vertex or edge) after the
change that happened. Deleted elements should arrive with the
is_deleted property set to True
:param graph: The graph
"""
notification_types = _get_notification_type(before, current, is_vertex)
if not notification_types:
return
# in case the vertex point to some resource add the resource to the
# notification (useful for deduce alarm notifications)
if current.get(VProps.RESOURCE_ID):
current.properties[VProps.RESOURCE] = graph.get_vertex(
current.get(VProps.RESOURCE_ID))
LOG.info('notification_types : %s', str(notification_types))
LOG.info('notification properties : %s', current.properties)

View File

@ -66,7 +66,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
VProps.IS_MARKED_DOWN: event.get(VProps.IS_MARKED_DOWN),
VProps.UPDATE_TIMESTAMP: update_timestamp,
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP],
VProps.IS_PLACEHOLDER: False
VProps.IS_PLACEHOLDER: False,
VProps.RESOURCE_ID: event.get(TFields.TARGET)
}
return Vertex(event[VProps.VITRAGE_ID], properties)
@ -75,7 +76,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
metadata = {
VProps.NAME: event[TFields.ALARM_NAME],
VProps.SEVERITY: event[TFields.SEVERITY],
VProps.STATE: event[VProps.STATE]
VProps.STATE: event[VProps.STATE],
VProps.RESOURCE_ID: event.get(TFields.TARGET)
}
return graph_utils.create_vertex(
self._create_entity_key(event),

View File

@ -69,7 +69,7 @@ class ScenarioEvaluator(object):
def scenario_repo(self, scenario_repo):
self._scenario_repo = scenario_repo
def process_event(self, before, current, is_vertex):
def process_event(self, before, current, is_vertex, *args, **kwargs):
"""Notification of a change in the entity graph.
:param is_vertex:

View File

@ -28,7 +28,7 @@ def _after_func(graph, item, data_before=None):
return
element = graph.get_item(item)
is_vertex = isinstance(element, Vertex)
graph.notifier.notify(data_before, graph.get_item(item), is_vertex)
graph.notifier.notify(data_before, graph.get_item(item), is_vertex, graph)
class Notifier(object):

View File

@ -77,9 +77,7 @@ class AodhNotifier(NotifierBase):
def _alarm_request(data, state):
# TODO(ihefetz) resource id should come from the alarm
affected_resource_id = data.get(VProps.VITRAGE_ID).replace(
'ALARM:vitrage:deduced_vm_alarm:RESOURCE:nova.instance:', '')
affected_resource_id = data.get(VProps.RESOURCE, {}).get(VProps.ID, '')
alarm_name = data.get(VProps.NAME)
aodh_alarm_name = '_'.join([alarm_name, affected_resource_id])
severity = severity_translation.get(data.get(VProps.SEVERITY), 'low')

View File

@ -417,7 +417,8 @@ class GraphTest(GraphTestBase):
def callback(pre_item,
current_item,
is_vertex):
is_vertex,
graph):
LOG.info('called with: pre_event_item ' + str(pre_item) +
' current_item ' + str(current_item))
self.assertIsNotNone(current_item)