state normalization support

Change-Id: Ieb9cf923cbe2b8ab737da9e4951b4fd28d26d923
This commit is contained in:
Alexey Weyl 2016-03-01 08:08:02 +02:00
parent b56311901a
commit b6454136e8
4 changed files with 25 additions and 22 deletions

View File

@ -134,7 +134,7 @@ The following template demonstrates
Example 2: Deduced state based on alarm 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 template_id: a_resource # entity ids are any string
- entity: - entity:
category: ALARM category: ALARM
severity: HIGH severity: CRITICAL
template_id: high_alarm # entity ids are any string template_id: high_alarm # entity ids are any string
relationships: relationships:
- relationship: - relationship:

View File

@ -14,8 +14,8 @@
class AlarmState(object): class AlarmState(object):
HIGH = 'HIGH' CRITICAL = 'CRITICAL'
MEDIUM = 'MEDIUM' SEVER = 'SEVER'
LOW = 'LOW' WARNING = 'WARNING'
OK = 'OK' DISABLED = 'DISABLED'
UNKNOWN = 'UNKNOWN' UNKNOWN = 'UNKNOWN'

View File

@ -50,6 +50,7 @@ class StateManager(object):
def aggregated_state(self, state1, state2, plugin_name, def aggregated_state(self, state1, state2, plugin_name,
is_normalized=False): is_normalized=False):
if plugin_name in self.states_plugins:
upper_state1 = state1 if not state1 else state1.upper() upper_state1 = state1 if not state1 else state1.upper()
upper_state2 = state2 if not state2 else state2.upper() upper_state2 = state2 if not state2 else state2.upper()
@ -65,6 +66,8 @@ class StateManager(object):
return normalized_state1 if priority_state1 > priority_state2 \ return normalized_state1 if priority_state1 > priority_state2 \
else normalized_state2 else normalized_state2
else:
return ResourceState.UNDEFINED
def _load_state_configurations(self): def _load_state_configurations(self):
states_plugins = {} states_plugins = {}

View File

@ -6,20 +6,20 @@ states:
original states: original states:
- name: UNKNOWN - name: UNKNOWN
- normalized state: - normalized state:
name: HIGH name: CRITICAL
priority: 40 priority: 40
original states: original states:
- name: CRITITCAL - name: CRITITCAL
- name: DOWN - name: DOWN
- normalized state: - normalized state:
name: MEDIUM name: SEVER
priority: 30 priority: 30
original states: original states:
- name: WARNING
- normalized state: - normalized state:
name: LOW name: WARNING
priority: 20 priority: 20
original states: original states:
- name: WARNING
- normalized state: - normalized state:
name: OK name: OK
priority: 10 priority: 10