The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/services/sqlstore/alerting.go

39 lines
743 B

package sqlstore
import (
"fmt"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
func init() {
bus.AddHandler("sql", SaveAlerts)
}
func SaveAlerts(cmd *m.SaveAlertsCommand) error {
fmt.Printf("Saving alerts for dashboard %v\n", cmd.DashboardId)
for _, alert := range *cmd.Alerts {
_, err := x.Insert(&alert)
if err != nil {
return err
}
}
return nil
}
func GetAlertsByDashboard(dashboardId, panelId int64) (m.Alert, error) {
// this code should be refactored!!
// uniqueness should be garanted!
alerts := make([]m.Alert, 0)
err := x.Where("dashboard_id = ? and panel_id = ?", dashboardId, panelId).Find(&alerts)
if err != nil {
return m.Alert{}, err
}
return alerts[0], nil
}