func CreateDashboardSnapshot(cmd *m.CreateDashboardSnapshotCommand) error { return inTransaction(func(sess *xorm.Session) error { // never var expires = time.Now().Add(time.Hour * 24 * 365 * 50) if cmd.Expires > 0 { expires = time.Now().Add(time.Second * time.Duration(cmd.Expires)) } snapshot := &m.DashboardSnapshot{ Key: cmd.Key, DeleteKey: cmd.DeleteKey, OrgId: cmd.OrgId, UserId: cmd.UserId, External: cmd.External, Dashboard: cmd.Dashboard, Expires: expires, Created: time.Now(), Updated: time.Now(), } _, err := sess.Insert(snapshot) cmd.Result = snapshot return err }) }
func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) { if cmd.External { // external snapshot ref requires key and delete key if cmd.Key == "" || cmd.DeleteKey == "" { c.JsonApiErr(400, "Missing key and delete key for external snapshot", nil) return } cmd.OrgId = -1 cmd.UserId = -1 metrics.M_Api_Dashboard_Snapshot_External.Inc(1) } else { cmd.Key = util.GetRandomString(32) cmd.DeleteKey = util.GetRandomString(32) cmd.OrgId = c.OrgId cmd.UserId = c.UserId metrics.M_Api_Dashboard_Snapshot_Create.Inc(1) } if err := bus.Dispatch(&cmd); err != nil { c.JsonApiErr(500, "Failed to create snaphost", err) return } c.JSON(200, util.DynMap{ "key": cmd.Key, "deleteKey": cmd.DeleteKey, "url": setting.ToAbsUrl("dashboard/snapshot/" + cmd.Key), "deleteUrl": setting.ToAbsUrl("api/snapshots-delete/" + cmd.DeleteKey), }) }