|
| 1 | +// Create a new timeseries widget with product_analytics data source |
| 2 | + |
| 3 | +package main |
| 4 | + |
| 5 | +import ( |
| 6 | + "context" |
| 7 | + "encoding/json" |
| 8 | + "fmt" |
| 9 | + "os" |
| 10 | + |
| 11 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadog" |
| 12 | + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV1" |
| 13 | +) |
| 14 | + |
| 15 | +func main() { |
| 16 | + body := datadogV1.Dashboard{ |
| 17 | + Title: "Example-Dashboard with product_analytics datasource", |
| 18 | + Widgets: []datadogV1.Widget{ |
| 19 | + { |
| 20 | + Definition: datadogV1.WidgetDefinition{ |
| 21 | + TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{ |
| 22 | + Title: datadog.PtrString(""), |
| 23 | + ShowLegend: datadog.PtrBool(true), |
| 24 | + LegendLayout: datadogV1.TIMESERIESWIDGETLEGENDLAYOUT_AUTO.Ptr(), |
| 25 | + LegendColumns: []datadogV1.TimeseriesWidgetLegendColumn{ |
| 26 | + datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_AVG, |
| 27 | + datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_MIN, |
| 28 | + datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_MAX, |
| 29 | + datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_VALUE, |
| 30 | + datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_SUM, |
| 31 | + }, |
| 32 | + Time: &datadogV1.WidgetTime{ |
| 33 | + WidgetLegacyLiveSpan: &datadogV1.WidgetLegacyLiveSpan{}}, |
| 34 | + Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES, |
| 35 | + Requests: []datadogV1.TimeseriesWidgetRequest{ |
| 36 | + { |
| 37 | + Formulas: []datadogV1.WidgetFormula{ |
| 38 | + { |
| 39 | + Formula: "query1", |
| 40 | + }, |
| 41 | + }, |
| 42 | + Queries: []datadogV1.FormulaAndFunctionQueryDefinition{ |
| 43 | + datadogV1.FormulaAndFunctionQueryDefinition{ |
| 44 | + FormulaAndFunctionEventQueryDefinition: &datadogV1.FormulaAndFunctionEventQueryDefinition{ |
| 45 | + DataSource: datadogV1.FORMULAANDFUNCTIONEVENTSDATASOURCE_PRODUCT_ANALYTICS, |
| 46 | + Name: "query1", |
| 47 | + Search: &datadogV1.FormulaAndFunctionEventQueryDefinitionSearch{ |
| 48 | + Query: "test_level:test", |
| 49 | + }, |
| 50 | + Indexes: []string{ |
| 51 | + "*", |
| 52 | + }, |
| 53 | + Compute: datadogV1.FormulaAndFunctionEventQueryDefinitionCompute{ |
| 54 | + Aggregation: datadogV1.FORMULAANDFUNCTIONEVENTAGGREGATION_COUNT, |
| 55 | + }, |
| 56 | + GroupBy: []datadogV1.FormulaAndFunctionEventQueryGroupBy{}, |
| 57 | + }}, |
| 58 | + }, |
| 59 | + ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_TIMESERIES.Ptr(), |
| 60 | + Style: &datadogV1.WidgetRequestStyle{ |
| 61 | + Palette: datadog.PtrString("dog_classic"), |
| 62 | + LineType: datadogV1.WIDGETLINETYPE_SOLID.Ptr(), |
| 63 | + LineWidth: datadogV1.WIDGETLINEWIDTH_NORMAL.Ptr(), |
| 64 | + }, |
| 65 | + DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(), |
| 66 | + }, |
| 67 | + }, |
| 68 | + }}, |
| 69 | + }, |
| 70 | + }, |
| 71 | + LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED, |
| 72 | + ReflowType: datadogV1.DASHBOARDREFLOWTYPE_AUTO.Ptr(), |
| 73 | + } |
| 74 | + ctx := datadog.NewDefaultContext(context.Background()) |
| 75 | + configuration := datadog.NewConfiguration() |
| 76 | + apiClient := datadog.NewAPIClient(configuration) |
| 77 | + api := datadogV1.NewDashboardsApi(apiClient) |
| 78 | + resp, r, err := api.CreateDashboard(ctx, body) |
| 79 | + |
| 80 | + if err != nil { |
| 81 | + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) |
| 82 | + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) |
| 83 | + } |
| 84 | + |
| 85 | + responseContent, _ := json.MarshalIndent(resp, "", " ") |
| 86 | + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) |
| 87 | +} |
0 commit comments