mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
chore(alerting): struct names and url refactoring
This commit is contained in:
@@ -30,7 +30,7 @@ func GetAlertChanges(c *middleware.Context) Response {
|
||||
|
||||
limit := c.QueryInt64("limit")
|
||||
if limit == 0 {
|
||||
limit = 10
|
||||
limit = 50
|
||||
}
|
||||
|
||||
query.Limit = limit
|
||||
@@ -125,10 +125,10 @@ func DelAlert(c *middleware.Context) Response {
|
||||
}
|
||||
|
||||
// GET /api/alerts/events/:id
|
||||
func GetAlertState(c *middleware.Context) Response {
|
||||
func GetAlertStates(c *middleware.Context) Response {
|
||||
alertId := c.ParamsInt64(":alertId")
|
||||
|
||||
query := models.GetAlertsStateLogCommand{
|
||||
query := models.GetAlertsStateCommand{
|
||||
AlertId: alertId,
|
||||
}
|
||||
|
||||
@@ -141,13 +141,9 @@ func GetAlertState(c *middleware.Context) Response {
|
||||
|
||||
// PUT /api/alerts/events/:id
|
||||
func PutAlertState(c *middleware.Context, cmd models.UpdateAlertStateCommand) Response {
|
||||
alertId := c.ParamsInt64(":alertId")
|
||||
cmd.AlertId = c.ParamsInt64(":alertId")
|
||||
|
||||
if alertId != cmd.AlertId {
|
||||
return ApiError(401, "Bad Request", nil)
|
||||
}
|
||||
|
||||
query := models.GetAlertByIdQuery{Id: alertId}
|
||||
query := models.GetAlertByIdQuery{Id: cmd.AlertId}
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
return ApiError(500, "Failed to get alertstate", err)
|
||||
}
|
||||
|
||||
@@ -239,11 +239,17 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/metrics/test", GetTestMetrics)
|
||||
|
||||
r.Group("/alerts", func() {
|
||||
r.Get("/:alertId/states", wrap(GetAlertState))
|
||||
r.Group("/rules", func() {
|
||||
r.Get("/:alertId/states", wrap(GetAlertStates))
|
||||
|
||||
r.Put("/:alertId/state", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
|
||||
|
||||
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
||||
r.Get("/", wrap(GetAlerts))
|
||||
r.Delete("/:alertId", ValidateOrgAlert, wrap(DelAlert))
|
||||
r.Get("/", wrap(GetAlerts))
|
||||
})
|
||||
|
||||
r.Get("/changes", wrap(GetAlertChanges))
|
||||
})
|
||||
|
||||
r.Get("/alert-changes", wrap(GetAlertChanges))
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type AlertStateLog struct {
|
||||
type AlertState struct {
|
||||
Id int64 `json:"-"`
|
||||
OrgId int64 `json:"-"`
|
||||
AlertId int64 `json:"alertId"`
|
||||
@@ -36,9 +36,9 @@ type UpdateAlertStateCommand struct {
|
||||
|
||||
// Queries
|
||||
|
||||
type GetAlertsStateLogCommand struct {
|
||||
type GetAlertsStateCommand struct {
|
||||
OrgId int64 `json:"orgId" binding:"Required"`
|
||||
AlertId int64 `json:"alertId" binding:"Required"`
|
||||
|
||||
Result *[]AlertStateLog
|
||||
Result *[]AlertState
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
|
||||
alert.State = cmd.NewState
|
||||
sess.Id(alert.Id).Update(&alert)
|
||||
|
||||
log := m.AlertStateLog{
|
||||
log := m.AlertState{
|
||||
AlertId: cmd.AlertId,
|
||||
OrgId: cmd.AlertId,
|
||||
NewState: cmd.NewState,
|
||||
@@ -47,8 +47,8 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func GetAlertStateLogByAlertId(cmd *m.GetAlertsStateLogCommand) error {
|
||||
alertLogs := make([]m.AlertStateLog, 0)
|
||||
func GetAlertStateLogByAlertId(cmd *m.GetAlertsStateCommand) error {
|
||||
alertLogs := make([]m.AlertState, 0)
|
||||
|
||||
if err := x.Where("alert_id = ?", cmd.AlertId).Desc("created").Find(&alertLogs); err != nil {
|
||||
return err
|
||||
|
||||
@@ -82,7 +82,7 @@ func TestAlertingStateAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("should have two event state logs", func() {
|
||||
query := &m.GetAlertsStateLogCommand{
|
||||
query := &m.GetAlertsStateCommand{
|
||||
AlertId: 1,
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func addAlertMigrations(mg *Migrator) {
|
||||
mg.AddMigration("create alert_rules_updates table v1", NewAddTableMigration(alert_changes))
|
||||
|
||||
alert_state_log := Table{
|
||||
Name: "alert_state_log",
|
||||
Name: "alert_state",
|
||||
Columns: []*Column{
|
||||
{Name: "id", Type: DB_BigInt, IsPrimaryKey: true, IsAutoIncrement: true},
|
||||
{Name: "alert_id", Type: DB_BigInt, Nullable: false},
|
||||
|
||||
@@ -22,7 +22,7 @@ export class AlertLogCtrl {
|
||||
}
|
||||
|
||||
loadAlertLogs() {
|
||||
this.backendSrv.get(`/api/alerts/${this.alertId}/states/`).then(result => {
|
||||
this.backendSrv.get(`/api/alerts/rules/${this.alertId}/states`).then(result => {
|
||||
this.alertLogs = _.map(result, log => {
|
||||
log.iconCss = alertDef.getCssForState(log.newState);
|
||||
log.humanTime = moment(log.created).format("YYYY-MM-DD HH:mm:ss");
|
||||
@@ -30,7 +30,7 @@ export class AlertLogCtrl {
|
||||
});
|
||||
});
|
||||
|
||||
this.backendSrv.get(`api/alerts/${this.alertId}`).then(result => {
|
||||
this.backendSrv.get(`/api/alerts/rules/${this.alertId}`).then(result => {
|
||||
this.alert = result;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class AlertPageCtrl {
|
||||
}
|
||||
|
||||
loadAlerts() {
|
||||
this.backendSrv.get('/api/alerts').then(result => {
|
||||
this.backendSrv.get('/api/alerts/rules').then(result => {
|
||||
this.alerts = _.map(result, alert => {
|
||||
alert.iconCss = alertDef.getCssForState(alert.state);
|
||||
return alert;
|
||||
|
||||
Reference in New Issue
Block a user