From 945f9a392a725c2cae494dcb36cd77d75225718a Mon Sep 17 00:00:00 2001 From: Pradeep Kilambi Date: Mon, 26 Jan 2015 09:53:13 -0800 Subject: Add severity field to alarm CLI Change-Id: I699bea4859d4f0a5832ced5ba74ba7fb26c122ef Partially-Implements: blueprint ceilometer-alarm-level --- ceilometerclient/tests/v2/test_alarms.py | 2 + ceilometerclient/tests/v2/test_shell.py | 67 ++++++++++++++++++-------------- ceilometerclient/v2/alarms.py | 1 + ceilometerclient/v2/shell.py | 18 +++++---- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/ceilometerclient/tests/v2/test_alarms.py b/ceilometerclient/tests/v2/test_alarms.py index 41246d1..4239d2f 100644 --- a/ceilometerclient/tests/v2/test_alarms.py +++ b/ceilometerclient/tests/v2/test_alarms.py @@ -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, diff --git a/ceilometerclient/tests/v2/test_shell.py b/ceilometerclient/tests/v2/test_shell.py index d14c8e5..65c8bb1 100644 --- a/ceilometerclient/tests/v2/test_shell.py +++ b/ceilometerclient/tests/v2/test_shell.py @@ -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()) diff --git a/ceilometerclient/v2/alarms.py b/ceilometerclient/v2/alarms.py index 8eefa9b..238fe41 100644 --- a/ceilometerclient/v2/alarms.py +++ b/ceilometerclient/v2/alarms.py @@ -26,6 +26,7 @@ UPDATABLE_ATTRIBUTES = [ 'description', 'type', 'state', + 'severity', 'enabled', 'alarm_actions', 'ok_actions', diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 95a137f..7cab85e 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -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='', help='State of the alarm, one of: ' + str(ALARM_STATES)) + @utils.arg('--severity', metavar='', + 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.') -- cgit v1.2.1