Feature for repeated alerting in grafana
This commit is contained in:
@@ -22,6 +22,7 @@ func init() {
|
||||
bus.AddHandler("sql", GetAlertStatesForDashboard)
|
||||
bus.AddHandler("sql", PauseAlert)
|
||||
bus.AddHandler("sql", PauseAllAlerts)
|
||||
bus.AddHandler("sql", IncAlertEval)
|
||||
}
|
||||
|
||||
func GetAlertById(query *m.GetAlertByIdQuery) error {
|
||||
@@ -188,7 +189,7 @@ func updateAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *DBS
|
||||
if alertToUpdate.ContainsUpdates(alert) {
|
||||
alert.Updated = timeNow()
|
||||
alert.State = alertToUpdate.State
|
||||
sess.MustCols("message")
|
||||
sess.MustCols("message", "notify_freq", "notify_once")
|
||||
_, err := sess.Id(alert.Id).Update(alert)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -343,3 +344,22 @@ func GetAlertStatesForDashboard(query *m.GetAlertStatesForDashboardQuery) error
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func IncAlertEval(cmd *m.IncAlertEvalCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
alert := m.Alert{}
|
||||
|
||||
if _, err := sess.Id(cmd.AlertId).Get(&alert); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
alert.NotifyEval = (alert.NotifyEval + 1) % alert.NotifyFreq
|
||||
|
||||
sess.MustCols("notify_eval")
|
||||
if _, err := sess.Id(cmd.AlertId).Update(alert); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ func addAlertMigrations(mg *Migrator) {
|
||||
{Name: "state_changes", Type: DB_Int, Nullable: false},
|
||||
{Name: "created", Type: DB_DateTime, Nullable: false},
|
||||
{Name: "updated", Type: DB_DateTime, Nullable: false},
|
||||
{Name: "notify_once", Type: DB_Bool, Nullable: false},
|
||||
{Name: "notify_freq", Type: DB_Int, Nullable: false},
|
||||
{Name: "notify_eval", Type: DB_Int, Nullable: false},
|
||||
},
|
||||
Indices: []*Index{
|
||||
{Cols: []string{"org_id", "id"}, Type: IndexType},
|
||||
|
||||
Reference in New Issue
Block a user