mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
commit
446bde2421
@ -252,33 +252,30 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
|
|||||||
return ApiSuccess("Test notification sent")
|
return ApiSuccess("Test notification sent")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAlertIdForRequest(c *middleware.Context) (int64, error) {
|
//POST /api/:alertId/pause
|
||||||
alertId := c.QueryInt64("alertId")
|
func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
|
||||||
panelId := c.QueryInt64("panelId")
|
cmd := models.PauseAlertCommand{
|
||||||
dashboardId := c.QueryInt64("dashboardId")
|
OrgId: c.OrgId,
|
||||||
|
AlertId: c.ParamsInt64("alertId"),
|
||||||
if alertId == 0 && dashboardId == 0 && panelId == 0 {
|
Paused: dto.Paused,
|
||||||
return 0, fmt.Errorf("Missing alertId or dashboardId and panelId")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if alertId == 0 {
|
if err := bus.Dispatch(&cmd); err != nil {
|
||||||
//fetch alertId
|
return ApiError(500, "", err)
|
||||||
query := models.GetAlertsQuery{
|
|
||||||
OrgId: c.OrgId,
|
|
||||||
DashboardId: dashboardId,
|
|
||||||
PanelId: panelId,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := bus.Dispatch(&query); err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(query.Result) != 1 {
|
|
||||||
return 0, fmt.Errorf("PanelId is not unique on dashboard")
|
|
||||||
}
|
|
||||||
|
|
||||||
alertId = query.Result[0].Id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return alertId, nil
|
var response models.AlertStateType = models.AlertStateNoData
|
||||||
|
pausedState := "un paused"
|
||||||
|
if cmd.Paused {
|
||||||
|
response = models.AlertStatePaused
|
||||||
|
pausedState = "paused"
|
||||||
|
}
|
||||||
|
|
||||||
|
result := map[string]interface{}{
|
||||||
|
"alertId": cmd.AlertId,
|
||||||
|
"state": response,
|
||||||
|
"message": "alert " + pausedState,
|
||||||
|
}
|
||||||
|
|
||||||
|
return Json(200, result)
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,7 @@ func Register(r *macaron.Macaron) {
|
|||||||
|
|
||||||
r.Group("/alerts", func() {
|
r.Group("/alerts", func() {
|
||||||
r.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
|
r.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
|
||||||
|
r.Post("/:alertId/pause", ValidateOrgAlert, bind(dtos.PauseAlertCommand{}), wrap(PauseAlert))
|
||||||
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
||||||
r.Get("/", wrap(GetAlerts))
|
r.Get("/", wrap(GetAlerts))
|
||||||
r.Get("/states-for-dashboard", wrap(GetAlertStatesForDashboard))
|
r.Get("/states-for-dashboard", wrap(GetAlertStatesForDashboard))
|
||||||
|
@ -58,3 +58,8 @@ type NotificationTestCommand struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Settings *simplejson.Json `json:"settings"`
|
Settings *simplejson.Json `json:"settings"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PauseAlertCommand struct {
|
||||||
|
AlertId int64 `json:"alertId"`
|
||||||
|
Paused bool `json:"paused"`
|
||||||
|
}
|
||||||
|
@ -101,6 +101,12 @@ type SaveAlertsCommand struct {
|
|||||||
Alerts []*Alert
|
Alerts []*Alert
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PauseAlertCommand struct {
|
||||||
|
OrgId int64
|
||||||
|
AlertId int64
|
||||||
|
Paused bool
|
||||||
|
}
|
||||||
|
|
||||||
type SetAlertStateCommand struct {
|
type SetAlertStateCommand struct {
|
||||||
AlertId int64
|
AlertId int64
|
||||||
OrgId int64
|
OrgId int64
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/log"
|
"github.com/grafana/grafana/pkg/log"
|
||||||
|
"github.com/grafana/grafana/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SchedulerImpl struct {
|
type SchedulerImpl struct {
|
||||||
@ -48,7 +49,7 @@ func (s *SchedulerImpl) Tick(tickTime time.Time, execQueue chan *Job) {
|
|||||||
now := tickTime.Unix()
|
now := tickTime.Unix()
|
||||||
|
|
||||||
for _, job := range s.jobs {
|
for _, job := range s.jobs {
|
||||||
if job.Running {
|
if job.Running || job.Rule.State == models.AlertStatePaused {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ func init() {
|
|||||||
bus.AddHandler("sql", GetAllAlertQueryHandler)
|
bus.AddHandler("sql", GetAllAlertQueryHandler)
|
||||||
bus.AddHandler("sql", SetAlertState)
|
bus.AddHandler("sql", SetAlertState)
|
||||||
bus.AddHandler("sql", GetAlertStatesForDashboard)
|
bus.AddHandler("sql", GetAlertStatesForDashboard)
|
||||||
|
bus.AddHandler("sql", PauseAlertRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAlertById(query *m.GetAlertByIdQuery) error {
|
func GetAlertById(query *m.GetAlertByIdQuery) error {
|
||||||
@ -243,6 +244,29 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PauseAlertRule(cmd *m.PauseAlertCommand) error {
|
||||||
|
return inTransaction(func(sess *xorm.Session) error {
|
||||||
|
alert := m.Alert{}
|
||||||
|
|
||||||
|
if has, err := sess.Id(cmd.AlertId).Get(&alert); err != nil {
|
||||||
|
return err
|
||||||
|
} else if !has {
|
||||||
|
return fmt.Errorf("Could not find alert")
|
||||||
|
}
|
||||||
|
|
||||||
|
var newState m.AlertStateType
|
||||||
|
if cmd.Paused {
|
||||||
|
newState = m.AlertStatePaused
|
||||||
|
} else {
|
||||||
|
newState = m.AlertStateNoData
|
||||||
|
}
|
||||||
|
alert.State = newState
|
||||||
|
|
||||||
|
sess.Id(alert.Id).Update(&alert)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func GetAlertStatesForDashboard(query *m.GetAlertStatesForDashboardQuery) error {
|
func GetAlertStatesForDashboard(query *m.GetAlertStatesForDashboardQuery) error {
|
||||||
var rawSql = `SELECT
|
var rawSql = `SELECT
|
||||||
id,
|
id,
|
||||||
|
@ -23,7 +23,7 @@ export class AlertListCtrl {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(private backendSrv, private $location) {
|
constructor(private backendSrv, private $location, private $scope) {
|
||||||
var params = $location.search();
|
var params = $location.search();
|
||||||
this.filters.state = params.state || null;
|
this.filters.state = params.state || null;
|
||||||
this.loadAlerts();
|
this.loadAlerts();
|
||||||
@ -43,6 +43,19 @@ export class AlertListCtrl {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pauseAlertRule(alertId: any) {
|
||||||
|
var alert = _.find(this.alerts, {id: alertId});
|
||||||
|
|
||||||
|
var payload = {
|
||||||
|
paused: alert.state !== "paused"
|
||||||
|
};
|
||||||
|
|
||||||
|
this.backendSrv.post(`/api/alerts/${alert.id}/pause`, payload).then(result => {
|
||||||
|
alert.state = result.state;
|
||||||
|
alert.stateModel = alertDef.getStateDisplayModel(result.state);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
openHowTo() {
|
openHowTo() {
|
||||||
appEvents.emit('show-modal', {
|
appEvents.emit('show-modal', {
|
||||||
src: 'public/app/features/alerting/partials/alert_howto.html',
|
src: 'public/app/features/alerting/partials/alert_howto.html',
|
||||||
|
@ -29,7 +29,10 @@
|
|||||||
<div class="card-item card-item--alert">
|
<div class="card-item card-item--alert">
|
||||||
<div class="card-item-header">
|
<div class="card-item-header">
|
||||||
<div class="card-item-type">
|
<div class="card-item-type">
|
||||||
<a class="card-item-cog" href="dashboard/{{alert.dashboardUri}}?panelId={{alert.panelId}}&fullscreen&edit&tab=alert" bs-tooltip="'Edit alert rule'">
|
<a class="card-item-cog" bs-tooltip="'Pausing an alert rule prevents it from executing'" ng-click="ctrl.pauseAlertRule(alert.id)">
|
||||||
|
<i class="fa fa-pause"></i>
|
||||||
|
</a>
|
||||||
|
<a class="card-item-cog" href="dashboard/{{alert.dashboardUri}}?panelId={{alert.panelId}}&fullscreen&edit&tab=alert" bs-tooltip="'Edit alert rule'">
|
||||||
<i class="icon-gf icon-gf-settings"></i>
|
<i class="icon-gf icon-gf-settings"></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user