Add severity field to alarm CLI

Change-Id: I699bea4859d4f0a5832ced5ba74ba7fb26c122ef
Partially-Implements: blueprint ceilometer-alarm-level
This commit is contained in:
Pradeep Kilambi
2015-01-26 09:53:13 -08:00
parent 4b6dc5ccfc
commit 945f9a392a
4 changed files with 51 additions and 37 deletions

View File

@@ -28,6 +28,7 @@ AN_ALARM = {u'alarm_actions': [u'http://site:8000/alarm'],
u'ok_actions': [u'http://site:8000/ok'],
u'description': u'An alarm',
u'type': u'threshold',
u'severity': 'low',
u'threshold_rule': {
u'meter_name': u'storage.objects',
u'query': [{u'field': u'key_name',
@@ -107,6 +108,7 @@ AN_LEGACY_ALARM = {u'alarm_actions': [u'http://site:8000/alarm'],
u'period': 240.0,
u'alarm_id': u'alarm-id',
u'state': u'ok',
u'severity': u'low',
u'insufficient_data_actions': [u'http://site:8000/nodata'],
u'statistic': u'avg',
u'threshold': 200.0,

View File

@@ -173,6 +173,7 @@ class ShellAlarmCommandTest(utils.BaseTestCase):
"timezone": ""}],
"alarm_id": ALARM_ID,
"state": "insufficient data",
"severity": "low",
"insufficient_data_actions": [],
"repeat_actions": True,
"user_id": "528d9b68fa774689834b5c04b4564f8a",
@@ -514,6 +515,7 @@ class ShellQueryAlarmsCommandTest(utils.BaseTestCase):
"project_id": "c96c887c216949acbdfbd8b494863567",
"repeat_actions": False,
"state": "ok",
"severity": "critical",
"state_timestamp": "2014-02-20T10:37:15.589860",
"threshold_rule": None,
"timestamp": "2014-02-20T10:37:15.589856",
@@ -544,21 +546,25 @@ class ShellQueryAlarmsCommandTest(utils.BaseTestCase):
ceilometer_shell.do_query_alarms(self.cc, self.args)
self.assertEqual('''\
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+--------------------------------+
| Alarm ID | Name | State | Enabled \
| Continuous | Alarm condition \
| Time constraints |
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+--------------------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok | True \
| False | combinated states (OR) of 739e99cb-c2ec-4718-b900-332502355f3\
8, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 | test at 0 23 * * * for 10800s |
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+--------------------------------+
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+-------------------------------\
-+
| Alarm ID | Name | State | Severity \
| Enabled | Continuous | Alarm condition \
| Time constraints \
|
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+--------------------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok | critical \
| True | False | combinated states (OR) of \
739e99cb-c2ec-4718-b900-332502355f38, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 |\
test at 0 23 * * * for 10800s |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------------------\
--+
''', sys.stdout.getvalue())
@mock.patch('sys.stdout', new=six.StringIO())
@@ -577,21 +583,22 @@ class ShellQueryAlarmsCommandTest(utils.BaseTestCase):
ceilometer_shell.do_query_alarms(self.cc, self.args)
self.assertEqual('''\
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+------------------+
| Alarm ID | Name | State | Enabled \
| Continuous | Alarm condition \
| Time constraints |
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok | True \
| False | combinated states (OR) of 739e99cb-c2ec-4718-b900-332502355f3\
8, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 | None |
+--------------------------------------+------------------+-------+---------\
+------------+--------------------------------------------------------------\
----------------------------------------+------------------+
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------+
| Alarm ID | Name | State | Severity \
| Enabled | Continuous | Alarm condition \
| Time constraints |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------+
| 768ff714-8cfb-4db9-9753-d484cb33a1cc | SwiftObjectAlarm | ok | critical \
| True | False | combinated states (OR) of \
739e99cb-c2ec-4718-b900-332502355f38, 153462d0-a9b8-4b5b-8175-9e4b05e9b856 \
| None |
+--------------------------------------+------------------+-------+----------+\
---------+------------+-------------------------------------------------------\
-----------------------------------------------+------------------+
''', sys.stdout.getvalue())

View File

@@ -26,6 +26,7 @@ UPDATABLE_ATTRIBUTES = [
'description',
'type',
'state',
'severity',
'enabled',
'alarm_actions',
'ok_actions',

View File

@@ -31,6 +31,7 @@ from ceilometerclient.v2 import options
ALARM_STATES = ['ok', 'alarm', 'insufficient data']
ALARM_SEVERITY = ['low', 'moderate', 'critical']
ALARM_OPERATORS = ['lt', 'le', 'eq', 'ne', 'ge', 'gt']
ALARM_COMBINATION_OPERATORS = ['and', 'or']
STATISTICS = ['max', 'min', 'avg', 'sum', 'count']
@@ -207,10 +208,10 @@ def do_meter_list(cc, args={}):
def _display_alarm_list(alarms, sortby=None):
# omit action initially to keep output width sane
# (can switch over to vertical formatting when available from CLIFF)
field_labels = ['Alarm ID', 'Name', 'State', 'Enabled', 'Continuous',
'Alarm condition', 'Time constraints']
fields = ['alarm_id', 'name', 'state', 'enabled', 'repeat_actions',
'rule', 'time_constraints']
field_labels = ['Alarm ID', 'Name', 'State', 'Severity', 'Enabled',
'Continuous', 'Alarm condition', 'Time constraints']
fields = ['alarm_id', 'name', 'state', 'severity', 'enabled',
'repeat_actions', 'rule', 'time_constraints']
utils.print_list(
alarms, fields, field_labels,
formatters={'rule': alarm_rule_formatter,
@@ -331,9 +332,9 @@ def time_constraints_formatter_full(alarm):
def _display_alarm(alarm):
fields = ['name', 'description', 'type',
'state', 'enabled', 'alarm_id', 'user_id', 'project_id',
'alarm_actions', 'ok_actions', 'insufficient_data_actions',
'repeat_actions']
'state', 'severity', 'enabled', 'alarm_id', 'user_id',
'project_id', 'alarm_actions', 'ok_actions',
'insufficient_data_actions', 'repeat_actions']
data = dict([(f, getattr(alarm, f, '')) for f in fields])
data.update(alarm.rule)
if alarm.type == 'threshold':
@@ -371,6 +372,9 @@ def common_alarm_arguments(create=False):
help='Free text description of the alarm.')
@utils.arg('--state', metavar='<STATE>',
help='State of the alarm, one of: ' + str(ALARM_STATES))
@utils.arg('--severity', metavar='<SEVERITY>',
help='Severity of the alarm, one of: '
+ str(ALARM_SEVERITY))
@utils.arg('--enabled', type=strutils.bool_from_string,
metavar='{True|False}',
help='True if alarm evaluation/actioning is enabled.')