From b6454136e8d965c3ed33fcfdc98e36238b74b754 Mon Sep 17 00:00:00 2001 From: Alexey Weyl Date: Tue, 1 Mar 2016 08:08:02 +0200 Subject: [PATCH] state normalization support Change-Id: Ieb9cf923cbe2b8ab737da9e4951b4fd28d26d923 --- doc/source/vitrage-template-format.rst | 4 +-- vitrage/entity_graph/states/alarm_state.py | 8 +++--- vitrage/entity_graph/states/state_manager.py | 27 ++++++++++--------- .../resources/states_plugins/nagios.yaml | 8 +++--- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/doc/source/vitrage-template-format.rst b/doc/source/vitrage-template-format.rst index f37bb1884..1d60dc8ac 100644 --- a/doc/source/vitrage-template-format.rst +++ b/doc/source/vitrage-template-format.rst @@ -134,7 +134,7 @@ The following template demonstrates Example 2: Deduced state based on alarm --------------------------------------- -The following template will change the state of a resource to "ERROR" if there is any alarm of severity "HIGH" on it. Also note that entity ids can be strings as well. +The following template will change the state of a resource to "ERROR" if there is any alarm of severity "CRITICAL" on it. Also note that entity ids can be strings as well. :: @@ -147,7 +147,7 @@ The following template will change the state of a resource to "ERROR" if there i template_id: a_resource # entity ids are any string - entity: category: ALARM - severity: HIGH + severity: CRITICAL template_id: high_alarm # entity ids are any string relationships: - relationship: diff --git a/vitrage/entity_graph/states/alarm_state.py b/vitrage/entity_graph/states/alarm_state.py index 34fcba7d2..6db12c340 100644 --- a/vitrage/entity_graph/states/alarm_state.py +++ b/vitrage/entity_graph/states/alarm_state.py @@ -14,8 +14,8 @@ class AlarmState(object): - HIGH = 'HIGH' - MEDIUM = 'MEDIUM' - LOW = 'LOW' - OK = 'OK' + CRITICAL = 'CRITICAL' + SEVER = 'SEVER' + WARNING = 'WARNING' + DISABLED = 'DISABLED' UNKNOWN = 'UNKNOWN' diff --git a/vitrage/entity_graph/states/state_manager.py b/vitrage/entity_graph/states/state_manager.py index 117367ba3..d55592849 100644 --- a/vitrage/entity_graph/states/state_manager.py +++ b/vitrage/entity_graph/states/state_manager.py @@ -50,21 +50,24 @@ class StateManager(object): def aggregated_state(self, state1, state2, plugin_name, is_normalized=False): - upper_state1 = state1 if not state1 else state1.upper() - upper_state2 = state2 if not state2 else state2.upper() + if plugin_name in self.states_plugins: + upper_state1 = state1 if not state1 else state1.upper() + upper_state2 = state2 if not state2 else state2.upper() - normalized_state1 = upper_state1.upper() if is_normalized else \ - self.normalize_state(plugin_name, upper_state1) - normalized_state2 = upper_state2.upper() if is_normalized else \ - self.normalize_state(plugin_name, upper_state2) + normalized_state1 = upper_state1.upper() if is_normalized else \ + self.normalize_state(plugin_name, upper_state1) + normalized_state2 = upper_state2.upper() if is_normalized else \ + self.normalize_state(plugin_name, upper_state2) - priority_state1 = self.state_priority(plugin_name, - normalized_state1) - priority_state2 = self.state_priority(plugin_name, - normalized_state2) + priority_state1 = self.state_priority(plugin_name, + normalized_state1) + priority_state2 = self.state_priority(plugin_name, + normalized_state2) - return normalized_state1 if priority_state1 > priority_state2 \ - else normalized_state2 + return normalized_state1 if priority_state1 > priority_state2 \ + else normalized_state2 + else: + return ResourceState.UNDEFINED def _load_state_configurations(self): states_plugins = {} diff --git a/vitrage/tests/resources/states_plugins/nagios.yaml b/vitrage/tests/resources/states_plugins/nagios.yaml index fda6b7075..2f7dd529d 100644 --- a/vitrage/tests/resources/states_plugins/nagios.yaml +++ b/vitrage/tests/resources/states_plugins/nagios.yaml @@ -6,20 +6,20 @@ states: original states: - name: UNKNOWN - normalized state: - name: HIGH + name: CRITICAL priority: 40 original states: - name: CRITITCAL - name: DOWN - normalized state: - name: MEDIUM + name: SEVER priority: 30 original states: - - name: WARNING - normalized state: - name: LOW + name: WARNING priority: 20 original states: + - name: WARNING - normalized state: name: OK priority: 10