diff --git a/dashboard/dashboard.go b/dashboard/dashboard.go index d3b07b0e..b1767ef8 100644 --- a/dashboard/dashboard.go +++ b/dashboard/dashboard.go @@ -155,6 +155,15 @@ func UID(uid string) Option { } } +// Slug sets the Slug used by the dashboard. +func Slug(slug string) Option { + return func(builder *Builder) error { + builder.board.Slug = slug + + return nil + } +} + // VariableAsCustom adds a templated variable, defined as a set of custom // values. // See https://grafana.com/docs/grafana/latest/reference/templating/#variable-types diff --git a/decoder/dashboard.go b/decoder/dashboard.go index 1537eecb..ee6200e8 100644 --- a/decoder/dashboard.go +++ b/decoder/dashboard.go @@ -12,6 +12,8 @@ var ErrInvalidTimezone = fmt.Errorf("invalid timezone") type DashboardModel struct { Title string + Slug string + UID string `yaml:",omitempty"` Editable bool SharedCrosshair bool `yaml:"shared_crosshair"` Tags []string @@ -38,6 +40,14 @@ func (d *DashboardModel) ToBuilder() (dashboard.Builder, error) { opts = append(opts, dashboard.Tags(d.Tags)) } + if len(d.Slug) != 0 { + opts = append(opts, dashboard.Slug(d.Slug)) + } + + if len(d.UID) != 0 { + opts = append(opts, dashboard.UID(d.UID)) + } + for _, externalLink := range d.ExternalLinks { opts = append(opts, dashboard.ExternalLinks(externalLink.toModel())) } diff --git a/decoder/dashboard_test.go b/decoder/dashboard_test.go index 5416d5c6..df83e871 100644 --- a/decoder/dashboard_test.go +++ b/decoder/dashboard_test.go @@ -314,6 +314,8 @@ rows: func generalOptions() testCase { yaml := `title: Awesome dashboard +slug: this_is_a_slug +uid: my_uid editable: true shared_crosshair: true tags: [generated, yaml] diff --git a/decoder/testdata/general_options.json b/decoder/testdata/general_options.json index 3880d495..cf748464 100644 --- a/decoder/testdata/general_options.json +++ b/decoder/testdata/general_options.json @@ -1,5 +1,6 @@ { - "slug": "", + "slug": "this_is_a_slug", + "uid": "my_uid", "title": "Awesome dashboard", "originalTitle": "", "tags": ["generated", "yaml"],