Merge "Make match_by item configurable in create alarm definition dialog"
This commit is contained in:
commit
132330f75a
|
@ -103,9 +103,11 @@ class BaseAlarmForm(forms.SelfHandlingForm):
|
|||
if create:
|
||||
expressionWidget = ExpressionWidget(initial)
|
||||
notificationWidget = NotificationCreateWidget()
|
||||
matchByAttr = None
|
||||
else:
|
||||
expressionWidget = textWidget
|
||||
notificationWidget = NotificationCreateWidget()
|
||||
matchByAttr = {'readonly':'readonly'}
|
||||
|
||||
self.fields['name'] = forms.CharField(label=_("Name"),
|
||||
required=required,
|
||||
|
@ -114,13 +116,10 @@ class BaseAlarmForm(forms.SelfHandlingForm):
|
|||
self.fields['expression'] = forms.CharField(label=_("Expression"),
|
||||
required=required,
|
||||
widget=expressionWidget)
|
||||
apply_to = [['1', _('individually')],
|
||||
['2', _('as a group')]]
|
||||
self.fields['apply_to'] = forms.ChoiceField(label=_("Apply function to metrics"),
|
||||
choices=apply_to,
|
||||
required=False,
|
||||
widget=forms.RadioSelect(),
|
||||
initial="1")
|
||||
self.fields['match_by'] = forms.CharField(label=_("Match by"),
|
||||
required=False,
|
||||
initial="url,hostname,component,service",
|
||||
widget=forms.TextInput(attrs=matchByAttr))
|
||||
self.fields['description'] = forms.CharField(label=_("Description"),
|
||||
required=False,
|
||||
widget=textWidget)
|
||||
|
@ -191,7 +190,7 @@ class CreateAlarmForm(BaseAlarmForm):
|
|||
expression=data['expression'],
|
||||
description=data['description'],
|
||||
severity=data['severity'],
|
||||
match_by=request.POST['match_by'].split(',') if request.POST['apply_to'] == '1' else None,
|
||||
match_by=data['match_by'].split(',') if data['match_by'] else None,
|
||||
alarm_actions=alarm_actions,
|
||||
ok_actions=alarm_actions,
|
||||
undetermined_actions=alarm_actions,
|
||||
|
|
|
@ -11,6 +11,8 @@ CREATE_URL = urlresolvers.reverse(
|
|||
constants.URL_PREFIX + 'alarm_create', args=())
|
||||
DETAIL_URL = urlresolvers.reverse(
|
||||
constants.URL_PREFIX + 'alarm_detail', args=('12345',))
|
||||
EDIT_URL = urlresolvers.reverse(
|
||||
constants.URL_PREFIX + 'alarm_edit', args=('12345',))
|
||||
|
||||
|
||||
class AlarmDefinitionsTest(helpers.TestCase):
|
||||
|
@ -43,7 +45,6 @@ class AlarmDefinitionsTest(helpers.TestCase):
|
|||
'spec_set': ['alarmdef_get'],
|
||||
'alarmdef_get.return_value': {
|
||||
'alarm_actions': [],
|
||||
'apply_to': '1',
|
||||
'match_by': [],
|
||||
}
|
||||
}) as mock:
|
||||
|
@ -52,3 +53,17 @@ class AlarmDefinitionsTest(helpers.TestCase):
|
|||
|
||||
self.assertTemplateUsed(
|
||||
res, 'monitoring/alarmdefs/_detail.html')
|
||||
|
||||
def test_alarmdefs_edit(self):
|
||||
with patch('monitoring.api.monitor', **{
|
||||
'spec_set': ['alarmdef_get'],
|
||||
'alarmdef_get.return_value': {
|
||||
'alarm_actions': [],
|
||||
'match_by': [],
|
||||
}
|
||||
}) as mock:
|
||||
res = self.client.get(EDIT_URL)
|
||||
self.assertEqual(mock.alarmdef_get.call_count, 1)
|
||||
|
||||
self.assertTemplateUsed(
|
||||
res, 'monitoring/alarmdefs/_edit.html')
|
||||
|
|
|
@ -100,7 +100,7 @@ class AlarmCreateView(forms.ModalFormView):
|
|||
|
||||
|
||||
def transform_alarm_data(obj):
|
||||
obj['apply_to'] = '1' if obj['match_by'] else '2'
|
||||
obj['match_by'] = ','.join(obj['match_by'])
|
||||
return obj
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue