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:
parent
962853469e
commit
7a8df27338
@ -36,6 +36,8 @@ class VertexProperties(object):
|
|||||||
INFO = 'info'
|
INFO = 'info'
|
||||||
GRAPH_INDEX = 'graph_index'
|
GRAPH_INDEX = 'graph_index'
|
||||||
RAWTEXT = 'rawtext'
|
RAWTEXT = 'rawtext'
|
||||||
|
RESOURCE_ID = 'resource_id'
|
||||||
|
RESOURCE = 'resource'
|
||||||
|
|
||||||
|
|
||||||
class EdgeProperties(object):
|
class EdgeProperties(object):
|
||||||
|
@ -47,7 +47,7 @@ class GraphNotifier(object):
|
|||||||
def enabled(self):
|
def enabled(self):
|
||||||
return self.oslo_notifier is not None
|
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
|
"""Callback subscribed to driver.graph updates
|
||||||
|
|
||||||
:param is_vertex:
|
:param is_vertex:
|
||||||
@ -56,11 +56,18 @@ class GraphNotifier(object):
|
|||||||
:param current: The graph element (vertex or edge) after the
|
:param current: The graph element (vertex or edge) after the
|
||||||
change that happened. Deleted elements should arrive with the
|
change that happened. Deleted elements should arrive with the
|
||||||
is_deleted property set to True
|
is_deleted property set to True
|
||||||
|
:param graph: The graph
|
||||||
"""
|
"""
|
||||||
notification_types = _get_notification_type(before, current, is_vertex)
|
notification_types = _get_notification_type(before, current, is_vertex)
|
||||||
if not notification_types:
|
if not notification_types:
|
||||||
return
|
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_types : %s', str(notification_types))
|
||||||
LOG.info('notification properties : %s', current.properties)
|
LOG.info('notification properties : %s', current.properties)
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
|||||||
VProps.IS_MARKED_DOWN: event.get(VProps.IS_MARKED_DOWN),
|
VProps.IS_MARKED_DOWN: event.get(VProps.IS_MARKED_DOWN),
|
||||||
VProps.UPDATE_TIMESTAMP: update_timestamp,
|
VProps.UPDATE_TIMESTAMP: update_timestamp,
|
||||||
VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_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)
|
return Vertex(event[VProps.VITRAGE_ID], properties)
|
||||||
|
|
||||||
@ -75,7 +76,8 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
|
|||||||
metadata = {
|
metadata = {
|
||||||
VProps.NAME: event[TFields.ALARM_NAME],
|
VProps.NAME: event[TFields.ALARM_NAME],
|
||||||
VProps.SEVERITY: event[TFields.SEVERITY],
|
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(
|
return graph_utils.create_vertex(
|
||||||
self._create_entity_key(event),
|
self._create_entity_key(event),
|
||||||
|
@ -69,7 +69,7 @@ class ScenarioEvaluator(object):
|
|||||||
def scenario_repo(self, scenario_repo):
|
def scenario_repo(self, scenario_repo):
|
||||||
self._scenario_repo = 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.
|
"""Notification of a change in the entity graph.
|
||||||
|
|
||||||
:param is_vertex:
|
:param is_vertex:
|
||||||
|
@ -28,7 +28,7 @@ def _after_func(graph, item, data_before=None):
|
|||||||
return
|
return
|
||||||
element = graph.get_item(item)
|
element = graph.get_item(item)
|
||||||
is_vertex = isinstance(element, Vertex)
|
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):
|
class Notifier(object):
|
||||||
|
@ -77,9 +77,7 @@ class AodhNotifier(NotifierBase):
|
|||||||
|
|
||||||
|
|
||||||
def _alarm_request(data, state):
|
def _alarm_request(data, state):
|
||||||
# TODO(ihefetz) resource id should come from the alarm
|
affected_resource_id = data.get(VProps.RESOURCE, {}).get(VProps.ID, '')
|
||||||
affected_resource_id = data.get(VProps.VITRAGE_ID).replace(
|
|
||||||
'ALARM:vitrage:deduced_vm_alarm:RESOURCE:nova.instance:', '')
|
|
||||||
alarm_name = data.get(VProps.NAME)
|
alarm_name = data.get(VProps.NAME)
|
||||||
aodh_alarm_name = '_'.join([alarm_name, affected_resource_id])
|
aodh_alarm_name = '_'.join([alarm_name, affected_resource_id])
|
||||||
severity = severity_translation.get(data.get(VProps.SEVERITY), 'low')
|
severity = severity_translation.get(data.get(VProps.SEVERITY), 'low')
|
||||||
|
@ -417,7 +417,8 @@ class GraphTest(GraphTestBase):
|
|||||||
|
|
||||||
def callback(pre_item,
|
def callback(pre_item,
|
||||||
current_item,
|
current_item,
|
||||||
is_vertex):
|
is_vertex,
|
||||||
|
graph):
|
||||||
LOG.info('called with: pre_event_item ' + str(pre_item) +
|
LOG.info('called with: pre_event_item ' + str(pre_item) +
|
||||||
' current_item ' + str(current_item))
|
' current_item ' + str(current_item))
|
||||||
self.assertIsNotNone(current_item)
|
self.assertIsNotNone(current_item)
|
||||||
|
Loading…
Reference in New Issue
Block a user