Merge "add "severity" value for alarm_history"
This commit is contained in:
commit
5fa2f3fc3a
@ -94,6 +94,7 @@ class Evaluator(object):
|
||||
user_id, project_id = self.ks_client.user_id, self.ks_client.project_id
|
||||
on_behalf_of = alarm.project_id
|
||||
now = timeutils.utcnow()
|
||||
severity = alarm.severity
|
||||
payload = dict(event_id=uuidutils.generate_uuid(),
|
||||
alarm_id=alarm.alarm_id,
|
||||
type=type,
|
||||
@ -101,7 +102,8 @@ class Evaluator(object):
|
||||
user_id=user_id,
|
||||
project_id=project_id,
|
||||
on_behalf_of=on_behalf_of,
|
||||
timestamp=now)
|
||||
timestamp=now,
|
||||
severity=severity)
|
||||
|
||||
try:
|
||||
self._storage_conn.record_alarm_change(payload)
|
||||
|
@ -297,7 +297,8 @@ class Connection(base.Connection):
|
||||
user_id=row.user_id,
|
||||
project_id=row.project_id,
|
||||
on_behalf_of=row.on_behalf_of,
|
||||
timestamp=row.timestamp)
|
||||
timestamp=row.timestamp,
|
||||
severity=row.severity)
|
||||
|
||||
def query_alarms(self, filter_expr=None, orderby=None, limit=None):
|
||||
"""Yields a lists of alarms that match filter."""
|
||||
|
@ -75,7 +75,8 @@ class AlarmTestBase(DBTestBase):
|
||||
aggregation_method='count',
|
||||
evaluation_periods=1,
|
||||
granularity=60,
|
||||
metrics=METRIC_IDS)
|
||||
metrics=METRIC_IDS),
|
||||
severity='low'
|
||||
),
|
||||
alarm_models.Alarm(alarm_id='0r4ng3',
|
||||
enabled=True,
|
||||
@ -99,7 +100,8 @@ class AlarmTestBase(DBTestBase):
|
||||
aggregation_method='avg',
|
||||
evaluation_periods=1,
|
||||
granularity=60,
|
||||
metrics=METRIC_IDS)
|
||||
metrics=METRIC_IDS),
|
||||
severity='low'
|
||||
),
|
||||
alarm_models.Alarm(alarm_id='y3ll0w',
|
||||
enabled=False,
|
||||
@ -123,7 +125,8 @@ class AlarmTestBase(DBTestBase):
|
||||
aggregation_method='min',
|
||||
evaluation_periods=1,
|
||||
granularity=60,
|
||||
metrics=METRIC_IDS)
|
||||
metrics=METRIC_IDS),
|
||||
severity='low'
|
||||
)]
|
||||
|
||||
for a in alarms:
|
||||
@ -302,6 +305,27 @@ class AlarmHistoryTest(AlarmTestBase):
|
||||
history = list(self.alarm_conn.query_alarm_history())
|
||||
self.assertEqual(0, len(history))
|
||||
|
||||
def test_record_severity_when_alarm_change(self):
|
||||
alarm = list(self.alarm_conn.get_alarms(name='orange-alert'))[0]
|
||||
severity = "low"
|
||||
alarm_change = {
|
||||
"event_id": "3d22800c-a3ca-4991-b34b-d97efb6047d9",
|
||||
"alarm_id": alarm.alarm_id,
|
||||
"type": alarm_models.AlarmChange.STATE_TRANSITION,
|
||||
"detail": "detail %s" % alarm.name,
|
||||
"user_id": alarm.user_id,
|
||||
"project_id": alarm.project_id,
|
||||
"on_behalf_of": alarm.project_id,
|
||||
"severity": severity,
|
||||
"timestamp": datetime.datetime(2014, 4, 7, 7, 34)
|
||||
}
|
||||
self.alarm_conn.record_alarm_change(alarm_change=alarm_change)
|
||||
filter_expr = {"=": {"severity": "low"}}
|
||||
history = list(self.alarm_conn.query_alarm_history(
|
||||
filter_expr=filter_expr))
|
||||
self.assertEqual(1, len(history))
|
||||
self.assertEqual("low", history[0].severity)
|
||||
|
||||
|
||||
class ComplexAlarmQueryTest(AlarmTestBase):
|
||||
|
||||
|
@ -56,6 +56,7 @@ class TestGnocchiEvaluatorBase(base.TestEvaluatorBase):
|
||||
alarm_actions=[],
|
||||
repeat_actions=False,
|
||||
time_constraints=[],
|
||||
severity='low',
|
||||
rule=dict(
|
||||
comparison_operator='gt',
|
||||
threshold=80.0,
|
||||
@ -235,6 +236,7 @@ class TestGnocchiResourceThresholdEvaluate(TestGnocchiEvaluatorBase):
|
||||
detail = json.dumps({'state': alarm.state,
|
||||
'transition_reason': reasons[num]})
|
||||
on_behalf_of = alarm.project_id
|
||||
severity = alarm.severity
|
||||
payload = dict(
|
||||
event_id='fake_event_id_%s' % num,
|
||||
alarm_id=alarm.alarm_id,
|
||||
@ -243,7 +245,8 @@ class TestGnocchiResourceThresholdEvaluate(TestGnocchiEvaluatorBase):
|
||||
user_id='fake_user_id',
|
||||
project_id='fake_project_id',
|
||||
on_behalf_of=on_behalf_of,
|
||||
timestamp=datetime.datetime(2015, 7, 26, 3, 33, 21, 876795))
|
||||
timestamp=datetime.datetime(2015, 7, 26, 3, 33, 21, 876795),
|
||||
severity=severity)
|
||||
payloads.append(payload)
|
||||
return payloads
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user