diff --git a/dashboards.go b/dashboards.go index ce2442f..5f64fbb 100644 --- a/dashboards.go +++ b/dashboards.go @@ -62,32 +62,34 @@ type Style struct { PaletteFlip *bool `json:"paletteFlip,omitempty"` } +type GraphDefinition struct { + Viz *string `json:"viz,omitempty"` + Requests []GraphDefinitionRequest `json:"requests,omitempty"` + Events []GraphEvent `json:"events,omitempty"` + Markers []GraphDefinitionMarker `json:"markers,omitempty"` + + // For timeseries type graphs + Yaxis Yaxis `json:"yaxis,omitempty"` + + // For query value type graphs + Autoscale *bool `json:"austoscale,omitempty"` + TextAlign *string `json:"text_align,omitempty"` + Precision *string `json:"precision,omitempty"` + CustomUnit *string `json:"custom_unit,omitempty"` + + // For hostname type graphs + Style *Style `json:"Style,omitempty"` + + Groups []string `json:"group,omitempty"` + IncludeNoMetricHosts *bool `json:"noMetricHosts,omitempty"` + Scopes []string `json:"scope,omitempty"` + IncludeUngroupedHosts *bool `json:"noGroupHosts,omitempty"` +} + // Graph represents a graph that might exist on a dashboard. type Graph struct { - Title *string `json:"title,omitempty"` - Definition struct { - Viz *string `json:"viz,omitempty"` - Requests []GraphDefinitionRequest `json:"requests,omitempty"` - Events []GraphEvent `json:"events,omitempty"` - Markers []GraphDefinitionMarker `json:"markers,omitempty"` - - // For timeseries type graphs - Yaxis Yaxis `json:"yaxis,omitempty"` - - // For query value type graphs - Autoscale *bool `json:"austoscale,omitempty"` - TextAlign *string `json:"text_align,omitempty"` - Precision *string `json:"precision,omitempty"` - CustomUnit *string `json:"custom_unit,omitempty"` - - // For hostname type graphs - Style *Style `json:"Style,omitempty"` - - Groups []string `json:"group,omitempty"` - IncludeNoMetricHosts *bool `json:"noMetricHosts,omitempty"` - Scopes []string `json:"scope,omitempty"` - IncludeUngroupedHosts *bool `json:"noGroupHosts,omitempty"` - } `json:"definition"` + Title *string `json:"title,omitempty"` + Definition *GraphDefinition `json:"definition"` } // Template variable represents a template variable that might exist on a dashboard diff --git a/datadog-accessors.go b/datadog-accessors.go index 5ab7a2f..6c4b8fe 100644 --- a/datadog-accessors.go +++ b/datadog-accessors.go @@ -4601,6 +4601,37 @@ func (f *FreeTextWidget) SetY(v int) { f.Y = &v } +// GetDefinition returns the Definition field if non-nil, zero value otherwise. +func (g *Graph) GetDefinition() GraphDefinition { + if g == nil || g.Definition == nil { + return GraphDefinition{} + } + return *g.Definition +} + +// GetOkDefinition returns a tuple with the Definition field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *Graph) GetDefinitionOk() (GraphDefinition, bool) { + if g == nil || g.Definition == nil { + return GraphDefinition{}, false + } + return *g.Definition, true +} + +// HasDefinition returns a boolean if a field has been set. +func (g *Graph) HasDefinition() bool { + if g != nil && g.Definition != nil { + return true + } + + return false +} + +// GetDefinition allocates a new g.Definition and returns the pointer to it. +func (g *Graph) SetDefinition(v GraphDefinition) { + g.Definition = &v +} + // GetTitle returns the Title field if non-nil, zero value otherwise. func (g *Graph) GetTitle() string { if g == nil || g.Title == nil { @@ -4632,6 +4663,254 @@ func (g *Graph) SetTitle(v string) { g.Title = &v } +// GetAutoscale returns the Autoscale field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetAutoscale() bool { + if g == nil || g.Autoscale == nil { + return false + } + return *g.Autoscale +} + +// GetOkAutoscale returns a tuple with the Autoscale field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetAutoscaleOk() (bool, bool) { + if g == nil || g.Autoscale == nil { + return false, false + } + return *g.Autoscale, true +} + +// HasAutoscale returns a boolean if a field has been set. +func (g *GraphDefinition) HasAutoscale() bool { + if g != nil && g.Autoscale != nil { + return true + } + + return false +} + +// GetAutoscale allocates a new g.Autoscale and returns the pointer to it. +func (g *GraphDefinition) SetAutoscale(v bool) { + g.Autoscale = &v +} + +// GetCustomUnit returns the CustomUnit field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetCustomUnit() string { + if g == nil || g.CustomUnit == nil { + return "" + } + return *g.CustomUnit +} + +// GetOkCustomUnit returns a tuple with the CustomUnit field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetCustomUnitOk() (string, bool) { + if g == nil || g.CustomUnit == nil { + return "", false + } + return *g.CustomUnit, true +} + +// HasCustomUnit returns a boolean if a field has been set. +func (g *GraphDefinition) HasCustomUnit() bool { + if g != nil && g.CustomUnit != nil { + return true + } + + return false +} + +// GetCustomUnit allocates a new g.CustomUnit and returns the pointer to it. +func (g *GraphDefinition) SetCustomUnit(v string) { + g.CustomUnit = &v +} + +// GetIncludeNoMetricHosts returns the IncludeNoMetricHosts field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetIncludeNoMetricHosts() bool { + if g == nil || g.IncludeNoMetricHosts == nil { + return false + } + return *g.IncludeNoMetricHosts +} + +// GetOkIncludeNoMetricHosts returns a tuple with the IncludeNoMetricHosts field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetIncludeNoMetricHostsOk() (bool, bool) { + if g == nil || g.IncludeNoMetricHosts == nil { + return false, false + } + return *g.IncludeNoMetricHosts, true +} + +// HasIncludeNoMetricHosts returns a boolean if a field has been set. +func (g *GraphDefinition) HasIncludeNoMetricHosts() bool { + if g != nil && g.IncludeNoMetricHosts != nil { + return true + } + + return false +} + +// GetIncludeNoMetricHosts allocates a new g.IncludeNoMetricHosts and returns the pointer to it. +func (g *GraphDefinition) SetIncludeNoMetricHosts(v bool) { + g.IncludeNoMetricHosts = &v +} + +// GetIncludeUngroupedHosts returns the IncludeUngroupedHosts field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetIncludeUngroupedHosts() bool { + if g == nil || g.IncludeUngroupedHosts == nil { + return false + } + return *g.IncludeUngroupedHosts +} + +// GetOkIncludeUngroupedHosts returns a tuple with the IncludeUngroupedHosts field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetIncludeUngroupedHostsOk() (bool, bool) { + if g == nil || g.IncludeUngroupedHosts == nil { + return false, false + } + return *g.IncludeUngroupedHosts, true +} + +// HasIncludeUngroupedHosts returns a boolean if a field has been set. +func (g *GraphDefinition) HasIncludeUngroupedHosts() bool { + if g != nil && g.IncludeUngroupedHosts != nil { + return true + } + + return false +} + +// GetIncludeUngroupedHosts allocates a new g.IncludeUngroupedHosts and returns the pointer to it. +func (g *GraphDefinition) SetIncludeUngroupedHosts(v bool) { + g.IncludeUngroupedHosts = &v +} + +// GetPrecision returns the Precision field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetPrecision() string { + if g == nil || g.Precision == nil { + return "" + } + return *g.Precision +} + +// GetOkPrecision returns a tuple with the Precision field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetPrecisionOk() (string, bool) { + if g == nil || g.Precision == nil { + return "", false + } + return *g.Precision, true +} + +// HasPrecision returns a boolean if a field has been set. +func (g *GraphDefinition) HasPrecision() bool { + if g != nil && g.Precision != nil { + return true + } + + return false +} + +// GetPrecision allocates a new g.Precision and returns the pointer to it. +func (g *GraphDefinition) SetPrecision(v string) { + g.Precision = &v +} + +// GetStyle returns the Style field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetStyle() Style { + if g == nil || g.Style == nil { + return Style{} + } + return *g.Style +} + +// GetOkStyle returns a tuple with the Style field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetStyleOk() (Style, bool) { + if g == nil || g.Style == nil { + return Style{}, false + } + return *g.Style, true +} + +// HasStyle returns a boolean if a field has been set. +func (g *GraphDefinition) HasStyle() bool { + if g != nil && g.Style != nil { + return true + } + + return false +} + +// GetStyle allocates a new g.Style and returns the pointer to it. +func (g *GraphDefinition) SetStyle(v Style) { + g.Style = &v +} + +// GetTextAlign returns the TextAlign field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetTextAlign() string { + if g == nil || g.TextAlign == nil { + return "" + } + return *g.TextAlign +} + +// GetOkTextAlign returns a tuple with the TextAlign field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetTextAlignOk() (string, bool) { + if g == nil || g.TextAlign == nil { + return "", false + } + return *g.TextAlign, true +} + +// HasTextAlign returns a boolean if a field has been set. +func (g *GraphDefinition) HasTextAlign() bool { + if g != nil && g.TextAlign != nil { + return true + } + + return false +} + +// GetTextAlign allocates a new g.TextAlign and returns the pointer to it. +func (g *GraphDefinition) SetTextAlign(v string) { + g.TextAlign = &v +} + +// GetViz returns the Viz field if non-nil, zero value otherwise. +func (g *GraphDefinition) GetViz() string { + if g == nil || g.Viz == nil { + return "" + } + return *g.Viz +} + +// GetOkViz returns a tuple with the Viz field if it's non-nil, zero value otherwise +// and a boolean to check if the value has been set. +func (g *GraphDefinition) GetVizOk() (string, bool) { + if g == nil || g.Viz == nil { + return "", false + } + return *g.Viz, true +} + +// HasViz returns a boolean if a field has been set. +func (g *GraphDefinition) HasViz() bool { + if g != nil && g.Viz != nil { + return true + } + + return false +} + +// GetViz allocates a new g.Viz and returns the pointer to it. +func (g *GraphDefinition) SetViz(v string) { + g.Viz = &v +} + // GetLabel returns the Label field if non-nil, zero value otherwise. func (g *GraphDefinitionMarker) GetLabel() string { if g == nil || g.Label == nil { diff --git a/integration/dashboards_test.go b/integration/dashboards_test.go index ce9d2fb..84f1b67 100644 --- a/integration/dashboards_test.go +++ b/integration/dashboards_test.go @@ -150,38 +150,49 @@ func cleanUpDashboard(t *testing.T, id int) { } func createGraph() []datadog.Graph { - graphDefinition := datadog.Graph{}.Definition - graphDefinition.Viz = datadog.String("timeseries") - r := datadog.Graph{}.Definition.Requests - graphDefinition.Requests = append(r, datadog.GraphDefinitionRequest{Query: datadog.String("avg:system.mem.free{*}"), Stacked: datadog.Bool(false)}) - graph := datadog.Graph{Title: datadog.String("Mandatory graph"), Definition: graphDefinition} + gd := &datadog.GraphDefinition{} + gd.SetViz("timeseries") + + r := gd.Requests + gd.Requests = append(r, datadog.GraphDefinitionRequest{ + Query: datadog.String("avg:system.mem.free{*}"), + Stacked: datadog.Bool(false), + }) + + graph := datadog.Graph{ + Title: datadog.String("Mandatory graph"), + Definition: gd, + } + graphs := []datadog.Graph{} graphs = append(graphs, graph) return graphs } func createAdvancedTimeseriesGraph() []datadog.Graph { - graphDefinition := datadog.Graph{}.Definition - graphDefinition.Viz = datadog.String("timeseries") - r := datadog.Graph{}.Definition.Requests + gd := &datadog.GraphDefinition{} + gd.SetViz("timeseries") - graphDefinition.Requests = append(r, datadog.GraphDefinitionRequest{ + r := gd.Requests + gd.Requests = append(r, datadog.GraphDefinitionRequest{ Query: datadog.String("avg:system.mem.free{*}"), Stacked: datadog.Bool(false), Type: datadog.String("bars"), Style: &datadog.GraphDefinitionRequestStyle{Palette: datadog.String("warm")}, }) - graph := datadog.Graph{Title: datadog.String("Custom type and style graph"), Definition: graphDefinition} + graph := datadog.Graph{Title: datadog.String("Custom type and style graph"), Definition: gd} + graphs := []datadog.Graph{} graphs = append(graphs, graph) return graphs } func createCustomGraph() []datadog.Graph { - graphDefinition := datadog.Graph{}.Definition - graphDefinition.Viz = datadog.String("query_value") - r := datadog.Graph{}.Definition.Requests - graphDefinition.Requests = append(r, datadog.GraphDefinitionRequest{ + gd := &datadog.GraphDefinition{} + gd.SetViz("query_value") + + r := gd.Requests + gd.Requests = append(r, datadog.GraphDefinitionRequest{ Query: datadog.String("( sum:system.mem.used{*} / sum:system.mem.free{*} ) * 100"), Stacked: datadog.Bool(false), Aggregator: datadog.String("avg"), @@ -198,7 +209,12 @@ func createCustomGraph() []datadog.Graph { Comparator: datadog.String("<"), Value: datadog.JsonNumber(json.Number("99")), Palette: datadog.String("white_on_red")}}}) - graph := datadog.Graph{Title: datadog.String("Mandatory graph 2"), Definition: graphDefinition} + + graph := datadog.Graph{ + Title: datadog.String("Mandatory graph 2"), + Definition: gd, + } + graphs := []datadog.Graph{} graphs = append(graphs, graph) return graphs