diff --git a/.apigentools-info b/.apigentools-info index 70028fe09cc..d52aa1d518e 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.5.1.dev2", - "regenerated": "2021-12-21 21:41:44.151379", - "spec_repo_commit": "ee277b0" + "regenerated": "2021-12-21 22:02:03.734218", + "spec_repo_commit": "d1a4fc3" }, "v2": { "apigentools_version": "1.5.1.dev2", - "regenerated": "2021-12-21 21:41:44.169261", - "spec_repo_commit": "ee277b0" + "regenerated": "2021-12-21 22:02:03.753283", + "spec_repo_commit": "d1a4fc3" } } } \ No newline at end of file diff --git a/examples/v1/dashboards/CreateDashboard_145494973.go b/examples/v1/dashboards/CreateDashboard_145494973.go new file mode 100644 index 00000000000..3477fb01cee --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_145494973.go @@ -0,0 +1,69 @@ +// Create a new dashboard with apm resource stats widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_apm_resource_stats_widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + TableWidgetDefinition: &datadog.TableWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadog.TABLEWIDGETDEFINITIONTYPE_QUERY_TABLE, + Requests: []datadog.TableWidgetRequest{ + datadog.TableWidgetRequest{ + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionApmResourceStatsQueryDefinition: &datadog.FormulaAndFunctionApmResourceStatsQueryDefinition{ + PrimaryTagValue: datadog.PtrString("edge-eu1.prod.dog"), + Stat: datadog.FORMULAANDFUNCTIONAPMRESOURCESTATNAME_HITS, + Name: "query1", + Service: "cassandra", + DataSource: datadog.FORMULAANDFUNCTIONAPMRESOURCESTATSDATASOURCE_APM_RESOURCE_STATS, + Env: "ci", + PrimaryTagName: datadog.PtrString("datacenter"), + OperationName: datadog.PtrString("cassandra.query"), + GroupBy: &[]string{ + "resource_name", + }, + }}, + }, + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 4, + }, + }, + }, + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_2104498738.go b/examples/v1/dashboards/CreateDashboard_2104498738.go new file mode 100644 index 00000000000..337a795af64 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_2104498738.go @@ -0,0 +1,82 @@ +// Create a new dashboard with formulas and functions scatterplot widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_formulas_and_functions_scatterplot_widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Id: datadog.PtrInt64(5346764334358972), + Definition: datadog.WidgetDefinition{ + ScatterPlotWidgetDefinition: &datadog.ScatterPlotWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadog.SCATTERPLOTWIDGETDEFINITIONTYPE_SCATTERPLOT, + Requests: datadog.ScatterPlotWidgetDefinitionRequests{ + Table: &datadog.ScatterplotTableRequest{ + Formulas: &[]datadog.ScatterplotWidgetFormula{ + datadog.ScatterplotWidgetFormula{ + Formula: "query1", + Dimension: datadog.SCATTERPLOTDIMENSION_X, + Alias: datadog.PtrString("my-query1"), + }, + datadog.ScatterplotWidgetFormula{ + Formula: "query2", + Dimension: datadog.SCATTERPLOTDIMENSION_Y, + Alias: datadog.PtrString("my-query2"), + }, + }, + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionMetricQueryDefinition: &datadog.FormulaAndFunctionMetricQueryDefinition{ + DataSource: datadog.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS, + Name: "query1", + Query: "avg:system.cpu.user{*} by {service}", + Aggregator: datadog.FORMULAANDFUNCTIONMETRICAGGREGATION_AVG.Ptr(), + }}, + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionMetricQueryDefinition: &datadog.FormulaAndFunctionMetricQueryDefinition{ + DataSource: datadog.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS, + Name: "query2", + Query: "avg:system.mem.used{*} by {service}", + Aggregator: datadog.FORMULAANDFUNCTIONMETRICAGGREGATION_AVG.Ptr(), + }}, + }, + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 2, + }, + }, + }, + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_2338918735.go b/examples/v1/dashboards/CreateDashboard_2338918735.go new file mode 100644 index 00000000000..0908ad53241 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_2338918735.go @@ -0,0 +1,54 @@ +// Create a new dashboard with list_stream widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + Title: "Example-Create_a_new_dashboard_with_list_stream_widget with list_stream widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + ListStreamWidgetDefinition: &datadog.ListStreamWidgetDefinition{ + Type: datadog.LISTSTREAMWIDGETDEFINITIONTYPE_LIST_STREAM, + Requests: []datadog.ListStreamWidgetRequest{ + datadog.ListStreamWidgetRequest{ + Columns: []datadog.ListStreamColumn{ + datadog.ListStreamColumn{ + Width: datadog.LISTSTREAMCOLUMNWIDTH_AUTO, + Field: "timestamp", + }, + }, + Query: datadog.ListStreamQuery{ + DataSource: datadog.LISTSTREAMSOURCE_ISSUE_STREAM, + QueryString: "", + }, + ResponseFormat: datadog.LISTSTREAMRESPONSEFORMAT_EVENT_LIST, + }, + }, + }}, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_2490110261.go b/examples/v1/dashboards/CreateDashboard_2490110261.go new file mode 100644 index 00000000000..fb1a044c5d8 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_2490110261.go @@ -0,0 +1,67 @@ +// Create a new dashboard with an audit logs query + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + Title: "Example-Create_a_new_dashboard_with_an_audit_logs_query with Audit Logs Query", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + TimeseriesWidgetDefinition: &datadog.TimeseriesWidgetDefinition{ + Type: datadog.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES, + Requests: []datadog.TimeseriesWidgetRequest{ + datadog.TimeseriesWidgetRequest{ + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_TIMESERIES.Ptr(), + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionEventQueryDefinition: &datadog.FormulaAndFunctionEventQueryDefinition{ + Search: &datadog.FormulaAndFunctionEventQueryDefinitionSearch{ + Query: "", + }, + DataSource: datadog.FORMULAANDFUNCTIONEVENTSDATASOURCE_AUDIT, + Compute: datadog.FormulaAndFunctionEventQueryDefinitionCompute{ + Aggregation: datadog.FORMULAANDFUNCTIONEVENTAGGREGATION_COUNT, + }, + Name: "query1", + Indexes: &[]string{ + "*", + }, + GroupBy: &[]datadog.FormulaAndFunctionEventQueryGroupBy{}, + }}, + }, + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 2, + Y: 0, + Width: 4, + Height: 2, + }, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_2644712913.go b/examples/v1/dashboards/CreateDashboard_2644712913.go new file mode 100644 index 00000000000..73259ba8eb7 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_2644712913.go @@ -0,0 +1,70 @@ +// Create a new dashboard with a query value widget using the percentile aggregator + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + Title: "Example-Create_a_new_dashboard_with_a_query_value_widget_using_the_percentile_aggregator with QVW Percentile Aggregator", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + QueryValueWidgetDefinition: &datadog.QueryValueWidgetDefinition{ + TitleSize: datadog.PtrString("16"), + Title: datadog.PtrString(""), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Precision: datadog.PtrInt64(2), + Time: &datadog.WidgetTime{}, + Autoscale: datadog.PtrBool(true), + Requests: []datadog.QueryValueWidgetRequest{ + datadog.QueryValueWidgetRequest{ + Formulas: &[]datadog.WidgetFormula{ + datadog.WidgetFormula{ + Formula: "query1", + }, + }, + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionMetricQueryDefinition: &datadog.FormulaAndFunctionMetricQueryDefinition{ + Query: "p90:dist.dd.dogweb.latency{*}", + DataSource: datadog.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS, + Name: "query1", + Aggregator: datadog.FORMULAANDFUNCTIONMETRICAGGREGATION_PERCENTILE.Ptr(), + }}, + }, + }, + }, + Type: datadog.QUERYVALUEWIDGETDEFINITIONTYPE_QUERY_VALUE, + }}, + Layout: &datadog.WidgetLayout{ + Y: 0, + X: 0, + Height: 2, + Width: 2, + }, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_2705593938.go b/examples/v1/dashboards/CreateDashboard_2705593938.go new file mode 100644 index 00000000000..b7605dd4714 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_2705593938.go @@ -0,0 +1,67 @@ +// Create a new dashboard with sunburst widget and metrics data + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_sunburst_widget_and_metrics_data", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + SunburstWidgetDefinition: &datadog.SunburstWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadog.SUNBURSTWIDGETDEFINITIONTYPE_SUNBURST, + Requests: []datadog.SunburstWidgetRequest{ + datadog.SunburstWidgetRequest{ + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + Formulas: &[]datadog.WidgetFormula{ + datadog.WidgetFormula{ + Formula: "query1", + }, + }, + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionMetricQueryDefinition: &datadog.FormulaAndFunctionMetricQueryDefinition{ + Query: "sum:system.mem.used{*} by {service}", + DataSource: datadog.FORMULAANDFUNCTIONMETRICDATASOURCE_METRICS, + Name: "query1", + Aggregator: datadog.FORMULAANDFUNCTIONMETRICAGGREGATION_SUM.Ptr(), + }}, + }, + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 4, + }, + }, + }, + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_3982498788.go b/examples/v1/dashboards/CreateDashboard_3982498788.go new file mode 100644 index 00000000000..1adfd0378af --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_3982498788.go @@ -0,0 +1,51 @@ +// Create a new dashboard with timeseries widget containing style attributes + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + Title: "Example-Create_a_new_dashboard_with_timeseries_widget_containing_style_attributes with timeseries widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + TimeseriesWidgetDefinition: &datadog.TimeseriesWidgetDefinition{ + Type: datadog.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES, + Requests: []datadog.TimeseriesWidgetRequest{ + datadog.TimeseriesWidgetRequest{ + Q: datadog.PtrString("sum:trace.test.errors{env:prod,service:datadog-api-spec} by {resource_name}.as_count()"), + OnRightYaxis: datadog.PtrBool(false), + Style: &datadog.WidgetRequestStyle{ + Palette: datadog.PtrString("warm"), + LineType: datadog.WIDGETLINETYPE_SOLID.Ptr(), + LineWidth: datadog.WIDGETLINEWIDTH_NORMAL.Ptr(), + }, + DisplayType: datadog.WIDGETDISPLAYTYPE_BARS.Ptr(), + }, + }, + }}, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_578885732.go b/examples/v1/dashboards/CreateDashboard_578885732.go new file mode 100644 index 00000000000..ca1c47b6c2c --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_578885732.go @@ -0,0 +1,84 @@ +// Create a new dashboard with a formulas and functions change widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_a_formulas_and_functions_change_widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + ChangeWidgetDefinition: &datadog.ChangeWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Time: &datadog.WidgetTime{}, + Type: datadog.CHANGEWIDGETDEFINITIONTYPE_CHANGE, + Requests: []datadog.ChangeWidgetRequest{ + datadog.ChangeWidgetRequest{ + Formulas: &[]datadog.WidgetFormula{ + datadog.WidgetFormula{ + Formula: "hour_before(query1)", + }, + datadog.WidgetFormula{ + Formula: "query1", + }, + }, + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionEventQueryDefinition: &datadog.FormulaAndFunctionEventQueryDefinition{ + DataSource: datadog.FORMULAANDFUNCTIONEVENTSDATASOURCE_LOGS, + Name: "query1", + Search: &datadog.FormulaAndFunctionEventQueryDefinitionSearch{ + Query: "", + }, + Indexes: &[]string{ + "*", + }, + Compute: datadog.FormulaAndFunctionEventQueryDefinitionCompute{ + Aggregation: datadog.FORMULAANDFUNCTIONEVENTAGGREGATION_COUNT, + }, + GroupBy: &[]datadog.FormulaAndFunctionEventQueryGroupBy{}, + }}, + }, + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + CompareTo: datadog.WIDGETCOMPARETO_HOUR_BEFORE.Ptr(), + IncreaseGood: datadog.PtrBool(true), + OrderBy: datadog.WIDGETORDERBY_CHANGE.Ptr(), + ChangeType: datadog.WIDGETCHANGETYPE_ABSOLUTE.Ptr(), + OrderDir: datadog.WIDGETSORT_DESCENDING.Ptr(), + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 4, + }, + }, + }, + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_798168180.go b/examples/v1/dashboards/CreateDashboard_798168180.go new file mode 100644 index 00000000000..1c163ac56d3 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_798168180.go @@ -0,0 +1,67 @@ +// Create a new dashboard with apm dependency stats widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_apm_dependency_stats_widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + TableWidgetDefinition: &datadog.TableWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadog.TABLEWIDGETDEFINITIONTYPE_QUERY_TABLE, + Requests: []datadog.TableWidgetRequest{ + datadog.TableWidgetRequest{ + ResponseFormat: datadog.FORMULAANDFUNCTIONRESPONSEFORMAT_SCALAR.Ptr(), + Queries: &[]datadog.FormulaAndFunctionQueryDefinition{ + datadog.FormulaAndFunctionQueryDefinition{ + FormulaAndFunctionApmDependencyStatsQueryDefinition: &datadog.FormulaAndFunctionApmDependencyStatsQueryDefinition{ + PrimaryTagValue: datadog.PtrString("edge-eu1.prod.dog"), + Stat: datadog.FORMULAANDFUNCTIONAPMDEPENDENCYSTATNAME_AVG_DURATION, + ResourceName: "DELETE FROM monitor_history.monitor_state_change_history WHERE org_id = ? AND monitor_id IN ? AND group = ?", + Name: "query1", + Service: "cassandra", + DataSource: datadog.FORMULAANDFUNCTIONAPMDEPENDENCYSTATSDATASOURCE_APM_DEPENDENCY_STATS, + Env: "ci", + PrimaryTagName: datadog.PtrString("datacenter"), + OperationName: "cassandra.query", + }}, + }, + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 4, + }, + }, + }, + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_803346562.go b/examples/v1/dashboards/CreateDashboard_803346562.go new file mode 100644 index 00000000000..ff7c06ec373 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_803346562.go @@ -0,0 +1,59 @@ +// Create a new dashboard with distribution widget and apm stats data + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + Title: "Example-Create_a_new_dashboard_with_distribution_widget_and_apm_stats_data", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + DistributionWidgetDefinition: &datadog.DistributionWidgetDefinition{ + Title: datadog.PtrString(""), + TitleSize: datadog.PtrString("16"), + TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(), + Type: datadog.DISTRIBUTIONWIDGETDEFINITIONTYPE_DISTRIBUTION, + Requests: []datadog.DistributionWidgetRequest{ + datadog.DistributionWidgetRequest{ + ApmStatsQuery: &datadog.ApmStatsQueryDefinition{ + Env: "prod", + Service: "cassandra", + Name: "cassandra.query", + PrimaryTag: "datacenter:dc1", + RowType: datadog.APMSTATSQUERYROWTYPE_SERVICE, + }, + }, + }, + }}, + Layout: &datadog.WidgetLayout{ + X: 0, + Y: 0, + Width: 4, + Height: 4, + }, + }, + }, + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/dashboards/CreateDashboard_927141680.go b/examples/v1/dashboards/CreateDashboard_927141680.go new file mode 100644 index 00000000000..779ff1e9907 --- /dev/null +++ b/examples/v1/dashboards/CreateDashboard_927141680.go @@ -0,0 +1,49 @@ +// Create a new dashboard with funnel widget + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Dashboard{ + LayoutType: datadog.DASHBOARDLAYOUTTYPE_ORDERED, + Title: "Example-Create_a_new_dashboard_with_funnel_widget with funnel widget", + Widgets: []datadog.Widget{ + datadog.Widget{ + Definition: datadog.WidgetDefinition{ + FunnelWidgetDefinition: &datadog.FunnelWidgetDefinition{ + Type: datadog.FUNNELWIDGETDEFINITIONTYPE_FUNNEL, + Requests: []datadog.FunnelWidgetRequest{ + datadog.FunnelWidgetRequest{ + Query: datadog.FunnelQuery{ + DataSource: datadog.FUNNELSOURCE_RUM, + QueryString: "", + Steps: []interface{}{}, + }, + RequestType: datadog.FUNNELREQUESTTYPE_FUNNEL, + }, + }, + }}, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DashboardsApi.CreateDashboard(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent) +} diff --git a/examples/v1/downtimes/CreateDowntime_1393233946.go b/examples/v1/downtimes/CreateDowntime_1393233946.go new file mode 100644 index 00000000000..7fd3815516c --- /dev/null +++ b/examples/v1/downtimes/CreateDowntime_1393233946.go @@ -0,0 +1,49 @@ +// Schedule a downtime with until occurrences + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Downtime{ + Message: datadog.PtrString("Example-Schedule_a_downtime_with_until_occurrences"), + Recurrence: *datadog.NewNullableDowntimeRecurrence(&datadog.DowntimeRecurrence{ + Period: datadog.PtrInt32(1), + Type: datadog.PtrString("weeks"), + UntilOccurrences: *datadog.NewNullableInt32(datadog.PtrInt32(3)), + WeekDays: &[]string{ + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + }, + }), + Scope: &[]string{ + "*", + }, + Start: datadog.PtrInt64(time.Now().Unix()), + End: *datadog.NewNullableInt64(datadog.PtrInt64(time.Now().Add(time.Hour * 1).Unix())), + Timezone: datadog.PtrString("Etc/UTC"), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DowntimesApi.CreateDowntime(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DowntimesApi.CreateDowntime`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DowntimesApi.CreateDowntime`:\n%s\n", responseContent) +} diff --git a/examples/v1/downtimes/CreateDowntime_2908359488.go b/examples/v1/downtimes/CreateDowntime_2908359488.go new file mode 100644 index 00000000000..e815ea51e7b --- /dev/null +++ b/examples/v1/downtimes/CreateDowntime_2908359488.go @@ -0,0 +1,49 @@ +// Schedule a downtime until date + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Downtime{ + Message: datadog.PtrString("Example-Schedule_a_downtime_until_date"), + Recurrence: *datadog.NewNullableDowntimeRecurrence(&datadog.DowntimeRecurrence{ + Period: datadog.PtrInt32(1), + Type: datadog.PtrString("weeks"), + UntilDate: *datadog.NewNullableInt64(datadog.PtrInt64(time.Now().AddDate(0, 0, 21).Unix())), + WeekDays: &[]string{ + "Mon", + "Tue", + "Wed", + "Thu", + "Fri", + }, + }), + Scope: &[]string{ + "*", + }, + Start: datadog.PtrInt64(time.Now().Unix()), + End: *datadog.NewNullableInt64(datadog.PtrInt64(time.Now().Add(time.Hour * 1).Unix())), + Timezone: datadog.PtrString("Etc/UTC"), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DowntimesApi.CreateDowntime(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DowntimesApi.CreateDowntime`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DowntimesApi.CreateDowntime`:\n%s\n", responseContent) +} diff --git a/examples/v1/downtimes/CreateDowntime_3059354445.go b/examples/v1/downtimes/CreateDowntime_3059354445.go new file mode 100644 index 00000000000..17299bf0611 --- /dev/null +++ b/examples/v1/downtimes/CreateDowntime_3059354445.go @@ -0,0 +1,41 @@ +// Schedule a downtime once a year + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Downtime{ + Message: datadog.PtrString("Example-Schedule_a_downtime_once_a_year"), + Recurrence: *datadog.NewNullableDowntimeRecurrence(&datadog.DowntimeRecurrence{ + Period: datadog.PtrInt32(1), + Type: datadog.PtrString("years"), + }), + Scope: &[]string{ + "*", + }, + Start: datadog.PtrInt64(time.Now().Unix()), + End: *datadog.NewNullableInt64(datadog.PtrInt64(time.Now().Add(time.Hour * 1).Unix())), + Timezone: datadog.PtrString("Etc/UTC"), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DowntimesApi.CreateDowntime(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DowntimesApi.CreateDowntime`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DowntimesApi.CreateDowntime`:\n%s\n", responseContent) +} diff --git a/examples/v1/downtimes/CreateDowntime_3355644446.go b/examples/v1/downtimes/CreateDowntime_3355644446.go new file mode 100644 index 00000000000..4c14ab6690b --- /dev/null +++ b/examples/v1/downtimes/CreateDowntime_3355644446.go @@ -0,0 +1,41 @@ +// Schedule a monitor downtime returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "strconv" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + // there is a valid "monitor" in the system + MONITOR_ID, _ := strconv.ParseInt(os.Getenv("MONITOR_ID"), 10, 64) + + body := datadog.Downtime{ + Message: datadog.PtrString("Example-Schedule_a_monitor_downtime_returns_OK_response"), + Start: datadog.PtrInt64(time.Now().Unix()), + Timezone: datadog.PtrString("Etc/UTC"), + Scope: &[]string{ + "test:examplescheduleamonitordowntimereturnsokresponse", + }, + MonitorId: *datadog.NewNullableInt64(datadog.PtrInt64(MONITOR_ID)), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.DowntimesApi.CreateDowntime(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `DowntimesApi.CreateDowntime`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `DowntimesApi.CreateDowntime`:\n%s\n", responseContent) +} diff --git a/examples/v1/events/CreateEvent_19927815.go b/examples/v1/events/CreateEvent_19927815.go new file mode 100644 index 00000000000..7116339014f --- /dev/null +++ b/examples/v1/events/CreateEvent_19927815.go @@ -0,0 +1,34 @@ +// Post an event with a long title returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.EventCreateRequest{ + Title: "Example-Post_an_event_with_a_long_title_returns_OK_response very very very looooooooong looooooooooooong loooooooooooooooooooooong looooooooooooooooooooooooooong title with 100+ characters", + Text: "A text message.", + Tags: &[]string{ + "test:ExamplePostaneventwithalongtitlereturnsOKresponse", + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.EventsApi.CreateEvent(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `EventsApi.CreateEvent`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `EventsApi.CreateEvent`:\n%s\n", responseContent) +} diff --git a/examples/v1/logs/SubmitLog_1920474053.go b/examples/v1/logs/SubmitLog_1920474053.go new file mode 100644 index 00000000000..1b7105ba5fd --- /dev/null +++ b/examples/v1/logs/SubmitLog_1920474053.go @@ -0,0 +1,33 @@ +// Send gzip logs returns "Response from server (always 200 empty JSON)." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := []datadog.HTTPLogItem{ + datadog.HTTPLogItem{ + Message: datadog.PtrString("Example-Send_gzip_logs_returns_Response_from_server_always_200_empty_JSON_response"), + Ddtags: datadog.PtrString("host:ExampleSendgziplogsreturnsResponsefromserveralways200emptyJSONresponse"), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.LogsApi.SubmitLog(ctx, body, *datadog.NewSubmitLogOptionalParameters().WithContentEncoding(datadog.CONTENTENCODING_GZIP)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.SubmitLog`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsApi.SubmitLog`:\n%s\n", responseContent) +} diff --git a/examples/v1/logs/SubmitLog_3418823904.go b/examples/v1/logs/SubmitLog_3418823904.go new file mode 100644 index 00000000000..dacb5b88dc4 --- /dev/null +++ b/examples/v1/logs/SubmitLog_3418823904.go @@ -0,0 +1,33 @@ +// Send deflate logs returns "Response from server (always 200 empty JSON)." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := []datadog.HTTPLogItem{ + datadog.HTTPLogItem{ + Message: datadog.PtrString("Example-Send_deflate_logs_returns_Response_from_server_always_200_empty_JSON_response"), + Ddtags: datadog.PtrString("host:ExampleSenddeflatelogsreturnsResponsefromserveralways200emptyJSONresponse"), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.LogsApi.SubmitLog(ctx, body, *datadog.NewSubmitLogOptionalParameters().WithContentEncoding(datadog.CONTENTENCODING_DEFLATE)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.SubmitLog`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsApi.SubmitLog`:\n%s\n", responseContent) +} diff --git a/examples/v1/metrics/SubmitMetrics_2203981258.go b/examples/v1/metrics/SubmitMetrics_2203981258.go new file mode 100644 index 00000000000..6192b9e69b4 --- /dev/null +++ b/examples/v1/metrics/SubmitMetrics_2203981258.go @@ -0,0 +1,45 @@ +// Submit deflate metrics returns "Payload accepted" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.MetricsPayload{ + Series: []datadog.Series{ + datadog.Series{ + Metric: "system.load.1", + Type: datadog.PtrString("gauge"), + Points: [][]*float64{ + { + datadog.PtrFloat64(float64(time.Now().Unix())), + datadog.PtrFloat64(1.1), + }, + }, + Tags: &[]string{ + "test:ExampleSubmitdeflatemetricsreturnsPayloadacceptedresponse", + }, + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.MetricsApi.SubmitMetrics(ctx, body, *datadog.NewSubmitMetricsOptionalParameters().WithContentEncoding(datadog.METRICCONTENTENCODING_DEFLATE)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MetricsApi.SubmitMetrics`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MetricsApi.SubmitMetrics`:\n%s\n", responseContent) +} diff --git a/examples/v1/monitors/CreateMonitor_3790803616.go b/examples/v1/monitors/CreateMonitor_3790803616.go new file mode 100644 index 00000000000..2a690902f72 --- /dev/null +++ b/examples/v1/monitors/CreateMonitor_3790803616.go @@ -0,0 +1,43 @@ +// Create a ci-pipelines monitor returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.Monitor{ + Name: datadog.PtrString("Example-Create_a_ci_pipelines_monitor_returns_OK_response"), + Type: datadog.MONITORTYPE_CI_PIPELINES_ALERT, + Query: `ci-pipelines("ci_level:pipeline @git.branch:staging* @ci.status:error").rollup("count").by("@git.branch,@ci.pipeline.name").last("5m") >= 1`, + Message: datadog.PtrString("some message Notify: @hipchat-channel"), + Tags: &[]string{ + "test:examplecreateacipipelinesmonitorreturnsokresponse", + "env:ci", + }, + Priority: *datadog.NewNullableInt64(datadog.PtrInt64(3)), + Options: &datadog.MonitorOptions{ + Thresholds: &datadog.MonitorThresholds{ + Critical: datadog.PtrFloat64(1), + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.MonitorsApi.CreateMonitor(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.CreateMonitor`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.CreateMonitor`:\n%s\n", responseContent) +} diff --git a/examples/v1/monitors/GetMonitor_3691711704.go b/examples/v1/monitors/GetMonitor_3691711704.go new file mode 100644 index 00000000000..364390416fb --- /dev/null +++ b/examples/v1/monitors/GetMonitor_3691711704.go @@ -0,0 +1,31 @@ +// Get a synthetics monitor's details + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "strconv" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + // there is a valid "synthetics_api_test" in the system + SYNTHETICS_API_TEST_MONITOR_ID, _ := strconv.ParseInt(os.Getenv("SYNTHETICS_API_TEST_MONITOR_ID"), 10, 64) + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.MonitorsApi.GetMonitor(ctx, SYNTHETICS_API_TEST_MONITOR_ID, *datadog.NewGetMonitorOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.GetMonitor`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.GetMonitor`:\n%s\n", responseContent) +} diff --git a/examples/v1/service-level-objective-corrections/CreateSLOCorrection_1326388368.go b/examples/v1/service-level-objective-corrections/CreateSLOCorrection_1326388368.go new file mode 100644 index 00000000000..bea69130fc6 --- /dev/null +++ b/examples/v1/service-level-objective-corrections/CreateSLOCorrection_1326388368.go @@ -0,0 +1,46 @@ +// Create an SLO correction with rrule returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + // there is a valid "slo" in the system + SLO_DATA_0_ID := os.Getenv("SLO_DATA_0_ID") + + body := datadog.SLOCorrectionCreateRequest{ + Data: &datadog.SLOCorrectionCreateData{ + Attributes: &datadog.SLOCorrectionCreateRequestAttributes{ + Category: datadog.SLOCORRECTIONCATEGORY_SCHEDULED_MAINTENANCE, + Description: datadog.PtrString("Example-Create_an_SLO_correction_with_rrule_returns_OK_response"), + SloId: SLO_DATA_0_ID, + Start: time.Now().Unix(), + Duration: datadog.PtrInt64(3600), + Rrule: datadog.PtrString("FREQ=DAILY;INTERVAL=10;COUNT=5"), + Timezone: datadog.PtrString("UTC"), + }, + Type: datadog.SLOCORRECTIONTYPE_CORRECTION, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("CreateSLOCorrection", true) + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.ServiceLevelObjectiveCorrectionsApi.CreateSLOCorrection(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceLevelObjectiveCorrectionsApi.CreateSLOCorrection`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `ServiceLevelObjectiveCorrectionsApi.CreateSLOCorrection`:\n%s\n", responseContent) +} diff --git a/examples/v1/synthetics/CreateSyntheticsAPITest_2472747642.go b/examples/v1/synthetics/CreateSyntheticsAPITest_2472747642.go new file mode 100644 index 00000000000..2a784ad7720 --- /dev/null +++ b/examples/v1/synthetics/CreateSyntheticsAPITest_2472747642.go @@ -0,0 +1,74 @@ +// Create an API test with WEBSOCKET subtype returns "OK - Returns the created test details." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.SyntheticsAPITest{ + Config: &datadog.SyntheticsAPITestConfig{ + Assertions: &[]datadog.SyntheticsAssertion{ + datadog.SyntheticsAssertion{ + SyntheticsAssertionTarget: &datadog.SyntheticsAssertionTarget{ + Operator: datadog.SYNTHETICSASSERTIONOPERATOR_IS, + Target: "message", + Type: datadog.SYNTHETICSASSERTIONTYPE_RECEIVED_MESSAGE, + }}, + datadog.SyntheticsAssertion{ + SyntheticsAssertionTarget: &datadog.SyntheticsAssertionTarget{ + Operator: datadog.SYNTHETICSASSERTIONOPERATOR_LESS_THAN, + Target: 2000, + Type: datadog.SYNTHETICSASSERTIONTYPE_RESPONSE_TIME, + }}, + }, + ConfigVariables: &[]datadog.SyntheticsConfigVariable{}, + Request: &datadog.SyntheticsTestRequest{ + Url: datadog.PtrString("ws://datadoghq.com"), + Message: datadog.PtrString("message"), + }, + }, + Locations: &[]string{ + "aws:us-east-2", + }, + Message: datadog.PtrString("BDD test payload: synthetics_api_test_websocket_payload.json"), + Name: datadog.PtrString("Example-Create_an_API_test_with_WEBSOCKET_subtype_returns_OK_Returns_the_created_test_details_response"), + Options: &datadog.SyntheticsTestOptions{ + AcceptSelfSigned: datadog.PtrBool(false), + AllowInsecure: datadog.PtrBool(true), + FollowRedirects: datadog.PtrBool(true), + MinFailureDuration: datadog.PtrInt64(10), + MinLocationFailed: datadog.PtrInt64(1), + MonitorName: datadog.PtrString("Example-Create_an_API_test_with_WEBSOCKET_subtype_returns_OK_Returns_the_created_test_details_response"), + MonitorPriority: datadog.PtrInt32(5), + Retry: &datadog.SyntheticsTestOptionsRetry{ + Count: datadog.PtrInt64(3), + Interval: datadog.PtrFloat64(10), + }, + TickEvery: datadog.PtrInt64(60), + }, + Subtype: datadog.SYNTHETICSTESTDETAILSSUBTYPE_WEBSOCKET.Ptr(), + Tags: &[]string{ + "testing:api", + }, + Type: datadog.SYNTHETICSAPITESTTYPE_API.Ptr(), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.SyntheticsApi.CreateSyntheticsAPITest(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SyntheticsApi.CreateSyntheticsAPITest`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SyntheticsApi.CreateSyntheticsAPITest`:\n%s\n", responseContent) +} diff --git a/examples/v1/synthetics/CreateSyntheticsAPITest_3829801148.go b/examples/v1/synthetics/CreateSyntheticsAPITest_3829801148.go new file mode 100644 index 00000000000..a7f041225ae --- /dev/null +++ b/examples/v1/synthetics/CreateSyntheticsAPITest_3829801148.go @@ -0,0 +1,75 @@ +// Create an API test with UDP subtype returns "OK - Returns the created test details." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + body := datadog.SyntheticsAPITest{ + Config: &datadog.SyntheticsAPITestConfig{ + Assertions: &[]datadog.SyntheticsAssertion{ + datadog.SyntheticsAssertion{ + SyntheticsAssertionTarget: &datadog.SyntheticsAssertionTarget{ + Operator: datadog.SYNTHETICSASSERTIONOPERATOR_IS, + Target: "message", + Type: datadog.SYNTHETICSASSERTIONTYPE_RECEIVED_MESSAGE, + }}, + datadog.SyntheticsAssertion{ + SyntheticsAssertionTarget: &datadog.SyntheticsAssertionTarget{ + Operator: datadog.SYNTHETICSASSERTIONOPERATOR_LESS_THAN, + Target: 2000, + Type: datadog.SYNTHETICSASSERTIONTYPE_RESPONSE_TIME, + }}, + }, + ConfigVariables: &[]datadog.SyntheticsConfigVariable{}, + Request: &datadog.SyntheticsTestRequest{ + Host: datadog.PtrString("https://datadoghq.com"), + Message: datadog.PtrString("message"), + Port: datadog.PtrInt64(443), + }, + }, + Locations: &[]string{ + "aws:us-east-2", + }, + Message: datadog.PtrString("BDD test payload: synthetics_api_test_udp_payload.json"), + Name: datadog.PtrString("Example-Create_an_API_test_with_UDP_subtype_returns_OK_Returns_the_created_test_details_response"), + Options: &datadog.SyntheticsTestOptions{ + AcceptSelfSigned: datadog.PtrBool(false), + AllowInsecure: datadog.PtrBool(true), + FollowRedirects: datadog.PtrBool(true), + MinFailureDuration: datadog.PtrInt64(10), + MinLocationFailed: datadog.PtrInt64(1), + MonitorName: datadog.PtrString("Example-Create_an_API_test_with_UDP_subtype_returns_OK_Returns_the_created_test_details_response"), + MonitorPriority: datadog.PtrInt32(5), + Retry: &datadog.SyntheticsTestOptionsRetry{ + Count: datadog.PtrInt64(3), + Interval: datadog.PtrFloat64(10), + }, + TickEvery: datadog.PtrInt64(60), + }, + Subtype: datadog.SYNTHETICSTESTDETAILSSUBTYPE_UDP.Ptr(), + Tags: &[]string{ + "testing:api", + }, + Type: datadog.SYNTHETICSAPITESTTYPE_API.Ptr(), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.SyntheticsApi.CreateSyntheticsAPITest(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SyntheticsApi.CreateSyntheticsAPITest`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SyntheticsApi.CreateSyntheticsAPITest`:\n%s\n", responseContent) +} diff --git a/examples/v1/synthetics/ListTests_2779190961.go b/examples/v1/synthetics/ListTests_2779190961.go new file mode 100644 index 00000000000..3dcc9290514 --- /dev/null +++ b/examples/v1/synthetics/ListTests_2779190961.go @@ -0,0 +1,27 @@ +// Client is resilient to enum and oneOf deserialization errors + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.SyntheticsApi.ListTests(ctx) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SyntheticsApi.ListTests`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SyntheticsApi.ListTests`:\n%s\n", responseContent) +} diff --git a/examples/v2/key-management/CreateCurrentUserApplicationKey_1999509896.go b/examples/v2/key-management/CreateCurrentUserApplicationKey_1999509896.go new file mode 100644 index 00000000000..b8a910e39dc --- /dev/null +++ b/examples/v2/key-management/CreateCurrentUserApplicationKey_1999509896.go @@ -0,0 +1,35 @@ +// Create an Application key for current user returns "Created" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + body := datadog.ApplicationKeyCreateRequest{ + Data: datadog.ApplicationKeyCreateData{ + Type: datadog.APPLICATIONKEYSTYPE_APPLICATION_KEYS, + Attributes: datadog.ApplicationKeyCreateAttributes{ + Name: "Example-Create_an_Application_key_for_current_user_returns_Created_response", + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.KeyManagementApi.CreateCurrentUserApplicationKey(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyManagementApi.CreateCurrentUserApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `KeyManagementApi.CreateCurrentUserApplicationKey`:\n%s\n", responseContent) +} diff --git a/examples/v2/key-management/DeleteApplicationKey_771691550.go b/examples/v2/key-management/DeleteApplicationKey_771691550.go new file mode 100644 index 00000000000..e79fe34a19c --- /dev/null +++ b/examples/v2/key-management/DeleteApplicationKey_771691550.go @@ -0,0 +1,26 @@ +// Delete an Application key returns "No Content" response + +package main + +import ( + "context" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "application_key" in the system + APPLICATION_KEY_DATA_ID := os.Getenv("APPLICATION_KEY_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + r, err := apiClient.KeyManagementApi.DeleteApplicationKey(ctx, APPLICATION_KEY_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyManagementApi.DeleteApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/key-management/DeleteCurrentUserApplicationKey_1266687064.go b/examples/v2/key-management/DeleteCurrentUserApplicationKey_1266687064.go new file mode 100644 index 00000000000..1500368f7d1 --- /dev/null +++ b/examples/v2/key-management/DeleteCurrentUserApplicationKey_1266687064.go @@ -0,0 +1,26 @@ +// Delete an Application key owned by current user returns "No Content" response + +package main + +import ( + "context" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "application_key" in the system + APPLICATION_KEY_DATA_ID := os.Getenv("APPLICATION_KEY_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + r, err := apiClient.KeyManagementApi.DeleteCurrentUserApplicationKey(ctx, APPLICATION_KEY_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyManagementApi.DeleteCurrentUserApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/key-management/GetCurrentUserApplicationKey_1060640890.go b/examples/v2/key-management/GetCurrentUserApplicationKey_1060640890.go new file mode 100644 index 00000000000..797b656ef68 --- /dev/null +++ b/examples/v2/key-management/GetCurrentUserApplicationKey_1060640890.go @@ -0,0 +1,30 @@ +// Get one Application key owned by current user returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "application_key" in the system + APPLICATION_KEY_DATA_ID := os.Getenv("APPLICATION_KEY_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.KeyManagementApi.GetCurrentUserApplicationKey(ctx, APPLICATION_KEY_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyManagementApi.GetCurrentUserApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `KeyManagementApi.GetCurrentUserApplicationKey`:\n%s\n", responseContent) +} diff --git a/examples/v2/key-management/ListApplicationKeys_2237010090.go b/examples/v2/key-management/ListApplicationKeys_2237010090.go new file mode 100644 index 00000000000..2339fd48464 --- /dev/null +++ b/examples/v2/key-management/ListApplicationKeys_2237010090.go @@ -0,0 +1,27 @@ +// Get all Application keys returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.KeyManagementApi.ListApplicationKeys(ctx, *datadog.NewListApplicationKeysOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyManagementApi.ListApplicationKeys`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `KeyManagementApi.ListApplicationKeys`:\n%s\n", responseContent) +} diff --git a/examples/v2/key-management/ListCurrentUserApplicationKeys_1503860964.go b/examples/v2/key-management/ListCurrentUserApplicationKeys_1503860964.go new file mode 100644 index 00000000000..bc21f5b35ab --- /dev/null +++ b/examples/v2/key-management/ListCurrentUserApplicationKeys_1503860964.go @@ -0,0 +1,27 @@ +// Get all Application keys owned by current user returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.KeyManagementApi.ListCurrentUserApplicationKeys(ctx, *datadog.NewListCurrentUserApplicationKeysOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `KeyManagementApi.ListCurrentUserApplicationKeys`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `KeyManagementApi.ListCurrentUserApplicationKeys`:\n%s\n", responseContent) +} diff --git a/examples/v2/logs/AggregateLogs_2527007002.go b/examples/v2/logs/AggregateLogs_2527007002.go new file mode 100644 index 00000000000..e9227eb16c4 --- /dev/null +++ b/examples/v2/logs/AggregateLogs_2527007002.go @@ -0,0 +1,44 @@ +// Aggregate compute events returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + body := datadog.LogsAggregateRequest{ + Compute: &[]datadog.LogsCompute{ + datadog.LogsCompute{ + Aggregation: datadog.LOGSAGGREGATIONFUNCTION_COUNT, + Interval: datadog.PtrString("5m"), + Type: datadog.LOGSCOMPUTETYPE_TIMESERIES.Ptr(), + }, + }, + Filter: &datadog.LogsQueryFilter{ + From: datadog.PtrString("now-15m"), + Indexes: &[]string{ + "main", + }, + Query: datadog.PtrString("*"), + To: datadog.PtrString("now"), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.LogsApi.AggregateLogs(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.AggregateLogs`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsApi.AggregateLogs`:\n%s\n", responseContent) +} diff --git a/examples/v2/logs/ListLogsGet_2034110533.go b/examples/v2/logs/ListLogsGet_2034110533.go new file mode 100644 index 00000000000..941cc94a6cd --- /dev/null +++ b/examples/v2/logs/ListLogsGet_2034110533.go @@ -0,0 +1,28 @@ +// Get a quick list of logs returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + "time" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.LogsApi.ListLogsGet(ctx, *datadog.NewListLogsGetOptionalParameters().WithFilterQuery("datadog-agent").WithFilterIndex("main").WithFilterFrom(time.Date(2020, 9, 17, 11, 48, 36, 0, time.UTC)).WithFilterTo(time.Date(2020, 9, 17, 12, 48, 36, 0, time.UTC)).WithPageLimit(5)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.ListLogsGet`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsApi.ListLogsGet`:\n%s\n", responseContent) +} diff --git a/examples/v2/logs/SubmitLog_3496222707.go b/examples/v2/logs/SubmitLog_3496222707.go new file mode 100644 index 00000000000..253e210112d --- /dev/null +++ b/examples/v2/logs/SubmitLog_3496222707.go @@ -0,0 +1,36 @@ +// Send gzip logs returns "Request accepted for processing (always 202 empty JSON)." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + body := []datadog.HTTPLogItem{ + datadog.HTTPLogItem{ + Ddsource: datadog.PtrString("nginx"), + Ddtags: datadog.PtrString("env:staging,version:5.1"), + Hostname: datadog.PtrString("i-012345678"), + Message: datadog.PtrString("2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World"), + Service: datadog.PtrString("payment"), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.LogsApi.SubmitLog(ctx, body, *datadog.NewSubmitLogOptionalParameters().WithContentEncoding(datadog.CONTENTENCODING_GZIP)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.SubmitLog`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsApi.SubmitLog`:\n%s\n", responseContent) +} diff --git a/examples/v2/logs/SubmitLog_904601870.go b/examples/v2/logs/SubmitLog_904601870.go new file mode 100644 index 00000000000..3fd61980957 --- /dev/null +++ b/examples/v2/logs/SubmitLog_904601870.go @@ -0,0 +1,36 @@ +// Send deflate logs returns "Request accepted for processing (always 202 empty JSON)." response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + body := []datadog.HTTPLogItem{ + datadog.HTTPLogItem{ + Ddsource: datadog.PtrString("nginx"), + Ddtags: datadog.PtrString("env:staging,version:5.1"), + Hostname: datadog.PtrString("i-012345678"), + Message: datadog.PtrString("2019-11-19T14:37:58,995 INFO [process.name][20081] Hello World"), + Service: datadog.PtrString("payment"), + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.LogsApi.SubmitLog(ctx, body, *datadog.NewSubmitLogOptionalParameters().WithContentEncoding(datadog.CONTENTENCODING_DEFLATE)) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `LogsApi.SubmitLog`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `LogsApi.SubmitLog`:\n%s\n", responseContent) +} diff --git a/examples/v2/metrics/ListTagConfigurations_1799362914.go b/examples/v2/metrics/ListTagConfigurations_1799362914.go new file mode 100644 index 00000000000..d28e05da95d --- /dev/null +++ b/examples/v2/metrics/ListTagConfigurations_1799362914.go @@ -0,0 +1,28 @@ +// List tag configurations with a tag filter returns "Success" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + configuration.SetUnstableOperationEnabled("ListTagConfigurations", true) + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.MetricsApi.ListTagConfigurations(ctx, *datadog.NewListTagConfigurationsOptionalParameters().WithFilterTags("ExampleListtagconfigurationswithatagfilterreturnsSuccessresponse")) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `MetricsApi.ListTagConfigurations`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `MetricsApi.ListTagConfigurations`:\n%s\n", responseContent) +} diff --git a/examples/v2/security-monitoring/CreateSecurityMonitoringRule_498211763.go b/examples/v2/security-monitoring/CreateSecurityMonitoringRule_498211763.go new file mode 100644 index 00000000000..c32d9bd5c8c --- /dev/null +++ b/examples/v2/security-monitoring/CreateSecurityMonitoringRule_498211763.go @@ -0,0 +1,61 @@ +// Create a detection rule with type 'workload_security' returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + body := datadog.SecurityMonitoringRuleCreatePayload{ + Name: "Example-Create_a_detection_rule_with_type_workload_security_returns_OK_response", + Queries: []datadog.SecurityMonitoringRuleQueryCreate{ + datadog.SecurityMonitoringRuleQueryCreate{ + Query: "@test:true", + Aggregation: datadog.SECURITYMONITORINGRULEQUERYAGGREGATION_COUNT.Ptr(), + GroupByFields: &[]string{}, + DistinctFields: &[]string{}, + Metric: datadog.PtrString(""), + AgentRule: &datadog.SecurityMonitoringRuntimeAgentRule{ + AgentRuleId: datadog.PtrString("kernel_module_unlink_2"), + Expression: datadog.PtrString("(open.flags & ((O_CREAT|O_RDWR|O_WRONLY|O_TRUNC)) > 0)"), + }, + }, + }, + Filters: &[]datadog.SecurityMonitoringFilter{}, + Cases: []datadog.SecurityMonitoringRuleCaseCreate{ + datadog.SecurityMonitoringRuleCaseCreate{ + Name: datadog.PtrString(""), + Status: datadog.SECURITYMONITORINGRULESEVERITY_INFO, + Condition: datadog.PtrString("a > 0"), + Notifications: &[]string{}, + }, + }, + Options: datadog.SecurityMonitoringRuleOptions{ + EvaluationWindow: datadog.SECURITYMONITORINGRULEEVALUATIONWINDOW_FIFTEEN_MINUTES.Ptr(), + KeepAlive: datadog.SECURITYMONITORINGRULEKEEPALIVE_ONE_HOUR.Ptr(), + MaxSignalDuration: datadog.SECURITYMONITORINGRULEMAXSIGNALDURATION_ONE_DAY.Ptr(), + }, + Message: "Test rule", + Tags: &[]string{}, + IsEnabled: true, + Type: datadog.SECURITYMONITORINGRULETYPECREATE_WORKLOAD_SECURITY.Ptr(), + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.SecurityMonitoringApi.CreateSecurityMonitoringRule(ctx, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SecurityMonitoringApi.CreateSecurityMonitoringRule`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `SecurityMonitoringApi.CreateSecurityMonitoringRule`:\n%s\n", responseContent) +} diff --git a/examples/v2/security-monitoring/DeleteSecurityFilter_555029489.go b/examples/v2/security-monitoring/DeleteSecurityFilter_555029489.go new file mode 100644 index 00000000000..3eb842c5ce2 --- /dev/null +++ b/examples/v2/security-monitoring/DeleteSecurityFilter_555029489.go @@ -0,0 +1,26 @@ +// Delete a security filter returns "No Content" response + +package main + +import ( + "context" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "security_filter" in the system + SECURITY_FILTER_DATA_ID := os.Getenv("SECURITY_FILTER_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + r, err := apiClient.SecurityMonitoringApi.DeleteSecurityFilter(ctx, SECURITY_FILTER_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `SecurityMonitoringApi.DeleteSecurityFilter`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/service-accounts/CreateServiceAccountApplicationKey_1761876297.go b/examples/v2/service-accounts/CreateServiceAccountApplicationKey_1761876297.go new file mode 100644 index 00000000000..b26ba3447db --- /dev/null +++ b/examples/v2/service-accounts/CreateServiceAccountApplicationKey_1761876297.go @@ -0,0 +1,38 @@ +// Create an app key for this service account returns "Created" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "service_account_user" in the system + SERVICE_ACCOUNT_USER_DATA_ID := os.Getenv("SERVICE_ACCOUNT_USER_DATA_ID") + + body := datadog.ApplicationKeyCreateRequest{ + Data: datadog.ApplicationKeyCreateData{ + Attributes: datadog.ApplicationKeyCreateAttributes{ + Name: "Example-Create_an_app_key_for_this_service_account_returns_Created_response", + }, + Type: datadog.APPLICATIONKEYSTYPE_APPLICATION_KEYS, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.ServiceAccountsApi.CreateServiceAccountApplicationKey(ctx, SERVICE_ACCOUNT_USER_DATA_ID, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceAccountsApi.CreateServiceAccountApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `ServiceAccountsApi.CreateServiceAccountApplicationKey`:\n%s\n", responseContent) +} diff --git a/examples/v2/service-accounts/DeleteServiceAccountApplicationKey_992091161.go b/examples/v2/service-accounts/DeleteServiceAccountApplicationKey_992091161.go new file mode 100644 index 00000000000..b3a1ae2118a --- /dev/null +++ b/examples/v2/service-accounts/DeleteServiceAccountApplicationKey_992091161.go @@ -0,0 +1,29 @@ +// Delete an app key owned by this service account returns "No Content" response + +package main + +import ( + "context" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "service_account_user" in the system + SERVICE_ACCOUNT_USER_DATA_ID := os.Getenv("SERVICE_ACCOUNT_USER_DATA_ID") + + // there is a valid "service_account_application_key" for "service_account_user" + SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID := os.Getenv("SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + r, err := apiClient.ServiceAccountsApi.DeleteServiceAccountApplicationKey(ctx, SERVICE_ACCOUNT_USER_DATA_ID, SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceAccountsApi.DeleteServiceAccountApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } +} diff --git a/examples/v2/service-accounts/GetServiceAccountApplicationKey_819075131.go b/examples/v2/service-accounts/GetServiceAccountApplicationKey_819075131.go new file mode 100644 index 00000000000..bf5c47f5a04 --- /dev/null +++ b/examples/v2/service-accounts/GetServiceAccountApplicationKey_819075131.go @@ -0,0 +1,33 @@ +// Get one app key owned by this service account returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "service_account_user" in the system + SERVICE_ACCOUNT_USER_DATA_ID := os.Getenv("SERVICE_ACCOUNT_USER_DATA_ID") + + // there is a valid "service_account_application_key" for "service_account_user" + SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID := os.Getenv("SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.ServiceAccountsApi.GetServiceAccountApplicationKey(ctx, SERVICE_ACCOUNT_USER_DATA_ID, SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceAccountsApi.GetServiceAccountApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `ServiceAccountsApi.GetServiceAccountApplicationKey`:\n%s\n", responseContent) +} diff --git a/examples/v2/service-accounts/ListServiceAccountApplicationKeys_1268914341.go b/examples/v2/service-accounts/ListServiceAccountApplicationKeys_1268914341.go new file mode 100644 index 00000000000..9b0e23e12e0 --- /dev/null +++ b/examples/v2/service-accounts/ListServiceAccountApplicationKeys_1268914341.go @@ -0,0 +1,30 @@ +// Get all app keys owned by this service account returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "service_account_user" in the system + SERVICE_ACCOUNT_USER_DATA_ID := os.Getenv("SERVICE_ACCOUNT_USER_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.ServiceAccountsApi.ListServiceAccountApplicationKeys(ctx, SERVICE_ACCOUNT_USER_DATA_ID, *datadog.NewListServiceAccountApplicationKeysOptionalParameters()) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceAccountsApi.ListServiceAccountApplicationKeys`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `ServiceAccountsApi.ListServiceAccountApplicationKeys`:\n%s\n", responseContent) +} diff --git a/examples/v2/service-accounts/UpdateServiceAccountApplicationKey_768415790.go b/examples/v2/service-accounts/UpdateServiceAccountApplicationKey_768415790.go new file mode 100644 index 00000000000..eae1645b858 --- /dev/null +++ b/examples/v2/service-accounts/UpdateServiceAccountApplicationKey_768415790.go @@ -0,0 +1,42 @@ +// Edit an app key owned by this service account returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "service_account_user" in the system + SERVICE_ACCOUNT_USER_DATA_ID := os.Getenv("SERVICE_ACCOUNT_USER_DATA_ID") + + // there is a valid "service_account_application_key" for "service_account_user" + SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID := os.Getenv("SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID") + + body := datadog.ApplicationKeyUpdateRequest{ + Data: datadog.ApplicationKeyUpdateData{ + Id: SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID, + Type: datadog.APPLICATIONKEYSTYPE_APPLICATION_KEYS, + Attributes: datadog.ApplicationKeyUpdateAttributes{ + Name: "Application Key for submitting metrics-updated", + }, + }, + } + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.ServiceAccountsApi.UpdateServiceAccountApplicationKey(ctx, SERVICE_ACCOUNT_USER_DATA_ID, SERVICE_ACCOUNT_APPLICATION_KEY_DATA_ID, body) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `ServiceAccountsApi.UpdateServiceAccountApplicationKey`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `ServiceAccountsApi.UpdateServiceAccountApplicationKey`:\n%s\n", responseContent) +} diff --git a/examples/v2/users/GetUser_3047557953.go b/examples/v2/users/GetUser_3047557953.go new file mode 100644 index 00000000000..06189db2fff --- /dev/null +++ b/examples/v2/users/GetUser_3047557953.go @@ -0,0 +1,30 @@ +// Get a user returns "OK" response + +package main + +import ( + "context" + "encoding/json" + "fmt" + "os" + + datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog" +) + +func main() { + // there is a valid "user" in the system + USER_DATA_ID := os.Getenv("USER_DATA_ID") + + ctx := datadog.NewDefaultContext(context.Background()) + configuration := datadog.NewConfiguration() + apiClient := datadog.NewAPIClient(configuration) + resp, r, err := apiClient.UsersApi.GetUser(ctx, USER_DATA_ID) + + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `UsersApi.GetUser`: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + } + + responseContent, _ := json.MarshalIndent(resp, "", " ") + fmt.Fprintf(os.Stdout, "Response from `UsersApi.GetUser`:\n%s\n", responseContent) +}