alarm formatting changes
Change-Id: I6a454ff75fa4670489b19636961ec6f8f141d9d6
This commit is contained in:
parent
d6a26a626b
commit
aa1c054dc5
@ -1,6 +1,12 @@
|
||||
CHANGES
|
||||
=======
|
||||
|
||||
1.0.5
|
||||
-----
|
||||
* Fixed formatting for alarm-list, alarm-definition-list
|
||||
* Added fields to alarm-list
|
||||
* format output for alarm-history
|
||||
|
||||
1.0.4
|
||||
-----
|
||||
* Alarmed metrics API changes supported.
|
||||
|
49
README.rst
49
README.rst
@ -238,19 +238,19 @@ Note: To see complete usage: 'monasca help' and 'monasca help <command>'
|
||||
|
||||
alarm-definition-create::
|
||||
|
||||
monasca alarm-definition-create --match-by hostname TEST_ALARM_DEF_MATCH_BY "max(cpu.load_avg_1_min) > 0"
|
||||
monasca alarm-definition-create alarmPerHost "max(cpu.load_avg_1_min) > 0" --match-by hostname
|
||||
|
||||
alarm-definition-list::
|
||||
|
||||
+------------------------------+--------------------------------------+------------------------------------------------+---------------+-----------------+
|
||||
| name | id | expression | match_by | actions_enabled |
|
||||
+------------------------------+--------------------------------------+------------------------------------------------+---------------+-----------------+
|
||||
| TEST_ALARM_DEF_MATCH_BY | addfef44-e458-4a54-855b-78908e8cd60c | max(cpu.load_avg_1_min) > 0 | [u'hostname'] | True |
|
||||
+------------------------------+--------------------------------------+------------------------------------------------+---------------+-----------------+
|
||||
+--------------+--------------------------------------+-----------------------------+----------+-----------------+
|
||||
| name | id | expression | match_by | actions_enabled |
|
||||
+--------------+--------------------------------------+-----------------------------+----------+-----------------+
|
||||
| alarmPerHost | 4bf6bfc2-c5ac-4d57-b7db-cf5313b05412 | max(cpu.load_avg_1_min) > 0 | hostname | True |
|
||||
+--------------+--------------------------------------+-----------------------------+----------+-----------------+
|
||||
|
||||
alarm-definition-show::
|
||||
|
||||
monasca alarm-definition-show addfef44-e458-4a54-855b-78908e8cd60c
|
||||
monasca alarm-definition-show 4bf6bfc2-c5ac-4d57-b7db-cf5313b05412
|
||||
+----------------------+----------------------------------------------------------------------------------------------------+
|
||||
| Property | Value |
|
||||
+----------------------+----------------------------------------------------------------------------------------------------+
|
||||
@ -258,12 +258,12 @@ alarm-definition-show::
|
||||
| alarm_actions | [] |
|
||||
| description | "" |
|
||||
| expression | "max(cpu.load_avg_1_min) > 0" |
|
||||
| id | "addfef44-e458-4a54-855b-78908e8cd60c" |
|
||||
| links | href:http://192.168.10.4:8080/v2.0/alarm-definitions/addfef44-e458-4a54-855b-78908e8cd60c,rel:self |
|
||||
| id | "4bf6bfc2-c5ac-4d57-b7db-cf5313b05412" |
|
||||
| links | href:http://192.168.10.4:8080/v2.0/alarm-definitions/4bf6bfc2-c5ac-4d57-b7db-cf5313b05412,rel:self |
|
||||
| match_by | [ |
|
||||
| | "hostname" |
|
||||
| | ] |
|
||||
| name | "TEST_ALARM_DEF_MATCH_BY" |
|
||||
| name | "alarmPerHost" |
|
||||
| ok_actions | [] |
|
||||
| severity | "LOW" |
|
||||
| undetermined_actions | [] |
|
||||
@ -271,21 +271,34 @@ alarm-definition-show::
|
||||
|
||||
alarm-definition-delete::
|
||||
|
||||
monasca alarm-definition-delete addfef44-e458-4a54-855b-78908e8cd60c
|
||||
monasca alarm-definition-delete 4bf6bfc2-c5ac-4d57-b7db-cf5313b05412
|
||||
|
||||
alarm-list::
|
||||
|
||||
monasca alarm-list
|
||||
+--------------------------------------+--------------------------------------+----------------------------------------------------------------------------------------------------------+-------+
|
||||
| id | alarm_definition_id | metrics | state |
|
||||
+--------------------------------------+--------------------------------------+----------------------------------------------------------------------------------------------------------+-------+
|
||||
| 46b8568d-99fc-4801-8a9f-5469b4fefaea | addfef44-e458-4a54-855b-78908e8cd60c | [{u'name': u'cpu.load_avg_1_min', u'dimensions': {u'hostname': u'mini-mon', u'service': u'monitoring'}}] | ALARM |
|
||||
| e9399e5e-cabe-433e-b1d8-56be0bd809a9 | addfef44-e458-4a54-855b-78908e8cd60c | [{u'name': u'cpu.load_avg_1_min', u'dimensions': {u'hostname': u'devstack', u'service': u'monitoring'}}] | ALARM |
|
||||
+--------------------------------------+--------------------------------------+----------------------------------------------------------------------------------------------------------+-------+
|
||||
+--------------------------------------+--------------------------------------+--------------+--------------------+---------------------+----------+-------+
|
||||
| id | alarm_definition_id | alarm_name | metric_name | metric_dimensions | severity | state |
|
||||
+--------------------------------------+--------------------------------------+--------------+--------------------+---------------------+----------+-------+
|
||||
| 35122ab6-3007-41e7-9654-22e97b387f75 | 754276aa-a892-47c0-b74a-9c96ed84a712 | alarmPerHost | cpu.load_avg_1_min | hostname: mini-mon | LOW | ALARM |
|
||||
| | | | | service: monitoring | | |
|
||||
| 54ab81e3-b4d6-4fd0-9fec-707909f2d576 | 754276aa-a892-47c0-b74a-9c96ed84a712 | alarmPerHost | cpu.load_avg_1_min | hostname: devstack | LOW | ALARM |
|
||||
| | | | | service: monitoring | | |
|
||||
+--------------------------------------+--------------------------------------+--------------+--------------------+---------------------+----------+-------+
|
||||
|
||||
alarm-history::
|
||||
|
||||
monasca alarm-history 9d748b72-939b-45e7-a807-c0c5ad88d3e4
|
||||
+--------------------------------------+-----------+--------------+------------------------------------------------------------------------------+-------------+--------------------+---------------------+--------------------------+
|
||||
| alarm_id | new_state | old_state | reason | reason_data | metric_name | metric_dimensions | timestamp |
|
||||
+--------------------------------------+-----------+--------------+------------------------------------------------------------------------------+-------------+--------------------+---------------------+--------------------------+
|
||||
| 9d748b72-939b-45e7-a807-c0c5ad88d3e4 | ALARM | UNDETERMINED | Thresholds were exceeded for the sub-alarms: [max(cpu.load_avg_1_min) > 0.0] | {} | cpu.load_avg_1_min | hostname: mini-mon | 2014-10-14T21:14:11.000Z |
|
||||
| | | | | | | service: monitoring | |
|
||||
+--------------------------------------+-----------+--------------+------------------------------------------------------------------------------+-------------+--------------------+---------------------+--------------------------+
|
||||
|
||||
|
||||
alarm-patch::
|
||||
|
||||
monasca alarm-patch 46b8568d-99fc-4801-8a9f-5469b4fefaea --state OK
|
||||
monasca alarm-patch fda5537b-1550-435f-9d6c-262b7e05065b --state OK
|
||||
|
||||
|
||||
Python API
|
||||
|
@ -232,3 +232,14 @@ def format_dict(dict):
|
||||
d_str = k + ': ' + v
|
||||
dstring_list.append(d_str)
|
||||
return '\n'.join(dstring_list)
|
||||
|
||||
|
||||
def format_list(in_list):
|
||||
string_list = list()
|
||||
for k in in_list:
|
||||
if isinstance(k, unicode):
|
||||
key = k.encode('utf-8')
|
||||
else:
|
||||
key = k
|
||||
string_list.append(key)
|
||||
return '\n'.join(string_list)
|
||||
|
@ -14,6 +14,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
import numbers
|
||||
import time
|
||||
|
||||
from monascaclient.common import utils
|
||||
@ -179,6 +180,37 @@ def format_statistic_value(statistics, columns, stat_type):
|
||||
return '\n'.join(value_list)
|
||||
|
||||
|
||||
def format_metric_name(metrics):
|
||||
# returns newline separated metric names for the column
|
||||
metric_string_list = list()
|
||||
for metric in metrics:
|
||||
metric_name = metric['name']
|
||||
metric_dimensions = metric['dimensions']
|
||||
metric_string_list.append(metric_name)
|
||||
# need to line up with dimensions column
|
||||
rng = len(metric_dimensions)
|
||||
for i in range(rng):
|
||||
if i == rng - 1:
|
||||
# last one
|
||||
break
|
||||
metric_string_list.append(" ")
|
||||
return '\n'.join(metric_string_list)
|
||||
|
||||
|
||||
def format_metric_dimensions(metrics):
|
||||
# returns newline separated dimension key values for the column
|
||||
metric_string_list = list()
|
||||
for metric in metrics:
|
||||
metric_dimensions = metric['dimensions']
|
||||
for k, v in metric_dimensions.items():
|
||||
if isinstance(v, numbers.Number):
|
||||
d_str = k + ': ' + str(v)
|
||||
else:
|
||||
d_str = k + ': ' + v
|
||||
metric_string_list.append(d_str)
|
||||
return '\n'.join(metric_string_list)
|
||||
|
||||
|
||||
@utils.arg('name', metavar='<METRIC_NAME>',
|
||||
help='Name of the metric to list measurements.')
|
||||
@utils.arg('--dimensions', metavar='<KEY1=VALUE1,KEY2=VALUE2...>',
|
||||
@ -575,7 +607,7 @@ def do_alarm_definition_list(mc, args):
|
||||
'name': lambda x: x['name'],
|
||||
'id': lambda x: x['id'],
|
||||
'expression': lambda x: x['expression'],
|
||||
'match_by': lambda x: x['match_by'],
|
||||
'match_by': lambda x: utils.format_list(x['match_by']),
|
||||
'actions_enabled': lambda x: x['actions_enabled'],
|
||||
}
|
||||
if isinstance(alarm, list):
|
||||
@ -783,21 +815,24 @@ def do_alarm_list(mc, args):
|
||||
if args.json:
|
||||
print(utils.json_formatter(alarm))
|
||||
return
|
||||
cols = ['id', 'alarm_definition_id', 'metrics', 'state']
|
||||
cols = ['id', 'alarm_definition_id', 'alarm_name', 'metric_name', 'metric_dimensions', 'severity', 'state']
|
||||
formatters = {
|
||||
'id': lambda x: x['id'],
|
||||
'alarm_definition_id': lambda x: x['alarm_definition_id'],
|
||||
'metrics': lambda x: x['metrics'],
|
||||
'alarm_definition_id': lambda x: x['alarm_definition']['id'],
|
||||
'alarm_name': lambda x: x['alarm_definition']['name'],
|
||||
'metric_name': lambda x: format_metric_name(x['metrics']),
|
||||
'metric_dimensions': lambda x: format_metric_dimensions(x['metrics']),
|
||||
'severity': lambda x: x['alarm_definition']['severity'],
|
||||
'state': lambda x: x['state'],
|
||||
}
|
||||
if isinstance(alarm, list):
|
||||
# print the list
|
||||
utils.print_list(alarm, cols, formatters=formatters, sortby=3)
|
||||
utils.print_list(alarm, cols, formatters=formatters, sortby=2)
|
||||
else:
|
||||
# add the dictionary to a list, so print_list works
|
||||
alarm_list = list()
|
||||
alarm_list.append(alarm)
|
||||
utils.print_list(alarm_list, cols, formatters=formatters, sortby=3)
|
||||
utils.print_list(alarm_list, cols, formatters=formatters, sortby=2)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<ALARM_ID>',
|
||||
@ -819,7 +854,7 @@ def do_alarm_show(mc, args):
|
||||
# print out detail of a single alarm
|
||||
formatters = {
|
||||
'id': utils.json_formatter,
|
||||
'alarm_definition_id': utils.json_formatter,
|
||||
'alarm_definition': utils.json_formatter,
|
||||
'metrics': utils.json_formatter,
|
||||
'state': utils.json_formatter,
|
||||
'links': utils.format_dictlist,
|
||||
@ -891,6 +926,33 @@ def do_alarm_delete(mc, args):
|
||||
print('Successfully deleted alarm')
|
||||
|
||||
|
||||
def output_alarm_history(args, alarm_history):
|
||||
if args.json:
|
||||
print(utils.json_formatter(alarm_history))
|
||||
return
|
||||
# format output
|
||||
cols = ['alarm_id', 'new_state', 'old_state', 'reason',
|
||||
'reason_data', 'metric_name', 'metric_dimensions', 'timestamp']
|
||||
formatters = {
|
||||
'alarm_id': lambda x: x['alarm_id'],
|
||||
'new_state': lambda x: x['new_state'],
|
||||
'old_state': lambda x: x['old_state'],
|
||||
'reason': lambda x: x['reason'],
|
||||
'reason_data': lambda x: x['reason_data'],
|
||||
'metric_name': lambda x: format_metric_name(x['metrics']),
|
||||
'metric_dimensions': lambda x: format_metric_dimensions(x['metrics']),
|
||||
'timestamp': lambda x: x['timestamp'],
|
||||
}
|
||||
if isinstance(alarm_history, list):
|
||||
# print the list
|
||||
utils.print_list(alarm_history, cols, formatters=formatters, sortby=7)
|
||||
else:
|
||||
# add the dictionary to a list, so print_list works
|
||||
alarm_list = list()
|
||||
alarm_list.append(alarm_history)
|
||||
utils.print_list(alarm_list, cols, formatters=formatters, sortby=7)
|
||||
|
||||
|
||||
@utils.arg('id', metavar='<ALARM_ID>',
|
||||
help='The ID of the alarm.')
|
||||
def do_alarm_history(mc, args):
|
||||
@ -904,10 +966,7 @@ def do_alarm_history(mc, args):
|
||||
'HTTPException code=%s message=%s' %
|
||||
(he.code, he.message))
|
||||
else:
|
||||
# if args.json:
|
||||
print(utils.json_formatter(alarm))
|
||||
return
|
||||
# TODO(cindyo) format output
|
||||
output_alarm_history(args, alarm)
|
||||
|
||||
|
||||
@utils.arg('--dimensions', metavar='<KEY1=VALUE1,KEY2=VALUE2...>',
|
||||
@ -937,7 +996,4 @@ def do_alarm_history_list(mc, args):
|
||||
'HTTPException code=%s message=%s' %
|
||||
(he.code, he.message))
|
||||
else:
|
||||
# if args.json:
|
||||
print(utils.json_formatter(alarm))
|
||||
return
|
||||
# TODO(cindyo) format output
|
||||
output_alarm_history(args, alarm)
|
||||
|
Loading…
Reference in New Issue
Block a user