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/dashboard_snapshot.go

47 lines
928 B

package sqlstore
import (
"time"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
func init() {
bus.AddHandler("sql", CreateDashboardSnapshot)
bus.AddHandler("sql", GetDashboardSnapshot)
}
func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error {
return inTransaction(func(sess *xorm.Session) error {
snapshot := &m.DashboardSnapshot{
Key: cmd.Key,
Dashboard: cmd.Dashboard,
Expires: time.Unix(0, 0),
Created: time.Now(),
Updated: time.Now(),
}
_, err := sess.Insert(snapshot)
cmd.Result = snapshot
return err
})
}
func GetDashboardSnapshot(query *m.GetDashboardSnapshotQuery) error {
var snapshot m.DashboardSnapshot
has, err := x.Where("key=?", query.Key).Get(&snapshot)
if err != nil {
return err
} else if has == false {
return m.ErrNotFound
}
query.Result = &snapshot
return nil
}