mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): adds basic page for listing alerts
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/bus"
|
"github.com/grafana/grafana/pkg/bus"
|
||||||
"github.com/grafana/grafana/pkg/middleware"
|
"github.com/grafana/grafana/pkg/middleware"
|
||||||
"github.com/grafana/grafana/pkg/models"
|
"github.com/grafana/grafana/pkg/models"
|
||||||
@@ -21,7 +22,7 @@ func ValidateOrgAlert(c *middleware.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/alert_rule
|
// GET /api/alert_rule/changes
|
||||||
func GetAlertChanges(c *middleware.Context) Response {
|
func GetAlertChanges(c *middleware.Context) Response {
|
||||||
query := models.GetAlertChangesQuery{
|
query := models.GetAlertChangesQuery{
|
||||||
OrgId: c.OrgId,
|
OrgId: c.OrgId,
|
||||||
@@ -44,7 +45,44 @@ func GetAlerts(c *middleware.Context) Response {
|
|||||||
return ApiError(500, "List alerts failed", err)
|
return ApiError(500, "List alerts failed", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Json(200, query.Result)
|
dashboardIds := make([]int64, 0)
|
||||||
|
alertDTOs := make([]*dtos.AlertRuleDTO, 0)
|
||||||
|
for _, alert := range query.Result {
|
||||||
|
dashboardIds = append(dashboardIds, alert.DashboardId)
|
||||||
|
alertDTOs = append(alertDTOs, &dtos.AlertRuleDTO{
|
||||||
|
Id: alert.Id,
|
||||||
|
DashboardId: alert.DashboardId,
|
||||||
|
PanelId: alert.PanelId,
|
||||||
|
Query: alert.Query,
|
||||||
|
QueryRefId: alert.QueryRefId,
|
||||||
|
WarnLevel: alert.WarnLevel,
|
||||||
|
CritLevel: alert.CritLevel,
|
||||||
|
Interval: alert.Interval,
|
||||||
|
Title: alert.Title,
|
||||||
|
Description: alert.Description,
|
||||||
|
QueryRange: alert.QueryRange,
|
||||||
|
Aggregator: alert.Aggregator,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
dashboardsQuery := models.GetDashboardsQuery{
|
||||||
|
DashboardIds: dashboardIds,
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := bus.Dispatch(&dashboardsQuery); err != nil {
|
||||||
|
return ApiError(500, "List alerts failed", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: should be possible to speed this up with lookup table
|
||||||
|
for _, alert := range alertDTOs {
|
||||||
|
for _, dash := range *dashboardsQuery.Result {
|
||||||
|
if alert.DashboardId == dash.Id {
|
||||||
|
alert.DashbboardUri = "db/" + dash.Slug
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Json(200, alertDTOs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET /api/alert_rule/:id
|
// GET /api/alert_rule/:id
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ func Register(r *macaron.Macaron) {
|
|||||||
|
|
||||||
r.Get("/playlists/", reqSignedIn, Index)
|
r.Get("/playlists/", reqSignedIn, Index)
|
||||||
r.Get("/playlists/*", reqSignedIn, Index)
|
r.Get("/playlists/*", reqSignedIn, Index)
|
||||||
|
r.Get("/alerts/", reqSignedIn, Index)
|
||||||
|
r.Get("/alerts/*", reqSignedIn, Index)
|
||||||
|
|
||||||
// sign up
|
// sign up
|
||||||
r.Get("/signup", Index)
|
r.Get("/signup", Index)
|
||||||
|
|||||||
18
pkg/api/dtos/alerting.go
Normal file
18
pkg/api/dtos/alerting.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package dtos
|
||||||
|
|
||||||
|
type AlertRuleDTO struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
DashboardId int64 `json:"dashboardId"`
|
||||||
|
PanelId int64 `json:"panelId"`
|
||||||
|
Query string `json:"query"`
|
||||||
|
QueryRefId string `json:"queryRefId"`
|
||||||
|
WarnLevel string `json:"warnLevel"`
|
||||||
|
CritLevel string `json:"critLevel"`
|
||||||
|
Interval string `json:"interval"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
QueryRange string `json:"queryRange"`
|
||||||
|
Aggregator string `json:"aggregator"`
|
||||||
|
|
||||||
|
DashbboardUri string `json:"dashboardUri"`
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
|
|||||||
var loadOrgBundle = new BundleLoader('app/features/org/all');
|
var loadOrgBundle = new BundleLoader('app/features/org/all');
|
||||||
var loadPluginsBundle = new BundleLoader('app/features/plugins/all');
|
var loadPluginsBundle = new BundleLoader('app/features/plugins/all');
|
||||||
var loadAdminBundle = new BundleLoader('app/features/admin/admin');
|
var loadAdminBundle = new BundleLoader('app/features/admin/admin');
|
||||||
|
var loadAlertsBundle = new BundleLoader('app/features/alerts/all');
|
||||||
|
|
||||||
$routeProvider
|
$routeProvider
|
||||||
.when('/', {
|
.when('/', {
|
||||||
@@ -197,6 +198,12 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
|
|||||||
controllerAs: 'ctrl',
|
controllerAs: 'ctrl',
|
||||||
templateUrl: 'public/app/features/styleguide/styleguide.html',
|
templateUrl: 'public/app/features/styleguide/styleguide.html',
|
||||||
})
|
})
|
||||||
|
.when('/alerts', {
|
||||||
|
templateUrl: 'public/app/features/alerts/partials/alerts_page.html',
|
||||||
|
controller: 'AlertPageCtrl',
|
||||||
|
controllerAs: 'ctrl',
|
||||||
|
resolve: loadAlertsBundle,
|
||||||
|
})
|
||||||
.otherwise({
|
.otherwise({
|
||||||
templateUrl: 'public/app/partials/error.html',
|
templateUrl: 'public/app/partials/error.html',
|
||||||
controller: 'ErrorCtrl'
|
controller: 'ErrorCtrl'
|
||||||
|
|||||||
26
public/app/features/alerts/alerts_ctrl.ts
Normal file
26
public/app/features/alerts/alerts_ctrl.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
///<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 AlertPageCtrl {
|
||||||
|
|
||||||
|
alerts: any;
|
||||||
|
/** @ngInject */
|
||||||
|
constructor(private $scope, private backendSrv) {
|
||||||
|
console.log('ctor!');
|
||||||
|
this.loadAlerts();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadAlerts() {
|
||||||
|
this.backendSrv.get('/api/alert_rule').then(result => {
|
||||||
|
console.log(result);
|
||||||
|
this.alerts = result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
coreModule.controller('AlertPageCtrl', AlertPageCtrl);
|
||||||
|
|
||||||
2
public/app/features/alerts/all.ts
Normal file
2
public/app/features/alerts/all.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
import './alerts_ctrl';
|
||||||
|
|
||||||
34
public/app/features/alerts/partials/alerts_page.html
Normal file
34
public/app/features/alerts/partials/alerts_page.html
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<navbar icon="fa fa-fw fa-list" title="Alerts" title-url="alerts">
|
||||||
|
</navbar>
|
||||||
|
|
||||||
|
<div class="page-container" >
|
||||||
|
<div class="page-header">
|
||||||
|
<h1>Alerts</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table class="filter-table">
|
||||||
|
<thead>
|
||||||
|
<th><strong>Name</strong></th>
|
||||||
|
<th style="width: 68px"></th>
|
||||||
|
<th style="width: 28px"></th>
|
||||||
|
|
||||||
|
</thead>
|
||||||
|
<tr ng-repeat="alert in ctrl.alerts">
|
||||||
|
<td>
|
||||||
|
{{alert.title}}
|
||||||
|
</td>
|
||||||
|
<td class="text-center">
|
||||||
|
<a href="/dashboard/{{alert.dashboardUri}}" class="btn btn-inverse btn-small">
|
||||||
|
Go to dashboard
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<a ng-click="ctrl.deleteAlert(alert)" class="btn btn-danger btn-small">
|
||||||
|
<i class="fa fa-remove"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user