Template v3 causing alarm implemented.

Adding causing_alarm property to raise_alarm action.
This field contains an identifier of the causing alarm, during loading,
 it is replaced by get_attr(identifier, vitrage_id).
The evaluator transformer handles this field by adding a neighbor to the alarm.

Story: 2004871
Task: 29130
Depends-On: https://review.openstack.org/#/c/637526/
Change-Id: I66527d559a09b02801fab6f1373f10ee9ba9a77c
This commit is contained in:
Idan Hefetz 2019-02-18 10:19:06 +00:00
parent c10cb80b6e
commit e72846df09
4 changed files with 66 additions and 4 deletions

View File

@ -123,6 +123,7 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
return [Neighbor(None, relation_edge)]
if event_type == ADD_VERTEX:
result = []
relation_edge = graph_utils.create_edge(
source_id=TransformerBase.uuid_from_deprecated_vitrage_id(
@ -140,8 +141,25 @@ class EvaluatorEventTransformer(transformer_base.TransformerBase):
VProps.VITRAGE_TYPE: event.get(VProps.VITRAGE_RESOURCE_TYPE),
VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE,
}
neighbor = Vertex(event[TFields.TARGET], neighbor_props)
return [Neighbor(neighbor, relation_edge)]
result.append(Neighbor(
Vertex(event[TFields.TARGET], neighbor_props), relation_edge))
if event.get(TFields.CAUSING_ALARM):
relation_edge = graph_utils.create_edge(
source_id=event[TFields.CAUSING_ALARM],
target_id=TransformerBase.uuid_from_deprecated_vitrage_id(
self._create_entity_key(event)),
relationship_type=EdgeLabel.CAUSES,
update_timestamp=timestamp)
result.append(
Neighbor(Vertex(
event[TFields.CAUSING_ALARM],
{
VProps.UPDATE_TIMESTAMP: timestamp,
VProps.VITRAGE_IS_PLACEHOLDER: True,
}),
relation_edge)
)
return result
return []

View File

@ -0,0 +1,41 @@
# Copyright 2019 - Nokia
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from vitrage.evaluator.template_fields import TemplateFields as TField
from vitrage.evaluator.template_loading.v3.action_loader import ActionLoader
class RaiseAlarmLoader(ActionLoader):
def load(self, action_id, default_target, action_dict, action_type):
"""V3 template action raise_alarm to ActionSpecs transformation
causing_alarm is replaced with a function, to get the vertex id.
Example:
causing_alarm: zabbix_alarm
Replaced with:
causing_alarm: get_attr(zabbix_alarm, vitrage_id)
:param action_id: Unique action identifier
:param default_target: Is taken from the condition,
it is used when the action doesn't define a target
:param action_dict: Action section taken from the template.
:param action_type: example: set_state/raise_alarm/etc..
:rtype: ActionSpecs
"""
if TField.CAUSING_ALARM in action_dict:
action_dict[TField.CAUSING_ALARM] = \
'get_attr(%s, vitrage_id)' % action_dict[TField.CAUSING_ALARM]
return super(RaiseAlarmLoader, self).load(
action_id, default_target, action_dict, action_type)

View File

@ -28,6 +28,8 @@ from vitrage.evaluator.template_loading.v1.execute_mistral_loader import \
ExecuteMistralLoader
from vitrage.evaluator.template_loading.v3.action_loader import ActionLoader \
as V3ActionLoader
from vitrage.evaluator.template_loading.v3.raise_alarm_loader import \
RaiseAlarmLoader as V3RaiseAlarmLoader
from vitrage.evaluator.template_schema_factory import TemplateSchemaFactory
from vitrage.evaluator.template_validation.content.\
template_content_validator_v3 import ContentValidator as V3ContentValidator
@ -121,7 +123,7 @@ class TemplateSchema3(object):
ActionType.ADD_CAUSAL_RELATIONSHIP: V3ActionLoader(),
ActionType.EXECUTE_MISTRAL: V3ActionLoader(),
ActionType.MARK_DOWN: V3ActionLoader(),
ActionType.RAISE_ALARM: V3ActionLoader(),
ActionType.RAISE_ALARM: V3RaiseAlarmLoader(),
ActionType.SET_STATE: V3ActionLoader(),
}

View File

@ -247,7 +247,8 @@ class TemplateLoaderV3Test(BaseTest, TestConfiguration):
{
'severity': 'WARNING',
'alarm_name': 'instance is down',
'causing_alarm': 'host_ssh_alarm',
'causing_alarm':
'get_attr(host_ssh_alarm, vitrage_id)',
}),
ActionSpecs(
'valid actions-scenario2-action1',