grafana/pkg/api/dashboard_snapshot.go

47 lines
1.1 KiB
Go
Raw Normal View History

2015-03-21 07:53:16 -05:00
package api
import (
"github.com/grafana/grafana/pkg/api/dtos"
2015-03-21 07:53:16 -05:00
"github.com/grafana/grafana/pkg/bus"
2015-03-24 10:49:12 -05:00
"github.com/grafana/grafana/pkg/metrics"
2015-03-21 07:53:16 -05:00
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/util"
)
func CreateDashboardSnapshot(c *middleware.Context, cmd m.CreateDashboardSnapshotCommand) {
cmd.Key = util.GetRandomString(32)
2015-03-21 07:53:16 -05:00
if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Failed to create snaphost", err)
return
}
2015-03-24 10:49:12 -05:00
metrics.M_Api_Dashboard_Snapshot_Create.Inc(1)
2015-03-21 07:53:16 -05:00
c.JSON(200, util.DynMap{"key": cmd.Key})
}
func GetDashboardSnapshot(c *middleware.Context) {
key := c.Params(":key")
query := &m.GetDashboardSnapshotQuery{Key: key}
err := bus.Dispatch(query)
if err != nil {
c.JsonApiErr(500, "Failed to get dashboard snapshot", err)
return
}
dto := dtos.Dashboard{
Model: query.Result.Dashboard,
Meta: dtos.DashboardMeta{IsSnapshot: true},
}
2015-03-24 10:49:12 -05:00
metrics.M_Api_Dashboard_Snapshot_Get.Inc(1)
2015-03-23 23:58:29 -05:00
c.Resp.Header().Set("Cache-Control", "public, max-age=31536000")
2015-03-24 10:49:12 -05:00
c.JSON(200, dto)
2015-03-21 07:53:16 -05:00
}