Skip to content

Commit

Permalink
Merge "Add support for <, > and range operators in alarm configuratio…
Browse files Browse the repository at this point in the history
…n" into R3.1
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Oct 25, 2016
2 parents 63486d7 + 723dd4f commit 75e65a2
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/config/api-server/vnc_cfg_types.py
Expand Up @@ -2139,6 +2139,20 @@ def _check_alarm_rules(cls, alarm_rules):
except ValueError:
return (False, (400, 'Invalid json_value %s '
'specified in alarm_rules' % (json_val)))
if and_cond['operation'] == 'range':
if json_val is None:
return (False, (400, 'json_value not specified'
' for "range" operation'))
val = json.loads(json_val)
if not (isinstance(val, list) and
len(val) == 2 and
isinstance(val[0], (int, long, float)) and
isinstance(val[1], (int, long, float)) and
val[0] < val[1]):
return (False, (400, 'Invalid json_value %s '
'for "range" operation. json_value should '
'be specified as "[x, y]", where x < y' %
(json_val)))
else:
return (False, (400, 'operand2 should have '
'"uve_attribute" or "json_value"'))
Expand Down
6 changes: 6 additions & 0 deletions src/opserver/alarmgen.py
Expand Up @@ -355,8 +355,12 @@ def _compare_operand_vals(self, val1, val2, operation):
return val1 == val2
elif operation == '!=':
return val1 != val2
elif operation == '<':
return val1 < val2
elif operation == '<=':
return val1 <= val2
elif operation == '>':
return val1 > val2
elif operation == '>=':
return val1 >= val2
elif operation == 'in':
Expand All @@ -367,6 +371,8 @@ def _compare_operand_vals(self, val1, val2, operation):
if not isinstance(val2, list):
return True
return val1 not in val2
elif operation == 'range':
return val2[0] <= val1 <= val2[1]
elif operation == 'size==':
if not isinstance(val1, list):
return False
Expand Down
156 changes: 156 additions & 0 deletions src/opserver/test/test_alarm.py
Expand Up @@ -1145,6 +1145,51 @@ def test_05_evaluate_uve_for_alarms(self):
}
)

alarm_config13 = self.get_alarm_config_object(
{
'name': 'alarm13',
'uve_keys': ['key13'],
'alarm_severity': AlarmBase.ALARM_MAJOR,
'alarm_rules': {
'or_list': [
{
'and_list': [
{
'operand1': 'A.B.C',
'operation': '<',
'operand2': {
'uve_attribute': 'A.B.D'
}
},
{
'operand1': 'A.B.C',
'operation': '>',
'operand2': {
'json_value': '100'
}
}
]
},
{
'and_list': [
{
'operand1': 'A.B.C',
'operation': 'range',
'operand2': {
'json_value': '[500, 1000]'
}
}
]
}
]
},
'kwargs': {
'parent_type': 'global-system-config',
'fq_name': ['global-syscfg-default', 'alarm13']
}
}
)

tests = [
TestCase(name='operand1 not present/null in UVE',
input=TestInput(alarm_cfg=alarm_config1,
Expand Down Expand Up @@ -2421,6 +2466,117 @@ def test_05_evaluate_uve_for_alarms(self):
]
}
])
),
TestCase(
name='Test operation < and > - no condition match',
input=TestInput(alarm_cfg=alarm_config13,
uve_key='table13:host13',
uve={
'A': {
'B': {
'C': 5,
'D': 5
}
}
}
),
output=TestOutput(or_list=None)
),
TestCase(
name='Test operation < and > - condition match',
input=TestInput(alarm_cfg=alarm_config13,
uve_key='table13:host13',
uve={
'A': {
'B': {
'C': 150,
'D': 200
}
}
}
),
output=TestOutput(or_list=[
{
'and_list': [
{
'condition': {
'operand1': 'A.B.C',
'operand2': {
'uve_attribute': 'A.B.D'
},
'operation': '<'
},
'match': [
{
'json_operand1_val': '150',
'json_operand2_val': '200'
}
]
},
{
'condition': {
'operand1': 'A.B.C',
'operand2': {
'json_value': '100'
},
'operation': '>'
},
'match': [
{
'json_operand1_val': '150'
}
]
}
]
}
])
),
TestCase(
name='Test range operation - no condition match',
input=TestInput(alarm_cfg=alarm_config13,
uve_key='table13:host13',
uve={
'A': {
'B': {
'C': 1500,
}
}
}
),
output=TestOutput(or_list=None)
),
TestCase(
name='Test range operation - condition match',
input=TestInput(alarm_cfg=alarm_config13,
uve_key='table13:host13',
uve={
'A': {
'B': {
'C': 500,
}
}
}
),
output=TestOutput(or_list=[
{
'and_list': [
{
'condition': {
'operand1': 'A.B.C',
'operand2': {
'json_value': '[500, 1000]'
},
'operation': 'range'
},
'match': [
{
'json_operand1_val': '500'
}
]
}
]
}
])
)
]

Expand Down
3 changes: 3 additions & 0 deletions src/schema/alarm.xsd
Expand Up @@ -8,10 +8,13 @@
<xsd:restriction base="xsd:string">
<xsd:enumeration value="=="/>
<xsd:enumeration value="!="/>
<xsd:enumeration value="&lt;"/>
<xsd:enumeration value="&lt;="/>
<xsd:enumeration value="&gt;"/>
<xsd:enumeration value="&gt;="/>
<xsd:enumeration value="in"/>
<xsd:enumeration value="not in"/>
<xsd:enumeration value="range"/>
<xsd:enumeration value="size=="/>
<xsd:enumeration value="size!="/>
</xsd:restriction>
Expand Down

0 comments on commit 75e65a2

Please sign in to comment.