Alarms History added
This commit is contained in:
parent
95d00a2ec2
commit
89c26d0606
@ -81,9 +81,16 @@ def show_host(data):
|
||||
class ShowAlarmHistory(tables.LinkAction):
|
||||
name = 'history'
|
||||
verbose_name = _('Show History')
|
||||
url = constants.URL_PREFIX + 'history'
|
||||
#url = constants.URL_PREFIX + 'history'
|
||||
classes = ('btn-edit',)
|
||||
|
||||
def get_link_url(self, datum):
|
||||
return reverse(constants.URL_PREFIX + 'history',
|
||||
args=(datum['name'], datum['id'], ))
|
||||
|
||||
def allowed(self, request, datum=None):
|
||||
return True
|
||||
|
||||
|
||||
class ShowAlarmMeters(tables.LinkAction):
|
||||
name = 'meters'
|
||||
@ -187,18 +194,15 @@ class AlarmsTable(tables.DataTable):
|
||||
|
||||
|
||||
class AlarmHistoryTable(tables.DataTable):
|
||||
status = tables.Column('Status', verbose_name=_('Status'),
|
||||
status_choices={(show_status('OK'), True)},
|
||||
filters=[show_status, template.defaultfilters.safe])
|
||||
target = tables.Column('Host', verbose_name=_('Host'))
|
||||
name = tables.Column('Service', verbose_name=_('Service'))
|
||||
lastCheck = tables.Column('Last_Check', verbose_name=_('Last Check'))
|
||||
time = tables.Column('Duration', verbose_name=_('Duration'))
|
||||
detail = tables.Column('Status_Information',
|
||||
verbose_name=_('Status_Information'))
|
||||
name = tables.Column('name', verbose_name=_('Name'))
|
||||
old_state = tables.Column('old_state', verbose_name=_('Old State'))
|
||||
new_state = tables.Column('new_state', verbose_name=_('New State'))
|
||||
timestamp = tables.Column('timestamp', verbose_name=_('Timestamp'))
|
||||
reason = tables.Column('reason', verbose_name=_('Reason'))
|
||||
reason_data = tables.Column('reason_data', verbose_name=_('Reason Data'))
|
||||
|
||||
def get_object_id(self, obj):
|
||||
return obj['Last_Check'] + obj['Service']
|
||||
return obj['alarm_id'] + obj['timestamp']
|
||||
|
||||
class Meta:
|
||||
name = "users"
|
||||
|
@ -25,7 +25,7 @@ urlpatterns = patterns(
|
||||
url(r'^alarm/(?P<service>[^/]+)/$',
|
||||
views.AlarmServiceView.as_view(),
|
||||
name='alarm'),
|
||||
url(r'^history/(?P<service>[^/]+)$',
|
||||
url(r'^history/(?P<name>[^/]+)/(?P<id>[^/]+)$',
|
||||
views.AlarmHistoryView.as_view(),
|
||||
name='history'),
|
||||
url(r'^meters/(?P<service>[^/]+)$',
|
||||
|
@ -232,6 +232,21 @@ def transform_alarm_data(obj):
|
||||
'notifications': getattr(obj, 'alarm_actions', None), }
|
||||
|
||||
|
||||
def transform_alarm_history(results, name):
|
||||
newlist = []
|
||||
for item in results:
|
||||
temp = {}
|
||||
temp['alarm_id'] = item['alarm_id']
|
||||
temp['name'] = name
|
||||
temp['old_state'] = item['old_state']
|
||||
temp['new_state'] = item['new_state']
|
||||
temp['timestamp'] = item['timestamp']
|
||||
temp['reason'] = item['reason']
|
||||
temp['reason_data'] = item['reason_data']
|
||||
newlist.append(temp)
|
||||
return newlist
|
||||
|
||||
|
||||
class AlarmDetailView(forms.ModalFormView):
|
||||
form_class = alarm_forms.DetailAlarmForm
|
||||
template_name = constants.TEMPLATE_PREFIX + 'alarms/detail.html'
|
||||
@ -344,10 +359,15 @@ class AlarmHistoryView(tables.DataTableView):
|
||||
return super(AlarmHistoryView, self).dispatch(*args, **kwargs)
|
||||
|
||||
def get_data(self):
|
||||
# to be implemented
|
||||
id = self.kwargs['id']
|
||||
name = self.kwargs['name']
|
||||
results = []
|
||||
|
||||
return results
|
||||
try:
|
||||
results = api.monitor.alarm_history(self.request, id)
|
||||
except:
|
||||
messages.error(self.request,
|
||||
_("Could not retrieve alarm history for %s") % id)
|
||||
return transform_alarm_history(results, name)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(AlarmHistoryView, self).get_context_data(**kwargs)
|
||||
|
@ -67,6 +67,10 @@ def alarm_delete(request, alarm_id):
|
||||
return monclient(request).alarms.delete(alarm_id=alarm_id)
|
||||
|
||||
|
||||
def alarm_history(request, alarm_id):
|
||||
return monclient(request).alarms.history(alarm_id=alarm_id)
|
||||
|
||||
|
||||
def alarm_get(request, alarm_id):
|
||||
return monclient(request).alarms.get(alarm_id=alarm_id)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user