mirror of
https://github.com/grafana/grafana.git
synced 2025-07-31 05:02:35 +08:00
feat(alerting): adds alert history page
This commit is contained in:
@ -239,8 +239,8 @@ func Register(r *macaron.Macaron) {
|
|||||||
r.Get("/metrics/test", GetTestMetrics)
|
r.Get("/metrics/test", GetTestMetrics)
|
||||||
|
|
||||||
r.Group("/alerts", func() {
|
r.Group("/alerts", func() {
|
||||||
r.Get("/state/:alertId", wrap(GetAlertState))
|
r.Get("/events/:alertId", wrap(GetAlertState))
|
||||||
r.Put("/state/:alertId", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
|
r.Put("/events/:alertId", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
|
||||||
r.Get("/changes", wrap(GetAlertChanges))
|
r.Get("/changes", wrap(GetAlertChanges))
|
||||||
r.Get("/", wrap(GetAlerts))
|
r.Get("/", wrap(GetAlerts))
|
||||||
r.Get("/:id", ValidateOrgAlert, wrap(GetAlert))
|
r.Get("/:id", ValidateOrgAlert, wrap(GetAlert))
|
||||||
|
@ -50,7 +50,7 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
|
|||||||
func GetAlertStateLogByAlertId(cmd *m.GetAlertsStateLogCommand) error {
|
func GetAlertStateLogByAlertId(cmd *m.GetAlertsStateLogCommand) error {
|
||||||
alertLogs := make([]m.AlertStateLog, 0)
|
alertLogs := make([]m.AlertStateLog, 0)
|
||||||
|
|
||||||
if err := x.Where("alert_id = ?", cmd.AlertId).Find(&alertLogs); err != nil {
|
if err := x.Where("alert_id = ?", cmd.AlertId).Desc("created").Find(&alertLogs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +204,12 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
|
|||||||
controllerAs: 'ctrl',
|
controllerAs: 'ctrl',
|
||||||
resolve: loadAlertsBundle,
|
resolve: loadAlertsBundle,
|
||||||
})
|
})
|
||||||
|
.when('/alerts/events/:alertId', {
|
||||||
|
templateUrl: 'public/app/features/alerts/partials/alert_log.html',
|
||||||
|
controller: 'AlertLogCtrl',
|
||||||
|
controllerAs: 'ctrl',
|
||||||
|
resolve: loadAlertsBundle,
|
||||||
|
})
|
||||||
.otherwise({
|
.otherwise({
|
||||||
templateUrl: 'public/app/partials/error.html',
|
templateUrl: 'public/app/partials/error.html',
|
||||||
controller: 'ErrorCtrl'
|
controller: 'ErrorCtrl'
|
||||||
|
33
public/app/features/alerts/alert_log_ctrl.ts
Normal file
33
public/app/features/alerts/alert_log_ctrl.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
///<reference path="../../headers/common.d.ts" />
|
||||||
|
|
||||||
|
import angular from 'angular';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import coreModule from '../../core/core_module';
|
||||||
|
import config from 'app/core/config';
|
||||||
|
|
||||||
|
export class AlertLogCtrl {
|
||||||
|
|
||||||
|
alertLogs: any;
|
||||||
|
alert: any;
|
||||||
|
alertId: any;
|
||||||
|
|
||||||
|
/** @ngInject */
|
||||||
|
constructor(private $route, private backendSrv) {
|
||||||
|
if ($route.current.params.alertId) {
|
||||||
|
this.alertId = $route.current.params.alertId;
|
||||||
|
this.loadAlertLogs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadAlertLogs() {
|
||||||
|
this.backendSrv.get('/api/alerts/events/' + this.alertId).then(result => {
|
||||||
|
this.alertLogs = result;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.backendSrv.get('/api/alerts/' + this.alertId).then(result => {
|
||||||
|
this.alert = result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
coreModule.controller('AlertLogCtrl', AlertLogCtrl);
|
@ -8,15 +8,14 @@ import config from 'app/core/config';
|
|||||||
export class AlertPageCtrl {
|
export class AlertPageCtrl {
|
||||||
|
|
||||||
alerts: any;
|
alerts: any;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private $scope, private backendSrv) {
|
constructor(private backendSrv) {
|
||||||
console.log('ctor!');
|
|
||||||
this.loadAlerts();
|
this.loadAlerts();
|
||||||
}
|
}
|
||||||
|
|
||||||
loadAlerts() {
|
loadAlerts() {
|
||||||
this.backendSrv.get('/api/alerts').then(result => {
|
this.backendSrv.get('/api/alerts').then(result => {
|
||||||
console.log(result);
|
|
||||||
this.alerts = result;
|
this.alerts = result;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
import './alerts_ctrl';
|
import './alerts_ctrl';
|
||||||
|
import './alert_log_ctrl';
|
||||||
|
|
||||||
|
29
public/app/features/alerts/partials/alert_log.html
Normal file
29
public/app/features/alerts/partials/alert_log.html
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<navbar icon="fa fa-fw fa-list" title="Alerts" title-url="alerts">
|
||||||
|
</navbar>
|
||||||
|
|
||||||
|
<div class="page-container" >
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>Alert history for {{ctrl.alert.title}}</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="filter-table">
|
||||||
|
<thead>
|
||||||
|
<th style="width: 68px"></th>
|
||||||
|
<th><strong>Time</strong></th>
|
||||||
|
<th>Description</th>
|
||||||
|
</thead>
|
||||||
|
<tr ng-repeat="alertLog in ctrl.alertLogs">
|
||||||
|
<td>
|
||||||
|
{{alertLog.newState}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{alertLog.created}}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{alertLog.info}}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
@ -18,7 +18,9 @@
|
|||||||
{{alert.title}}
|
{{alert.title}}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{alert.state}}
|
<a href="/alerts/events/{{alert.id}}" class="btn btn-inverse btn-small">
|
||||||
|
{{alert.state}}
|
||||||
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
<a href="/dashboard/{{alert.dashboardUri}}" class="btn btn-inverse btn-small">
|
<a href="/dashboard/{{alert.dashboardUri}}" class="btn btn-inverse btn-small">
|
||||||
|
Reference in New Issue
Block a user