本文整理匯總了Golang中github.com/grafana/grafana/pkg/models.GetAlertsQuery.Result方法的典型用法代碼示例。如果您正苦於以下問題:Golang GetAlertsQuery.Result方法的具體用法?Golang GetAlertsQuery.Result怎麽用?Golang GetAlertsQuery.Result使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/grafana/grafana/pkg/models.GetAlertsQuery
的用法示例。
在下文中一共展示了GetAlertsQuery.Result方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: HandleAlertsQuery
func HandleAlertsQuery(query *m.GetAlertsQuery) error {
var sql bytes.Buffer
params := make([]interface{}, 0)
sql.WriteString(`SELECT *
from alert
`)
sql.WriteString(`WHERE org_id = ?`)
params = append(params, query.OrgId)
if query.DashboardId != 0 {
sql.WriteString(` AND dashboard_id = ?`)
params = append(params, query.DashboardId)
}
if query.PanelId != 0 {
sql.WriteString(` AND panel_id = ?`)
params = append(params, query.PanelId)
}
if len(query.State) > 0 && query.State[0] != "ALL" {
sql.WriteString(` AND (`)
for i, v := range query.State {
if i > 0 {
sql.WriteString(" OR ")
}
sql.WriteString("state = ? ")
params = append(params, v)
}
sql.WriteString(")")
}
if query.Limit != 0 {
sql.WriteString(" LIMIT ?")
params = append(params, query.Limit)
}
sql.WriteString(" ORDER BY name ASC")
alerts := make([]*m.Alert, 0)
if err := x.Sql(sql.String(), params...).Find(&alerts); err != nil {
return err
}
for i, _ := range alerts {
if alerts[i].ExecutionError == " " {
alerts[i].ExecutionError = ""
}
}
query.Result = alerts
return nil
}
示例2: GetAlerts
func GetAlerts(query *m.GetAlertsQuery) error {
sess := x.Limit(100, 0).Where("org_id=?", query.OrgId).Asc("id")
query.Result = make([]*m.Alert, 0)
return sess.Find(&query.Result)
}