Added severity to alarm commands, Added alarm-list by state option

This commit is contained in:
cindy oneill 2014-05-23 11:50:27 -06:00
parent 5536795046
commit 3808b9b70e
4 changed files with 66 additions and 7 deletions

View File

@ -14,13 +14,14 @@ Ubuntu Install
--------------
Requires:
- pip - version >= 1.4. python get-pip.py
- git - sudo apt-get install git-core
Install Steps:
- git clone or copy the python-monclient distribution to the server
- cd python-monclient
Install It:
- sudo pip install python-monclient
Alternative Manual Install Steps:
- cd to your python-monclient repo
- sudo pip install -r requirements.txt
- sudo python setup.py install
- python setup.py install
Command-line API
----------------

View File

@ -12,4 +12,3 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

View File

@ -186,6 +186,23 @@ def format_output(output, format='yaml'):
% output_format)
def format_dimensions(dict):
return ('dimensions: {\n' + format_dict(dict) + '\n}')
def format_expression_data(dict):
# takes an dictionary containing a dict
string_list = list()
for k, v in dict.items():
if k == 'dimensions':
dim_str = format_dimensions(v)
string_list.append(dim_str)
else:
d_str = k + ': ' + str(v)
string_list.append(d_str)
return '\n'.join(string_list)
def format_dictlist(dict_list):
# takes list of dictionaries to format for output
string_list = list()
@ -204,6 +221,6 @@ def format_dict(dict):
# takes a dictionary to format for output
dstring_list = list()
for k, v in dict.items():
d_str = k + ':' + v
d_str = k + ': ' + str(v)
dstring_list.append(d_str)
return '\n'.join(dstring_list)

View File

@ -325,6 +325,8 @@ def do_notification_update(mc, args):
help='Description of the alarm.')
@utils.arg('expression', metavar='<EXPRESSION>',
help='The alarm expression to evaluate. No spaces.')
@utils.arg('--severity', metavar='<SEVERITY>',
help='Severity is one of [LOW, MEDIUM, HIGH, CRITICAL].')
@utils.arg('--alarm-actions', metavar='<NOTIFICATION-ID>',
help='The notification method to use when an alarm state is ALARM. '
'This param may be specified multiple times.',
@ -350,6 +352,14 @@ def do_alarm_create(mc, args):
fields['ok_actions'] = args.ok_actions
if args.undetermined_actions:
fields['undetermined_actions'] = args.undetermined_actions
if args.severity:
severity_types = ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL']
if args.severity not in severity_types:
errmsg = 'Invalid severity, not one of [' + \
', '.join(severity_types) + ']'
print(errmsg)
return
fields['severity'] = args.severity
try:
alarm = mc.alarms.create(**fields)
except exc.HTTPException as he:
@ -381,10 +391,12 @@ def do_alarm_show(mc, args):
'name': utils.json_formatter,
'id': utils.json_formatter,
'expression': utils.json_formatter,
'expression_data': utils.format_expression_data,
'state': utils.json_formatter,
'actions_enabled': utils.json_formatter,
'alarm_actions': utils.json_formatter,
'ok_actions': utils.json_formatter,
'severity': utils.json_formatter,
'undetermined_actions': utils.json_formatter,
'description': utils.json_formatter,
'links': utils.format_dictlist,
@ -397,11 +409,21 @@ def do_alarm_show(mc, args):
'This can be specified multiple times, or once with parameters '
'separated by a comma.',
action='append')
@utils.arg('--state', metavar='<STATE>',
help='STATE is one of [UNDETERMINED, OK, ALARM].')
def do_alarm_list(mc, args):
'''List alarms for this tenant.'''
fields = {}
if args.dimensions:
fields['dimensions'] = utils.format_parameters(args.dimensions)
if args.state:
state_types = ['UNDETERMINED', 'OK', 'ALARM']
if args.state not in state_types:
errmsg = 'Invalid state, not one of [' + \
', '.join(state_types) + ']'
print(errmsg)
return
fields['state'] = args.state
try:
alarm = mc.alarms.list(**fields)
except exc.HTTPException as he:
@ -470,6 +492,8 @@ def do_alarm_delete(mc, args):
help='The actions_enabled boolean is one of [true,false]')
@utils.arg('state', metavar='<STATE>',
help='The alarm state. State is one of [UNDETERMINED,ALARM,OK]')
@utils.arg('--severity', metavar='<SEVERITY>',
help='Severity is one of [LOW, MEDIUM, HIGH, CRITICAL].')
def do_alarm_update(mc, args):
'''Update the alarm.'''
fields = {}
@ -486,6 +510,14 @@ def do_alarm_update(mc, args):
fields['undetermined_actions'] = args.undetermined_actions
fields['actions_enabled'] = args.enabled
fields['state'] = args.state
if args.severity:
severity_types = ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL']
if args.severity not in severity_types:
errmsg = 'Invalid severity, not one of [' + \
', '.join(severity_types) + ']'
print(errmsg)
return
fields['severity'] = args.severity
try:
alarm = mc.alarms.update(**fields)
except exc.HTTPException as he:
@ -520,6 +552,8 @@ def do_alarm_update(mc, args):
help='The actions_enabled boolean is one of [true,false]')
@utils.arg('--state', metavar='<STATE>',
help='The alarm state. State is one of [UNDETERMINED,ALARM,OK]')
@utils.arg('--severity', metavar='<SEVERITY>',
help='Severity is one of [LOW, MEDIUM, HIGH, CRITICAL].')
def do_alarm_patch(mc, args):
'''Patch the alarm.'''
fields = {}
@ -540,6 +574,14 @@ def do_alarm_patch(mc, args):
fields['actions_enabled'] = args.enabled
if args.state:
fields['state'] = args.state
if args.severity:
severity_types = ['LOW', 'MEDIUM', 'HIGH', 'CRITICAL']
if args.severity not in severity_types:
errmsg = 'Invalid severity, not one of [' + \
', '.join(severity_types) + ']'
print(errmsg)
return
fields['severity'] = args.severity
try:
alarm = mc.alarms.patch(**fields)
except exc.HTTPException as he: