Comprehensive Go API client for the Datadog monitoring and analytics platform with strongly-typed interfaces for all Datadog API v1 and v2 endpoints
Dashboard creation, management, and notebook functionality in API v1.
import (
"context"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)Create and manage dashboards with various widget types.
type DashboardsApi struct {
// contains filtered or unexported fields
}
func NewDashboardsApi(client *datadog.APIClient) *DashboardsApifunc (a *DashboardsApi) CreateDashboard(
ctx context.Context,
body datadogV1.Dashboard,
) (datadogV1.Dashboard, *http.Response, error)func (a *DashboardsApi) CreatePublicDashboard(
ctx context.Context,
body datadogV1.SharedDashboard,
) (datadogV1.SharedDashboard, *http.Response, error)func (a *DashboardsApi) DeleteDashboard(
ctx context.Context,
dashboardId string,
) (datadogV1.DashboardDeleteResponse, *http.Response, error)func (a *DashboardsApi) DeleteDashboards(
ctx context.Context,
body datadogV1.DashboardBulkDeleteRequest,
) (*http.Response, error)func (a *DashboardsApi) DeletePublicDashboard(
ctx context.Context,
token string,
) (datadogV1.DeleteSharedDashboardResponse, *http.Response, error)func (a *DashboardsApi) DeletePublicDashboardInvitation(
ctx context.Context,
token string,
body datadogV1.SharedDashboardInvites,
) (*http.Response, error)func (a *DashboardsApi) GetDashboard(
ctx context.Context,
dashboardId string,
) (datadogV1.Dashboard, *http.Response, error)func (a *DashboardsApi) GetPublicDashboard(
ctx context.Context,
token string,
) (datadogV1.SharedDashboard, *http.Response, error)func (a *DashboardsApi) GetPublicDashboardInvitations(
ctx context.Context,
token string,
o ...GetPublicDashboardInvitationsOptionalParameters,
) (datadogV1.SharedDashboardInvites, *http.Response, error)func (a *DashboardsApi) ListDashboards(
ctx context.Context,
o ...ListDashboardsOptionalParameters,
) (datadogV1.DashboardSummary, *http.Response, error)func (a *DashboardsApi) ListDashboardsWithPagination(
ctx context.Context,
o ...ListDashboardsOptionalParameters,
) (<-chan datadog.PaginationResult[datadogV1.Dashboard], func())func (a *DashboardsApi) RestoreDashboards(
ctx context.Context,
body datadogV1.DashboardRestoreRequest,
) (*http.Response, error)func (a *DashboardsApi) SendPublicDashboardInvitation(
ctx context.Context,
token string,
body datadogV1.SharedDashboardInvites,
) (datadogV1.SharedDashboardInvites, *http.Response, error)func (a *DashboardsApi) UpdateDashboard(
ctx context.Context,
dashboardId string,
body datadogV1.Dashboard,
) (datadogV1.Dashboard, *http.Response, error)func (a *DashboardsApi) UpdatePublicDashboard(
ctx context.Context,
token string,
body datadogV1.SharedDashboard,
) (datadogV1.SharedDashboard, *http.Response, error)type GetPublicDashboardInvitationsOptionalParameters struct {
PageSize *int64
PageNumber *int64
}
type ListDashboardsOptionalParameters struct {
FilterShared *bool
FilterDeleted *bool
Count *int64
Start *int64
FilterSharedWithCurrentUser *bool
}type Dashboard struct {
AuthorHandle *string
AuthorName NullableString
CreatedAt *time.Time
Description NullableString
Id *string
IsReadOnly *bool
LayoutType DashboardLayoutType
ModifiedAt *time.Time
NotifyList NullableList[string]
ReflowType *DashboardReflowType
RestrictedRoles []string
Tags NullableList[string]
TemplateVariablePresets NullableList[DashboardTemplateVariablePreset]
TemplateVariables NullableList[DashboardTemplateVariable]
Title string
Url *string
Widgets []Widget
}
func NewDashboard(layoutType DashboardLayoutType, title string, widgets []Widget) *Dashboardpackage main
import (
"context"
"fmt"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)
func main() {
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewDashboardsApi(apiClient)
// Create a timeseries widget
widgetDef := datadogV1.NewTimeseriesWidgetDefinition(
[]datadogV1.TimeseriesWidgetRequest{
{
Q: datadog.PtrString("avg:system.cpu.user{*}"),
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
},
},
datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
)
widgetDef.SetTitle("CPU Usage")
widget := datadogV1.Widget{}
widget.TimeseriesWidgetDefinition = widgetDef
// Create dashboard
dashboard := datadogV1.NewDashboard(
datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
"My Dashboard",
[]datadogV1.Widget{widget},
)
dashboard.SetDescription("System metrics dashboard")
resp, r, err := api.CreateDashboard(ctx, *dashboard)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return
}
fmt.Printf("Dashboard created: %s (ID: %s)\n", resp.GetTitle(), resp.GetId())
}Organize dashboards into lists.
type DashboardListsApi struct {
// contains filtered or unexported fields
}
func NewDashboardListsApi(client *datadog.APIClient) *DashboardListsApifunc (a *DashboardListsApi) CreateDashboardList(
ctx context.Context,
body datadogV1.DashboardList,
) (datadogV1.DashboardList, *http.Response, error)func (a *DashboardListsApi) DeleteDashboardList(
ctx context.Context,
listId int64,
) (datadogV1.DashboardListDeleteResponse, *http.Response, error)func (a *DashboardListsApi) GetDashboardList(
ctx context.Context,
listId int64,
) (datadogV1.DashboardList, *http.Response, error)func (a *DashboardListsApi) ListDashboardLists(
ctx context.Context,
) (datadogV1.DashboardListListResponse, *http.Response, error)func (a *DashboardListsApi) UpdateDashboardList(
ctx context.Context,
listId int64,
body datadogV1.DashboardList,
) (datadogV1.DashboardList, *http.Response, error)type DashboardList struct {
Author *Creator
Created *time.Time
DashboardCount *int32
Id *int64
IsFavorite *bool
Modified *time.Time
Name string
Type *string
}
func NewDashboardList(name string) *DashboardListCreate and manage interactive notebooks.
type NotebooksApi struct {
// contains filtered or unexported fields
}
func NewNotebooksApi(client *datadog.APIClient) *NotebooksApifunc (a *NotebooksApi) CreateNotebook(
ctx context.Context,
body datadogV1.NotebookCreateRequest,
) (datadogV1.NotebookResponse, *http.Response, error)func (a *NotebooksApi) DeleteNotebook(
ctx context.Context,
notebookId int64,
) (*http.Response, error)func (a *NotebooksApi) GetNotebook(
ctx context.Context,
notebookId int64,
) (datadogV1.NotebookResponse, *http.Response, error)func (a *NotebooksApi) ListNotebooks(
ctx context.Context,
o ...ListNotebooksOptionalParameters,
) (datadogV1.NotebooksResponse, *http.Response, error)func (a *NotebooksApi) ListNotebooksWithPagination(
ctx context.Context,
o ...ListNotebooksOptionalParameters,
) (<-chan datadog.PaginationResult[[]datadogV1.NotebooksResponseData], func())func (a *NotebooksApi) UpdateNotebook(
ctx context.Context,
notebookId int64,
body datadogV1.NotebookUpdateRequest,
) (datadogV1.NotebookResponse, *http.Response, error)type ListNotebooksOptionalParameters struct {
AuthorHandle *string
ExcludeAuthorHandle *string
Start *int64
Count *int64
SortField *string
SortDir *string
Query *string
IncludeCells *bool
IsTemplate *bool
Type *string
}type NotebookCreateRequest struct {
Data NotebookCreateData
}
type NotebookCreateData struct {
Attributes NotebookCreateDataAttributes
Type NotebookResourceType
}
type NotebookCreateDataAttributes struct {
Cells []NotebookCellCreateRequest
Metadata *NotebookMetadata
Name string
Status *NotebookStatus
Time NotebookGlobalTime
}
func NewNotebookCreateDataAttributes(
cells []NotebookCellCreateRequest,
name string,
time NotebookGlobalTime,
) *NotebookCreateDataAttributes// Create a notebook with a markdown cell
markdownCell := datadogV1.NotebookCellCreateRequest{
NotebookMarkdownCellDefinition: &datadogV1.NotebookMarkdownCellDefinition{
Text: "# My Notebook\n\nThis is a markdown cell.",
Type: datadogV1.NOTEBOOKMARKDOWNCELLATTRIBUTESTYPE_MARKDOWN,
},
}
attrs := datadogV1.NewNotebookCreateDataAttributes(
[]datadogV1.NotebookCellCreateRequest{markdownCell},
"System Analysis Notebook",
datadogV1.NotebookGlobalTime{
NotebookRelativeTime: &datadogV1.NotebookRelativeTime{
LiveSpan: datadogV1.WIDGETLIVESPAN_PAST_ONE_HOUR,
},
},
)
data := datadogV1.NewNotebookCreateData(*attrs, datadogV1.NOTEBOOKRESOURCETYPE_NOTEBOOKS)
req := datadogV1.NewNotebookCreateRequest(*data)
resp, r, err := notebooksApi.CreateNotebook(ctx, *req)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return
}
fmt.Printf("Notebook created: %s\n", resp.Data.Attributes.GetName())Install with Tessl CLI
npx tessl i tessl/golang-github-com-data-dog--datadog-api-client-go-v2