本文整理汇总了Golang中github.com/grafana/grafana/pkg/models.Alert类的典型用法代码示例。如果您正苦于以下问题:Golang Alert类的具体用法?Golang Alert怎么用?Golang Alert使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Alert类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetAlertState
func SetAlertState(cmd *m.SetAlertStateCommand) 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")
}
alert.State = cmd.State
alert.StateChanges += 1
alert.NewStateDate = time.Now()
alert.EvalData = cmd.EvalData
if cmd.Error == "" {
alert.ExecutionError = " " //without this space, xorm skips updating this field
} else {
alert.ExecutionError = cmd.Error
}
sess.Id(alert.Id).Update(&alert)
return nil
})
}
示例2: upsertAlerts
func upsertAlerts(existingAlerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Session) error {
for _, alert := range cmd.Alerts {
update := false
var alertToUpdate *m.Alert
for _, k := range existingAlerts {
if alert.PanelId == k.PanelId {
update = true
alert.Id = k.Id
alertToUpdate = k
break
}
}
if update {
if alertToUpdate.ContainsUpdates(alert) {
alert.Updated = time.Now()
alert.State = alertToUpdate.State
_, err := sess.Id(alert.Id).Update(alert)
if err != nil {
return err
}
sqlog.Debug("Alert updated", "name", alert.Name, "id", alert.Id)
}
} else {
alert.Updated = time.Now()
alert.Created = time.Now()
alert.State = m.AlertStateNoData
alert.NewStateDate = time.Now()
_, err := sess.Insert(alert)
if err != nil {
return err
}
sqlog.Debug("Alert inserted", "name", alert.Name, "id", alert.Id)
}
}
return nil
}
示例3: PauseAlertRule
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
})
}
示例4: PauseAlertRule
func PauseAlertRule(cmd *m.PauseAlertCommand) error {
return inTransaction(func(sess *xorm.Session) error {
alert := m.Alert{}
has, err := x.Where("id = ? AND org_id=?", cmd.AlertId, cmd.OrgId).Get(&alert)
if 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.AlertStatePending
}
alert.State = newState
sess.Id(alert.Id).Update(&alert)
return nil
})
}