Add Create Notification button to table
This commit is contained in:
parent
2ae5ed1626
commit
cd918ec842
@ -0,0 +1,5 @@
|
||||
from monitoring.api import monitor
|
||||
|
||||
__all__ = [
|
||||
"monitor"
|
||||
]
|
Binary file not shown.
@ -173,7 +173,7 @@ class CreateAlarmForm(BaseAlarmForm):
|
||||
super(CreateAlarmForm, self)._init_fields(readOnly=False, create=True)
|
||||
|
||||
try:
|
||||
notifications = api.monitoring.notification_list(request)
|
||||
notifications = api.monitor.notification_list(request)
|
||||
except Exception as e:
|
||||
notifications = []
|
||||
exceptions.handle(request,
|
||||
@ -204,7 +204,7 @@ class CreateAlarmForm(BaseAlarmForm):
|
||||
try:
|
||||
alarm_actions = [notification.get('notification_id')
|
||||
for notification in data['notifications']]
|
||||
api.monitoring.alarm_create(
|
||||
api.monitor.alarm_create(
|
||||
request,
|
||||
name=data['name'],
|
||||
expression=data['expression'],
|
||||
@ -281,7 +281,7 @@ class CreateMethodForm(BaseNotificationMethodForm):
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
api.monitoring.notification_create(
|
||||
api.monitor.notification_create(
|
||||
request,
|
||||
name=data['name'],
|
||||
type=data['type'],
|
||||
|
@ -79,6 +79,16 @@ class CreateAlarm(tables.LinkAction):
|
||||
return True
|
||||
|
||||
|
||||
class CreateNotification(tables.LinkAction):
|
||||
name = "create_notification"
|
||||
verbose_name = _("Create Notification")
|
||||
classes = ("ajax-modal", "btn-create")
|
||||
url = constants.URL_PREFIX + 'notification_create'
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
|
||||
|
||||
class AlarmsTable(tables.DataTable):
|
||||
status = tables.Column('Status', verbose_name=_('Status'),
|
||||
status_choices={(show_status('OK'), True)},
|
||||
@ -116,7 +126,7 @@ class RealAlarmsTable(tables.DataTable):
|
||||
name = "alarms"
|
||||
verbose_name = _("Alarms")
|
||||
row_actions = (ShowAlarmHistory, ShowAlarmMeters,)
|
||||
table_actions = (CreateAlarm,)
|
||||
table_actions = (CreateNotification, CreateAlarm, )
|
||||
status_columns = ['state']
|
||||
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
{% load url from future %}
|
||||
|
||||
{% block form_id %}create_notif_method_form{% endblock %}
|
||||
{% block form_action %}{% url 'horizon:admin:monitoring:notification_create' %}{% endblock %}
|
||||
{% block form_action %}{{ action_url }}{% endblock %}
|
||||
|
||||
{% block modal-header %}{% trans "Create Notification Method" %}{% endblock %}
|
||||
|
||||
@ -30,5 +30,5 @@
|
||||
|
||||
{% block modal-footer %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create Notification Method" %}" />
|
||||
<a href="{% url 'horizon:admin:monitoring:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
<a href="{{ cancel_url }}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
||||
|
@ -29,8 +29,7 @@ from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import tables
|
||||
|
||||
from monitoring.api import monitoring
|
||||
|
||||
from monitoring import api
|
||||
from .tables import AlarmsTable
|
||||
from .tables import RealAlarmsTable
|
||||
from .tables import AlarmHistoryTable
|
||||
@ -200,7 +199,7 @@ class AlarmView(tables.DataTableView):
|
||||
return super(AlarmView, self).dispatch(*args, **kwargs)
|
||||
|
||||
def get_data(self):
|
||||
alarms = monitoring.alarm_list(self.request)
|
||||
alarms = api.monitor.alarm_list(self.request)
|
||||
results = alarms
|
||||
|
||||
return results
|
||||
@ -243,12 +242,12 @@ class AlarmDetailView(forms.ModalFormView):
|
||||
if hasattr(self, "_object"):
|
||||
return self._object
|
||||
self._object = None
|
||||
self._object = monitoring.alarm_get(self.request, id)
|
||||
self._object = api.monitor.alarm_get(self.request, id)
|
||||
notifications = []
|
||||
# Fetch the notification object for each alarm_actions
|
||||
for notif_id in self._object["alarm_actions"]:
|
||||
try:
|
||||
notification = monitoring.notification_get(
|
||||
notification = api.monitor.notification_get(
|
||||
self.request,
|
||||
notif_id)
|
||||
notifications.append(notification)
|
||||
@ -324,3 +323,9 @@ class NotificationCreateView(forms.ModalFormView):
|
||||
form_class = alarm_forms.CreateMethodForm
|
||||
template_name = constants.TEMPLATE_PREFIX + 'notifications/create.html'
|
||||
success_url = reverse_lazy(constants.URL_PREFIX + 'alarm')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(NotificationCreateView, self).get_context_data(**kwargs)
|
||||
context["cancel_url"] = self.success_url
|
||||
context["action_url"] = reverse(constants.URL_PREFIX + 'notification_create')
|
||||
return context
|
||||
|
Loading…
Reference in New Issue
Block a user