Comprehensive Go API client for the Datadog monitoring and analytics platform with strongly-typed interfaces for all Datadog API v1 and v2 endpoints
Monitoring and alerting capabilities in API v1, including monitors, downtimes, and service level objectives.
import (
"context"
"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)Manage monitors for alerting on metrics, logs, traces, and other data sources.
type MonitorsApi struct {
// contains filtered or unexported fields
}
func NewMonitorsApi(client *datadog.APIClient) *MonitorsApifunc (a *MonitorsApi) CheckCanDeleteMonitor(
ctx context.Context,
monitorIds []int64,
) (datadogV1.CheckCanDeleteMonitorResponse, *http.Response, error)Check if monitors can be deleted.
func (a *MonitorsApi) CreateMonitor(
ctx context.Context,
body datadogV1.Monitor,
) (datadogV1.Monitor, *http.Response, error)Create a new monitor.
func (a *MonitorsApi) DeleteMonitor(
ctx context.Context,
monitorId int64,
o ...DeleteMonitorOptionalParameters,
) (datadogV1.DeletedMonitor, *http.Response, error)Delete a monitor by ID.
func (a *MonitorsApi) GetMonitor(
ctx context.Context,
monitorId int64,
o ...GetMonitorOptionalParameters,
) (datadogV1.Monitor, *http.Response, error)Get a monitor's details by ID.
func (a *MonitorsApi) ListMonitors(
ctx context.Context,
o ...ListMonitorsOptionalParameters,
) ([]datadogV1.Monitor, *http.Response, error)List all monitors.
func (a *MonitorsApi) ListMonitorsWithPagination(
ctx context.Context,
o ...ListMonitorsOptionalParameters,
) (<-chan datadog.PaginationResult[[]datadogV1.Monitor], func())List all monitors with automatic pagination.
func (a *MonitorsApi) SearchMonitorGroups(
ctx context.Context,
o ...SearchMonitorGroupsOptionalParameters,
) (datadogV1.MonitorGroupSearchResponse, *http.Response, error)Search monitor groups.
func (a *MonitorsApi) SearchMonitors(
ctx context.Context,
o ...SearchMonitorsOptionalParameters,
) (datadogV1.MonitorSearchResponse, *http.Response, error)Search monitors.
func (a *MonitorsApi) UpdateMonitor(
ctx context.Context,
monitorId int64,
body datadogV1.MonitorUpdateRequest,
) (datadogV1.Monitor, *http.Response, error)Update an existing monitor.
func (a *MonitorsApi) ValidateMonitor(
ctx context.Context,
body datadogV1.Monitor,
) (interface{}, *http.Response, error)Validate a monitor configuration.
func (a *MonitorsApi) ValidateExistingMonitor(
ctx context.Context,
monitorId int64,
body datadogV1.Monitor,
) (interface{}, *http.Response, error)Validate an existing monitor configuration.
type DeleteMonitorOptionalParameters struct {
Force *string
}
func NewDeleteMonitorOptionalParameters() *DeleteMonitorOptionalParameters
func (r *DeleteMonitorOptionalParameters) WithForce(force string) *DeleteMonitorOptionalParameterstype GetMonitorOptionalParameters struct {
GroupStates *string
WithDowntimes *bool
}
func NewGetMonitorOptionalParameters() *GetMonitorOptionalParameters
func (r *GetMonitorOptionalParameters) WithGroupStates(groupStates string) *GetMonitorOptionalParameters
func (r *GetMonitorOptionalParameters) WithWithDowntimes(withDowntimes bool) *GetMonitorOptionalParameterstype ListMonitorsOptionalParameters struct {
GroupStates *string
Name *string
Tags *string
MonitorTags *string
WithDowntimes *bool
IdOffset *int64
PageSize *int64
Page *int64
}
func NewListMonitorsOptionalParameters() *ListMonitorsOptionalParameterstype SearchMonitorGroupsOptionalParameters struct {
Query *string
Page *int64
PerPage *int64
Sort *string
}
func NewSearchMonitorGroupsOptionalParameters() *SearchMonitorGroupsOptionalParameterstype SearchMonitorsOptionalParameters struct {
Query *string
Page *int64
PerPage *int64
Sort *string
}
func NewSearchMonitorsOptionalParameters() *SearchMonitorsOptionalParameterstype Monitor struct {
Assets []MonitorAsset
Created *time.Time
Creator *Creator
Deleted datadog.NullableTime
DraftStatus *MonitorDraftStatus
Id *int64
MatchingDowntimes []MatchingDowntime
Message *string
Modified *time.Time
Multi *bool
Name *string
Options *MonitorOptions
OverallState *MonitorOverallStates
Priority datadog.NullableInt64
Query string
RestrictedRoles datadog.NullableList[string]
State *MonitorState
Tags []string
Type MonitorType
}
func NewMonitor(query string, typeVar MonitorType) *Monitorpackage main
import (
"context"
"fmt"
"os"
"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.NewMonitorsApi(apiClient)
// Create a monitor
monitor := datadogV1.NewMonitor(
"avg(last_5m):sum:system.cpu.user{*} > 80",
datadogV1.MONITORTYPE_METRIC_ALERT,
)
monitor.SetName("High CPU Usage")
monitor.SetMessage("CPU usage is above 80% @slack-alerts")
options := datadogV1.NewMonitorOptions()
options.SetThresholds(datadogV1.MonitorThresholds{
Critical: datadog.PtrFloat64(80),
Warning: datadog.PtrFloat64(60),
})
monitor.SetOptions(*options)
resp, r, err := api.CreateMonitor(ctx, *monitor)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating monitor: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
return
}
fmt.Printf("Monitor created with ID: %d\n", resp.GetId())
// List monitors
optionalParams := datadogV1.NewListMonitorsOptionalParameters()
monitors, r, err := api.ListMonitors(ctx, *optionalParams)
if err != nil {
fmt.Fprintf(os.Stderr, "Error listing monitors: %v\n", err)
return
}
for _, mon := range monitors {
fmt.Printf("Monitor: %s (ID: %d)\n", mon.GetName(), mon.GetId())
}
}Schedule maintenance windows to mute alerts during planned maintenance.
type DowntimesApi struct {
// contains filtered or unexported fields
}
func NewDowntimesApi(client *datadog.APIClient) *DowntimesApifunc (a *DowntimesApi) CancelDowntime(
ctx context.Context,
downtimeId int64,
) (*http.Response, error)Cancel a downtime.
func (a *DowntimesApi) CancelDowntimesByScope(
ctx context.Context,
body datadogV1.CancelDowntimesByScopeRequest,
) (datadogV1.CanceledDowntimesIds, *http.Response, error)Cancel downtimes by scope.
func (a *DowntimesApi) CreateDowntime(
ctx context.Context,
body datadogV1.Downtime,
) (datadogV1.Downtime, *http.Response, error)Create a new downtime.
func (a *DowntimesApi) GetDowntime(
ctx context.Context,
downtimeId int64,
) (datadogV1.Downtime, *http.Response, error)Get a downtime's details.
func (a *DowntimesApi) ListDowntimes(
ctx context.Context,
o ...ListDowntimesOptionalParameters,
) ([]datadogV1.Downtime, *http.Response, error)List all downtimes.
func (a *DowntimesApi) ListMonitorDowntimes(
ctx context.Context,
monitorId int64,
) ([]datadogV1.Downtime, *http.Response, error)List all downtimes for a specific monitor.
func (a *DowntimesApi) UpdateDowntime(
ctx context.Context,
downtimeId int64,
body datadogV1.Downtime,
) (datadogV1.Downtime, *http.Response, error)Update a downtime.
type ListDowntimesOptionalParameters struct {
CurrentOnly *bool
WithCreator *bool
}
func NewListDowntimesOptionalParameters() *ListDowntimesOptionalParameterstype Downtime struct {
Active *bool
Canceled NullableInt64
CreatorId *int32
Disabled *bool
DowntimeType *int32
End NullableInt64
Id *int64
Message *string
MonitorId NullableInt64
MonitorTags []string
MuteFirstRecoveryNotification *bool
NotifyEndStates []datadogV1.NotifyEndState
NotifyEndTypes []datadogV1.NotifyEndType
ParentId NullableInt64
Recurrence NullableDowntimeRecurrence
Scope []string
Start *int64
Timezone *string
}
func NewDowntime() *Downtime// Create a downtime for 2 hours
downtime := datadogV1.NewDowntime()
downtime.SetScope([]string{"env:production"})
downtime.SetMessage("Planned maintenance")
downtime.SetStart(time.Now().Unix())
downtime.SetEnd(time.Now().Add(2 * time.Hour).Unix())
resp, r, err := downtimesApi.CreateDowntime(ctx, *downtime)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating downtime: %v\n", err)
return
}
fmt.Printf("Downtime created with ID: %d\n", resp.GetId())Create and manage service level objectives (SLOs).
type ServiceLevelObjectivesApi struct {
// contains filtered or unexported fields
}
func NewServiceLevelObjectivesApi(client *datadog.APIClient) *ServiceLevelObjectivesApifunc (a *ServiceLevelObjectivesApi) CheckCanDeleteSLO(
ctx context.Context,
ids string,
) (datadogV1.CheckCanDeleteSLOResponse, *http.Response, error)Check if SLOs can be deleted.
func (a *ServiceLevelObjectivesApi) CreateSLO(
ctx context.Context,
body datadogV1.ServiceLevelObjectiveRequest,
) (datadogV1.SLOListResponse, *http.Response, error)Create a new SLO.
func (a *ServiceLevelObjectivesApi) DeleteSLO(
ctx context.Context,
sloId string,
o ...DeleteSLOOptionalParameters,
) (datadogV1.SLODeleteResponse, *http.Response, error)Delete an SLO.
func (a *ServiceLevelObjectivesApi) DeleteSLOTimeframeInBulk(
ctx context.Context,
body map[string][]datadogV1.SLOTimeframe,
) (datadogV1.SLOBulkDeleteResponse, *http.Response, error)Delete SLO timeframes in bulk.
func (a *ServiceLevelObjectivesApi) GetSLO(
ctx context.Context,
sloId string,
o ...GetSLOOptionalParameters,
) (datadogV1.SLOResponse, *http.Response, error)Get an SLO's details.
func (a *ServiceLevelObjectivesApi) GetSLOCorrections(
ctx context.Context,
sloId string,
) (datadogV1.SLOCorrectionListResponse, *http.Response, error)Get SLO corrections for an SLO.
func (a *ServiceLevelObjectivesApi) GetSLOHistory(
ctx context.Context,
sloId string,
fromTs int64,
toTs int64,
o ...GetSLOHistoryOptionalParameters,
) (datadogV1.SLOHistoryResponse, *http.Response, error)Get historical SLO data.
func (a *ServiceLevelObjectivesApi) ListSLOs(
ctx context.Context,
o ...ListSLOsOptionalParameters,
) (datadogV1.SLOListResponse, *http.Response, error)List all SLOs.
func (a *ServiceLevelObjectivesApi) ListSLOsWithPagination(
ctx context.Context,
o ...ListSLOsOptionalParameters,
) (<-chan datadog.PaginationResult[datadogV1.SLOListResponse], func())List all SLOs with automatic pagination.
func (a *ServiceLevelObjectivesApi) SearchSLO(
ctx context.Context,
o ...SearchSLOOptionalParameters,
) (datadogV1.SearchSLOResponse, *http.Response, error)Search SLOs.
func (a *ServiceLevelObjectivesApi) UpdateSLO(
ctx context.Context,
sloId string,
body datadogV1.ServiceLevelObjective,
) (datadogV1.SLOListResponse, *http.Response, error)Update an SLO.
type DeleteSLOOptionalParameters struct {
Force *string
}
type GetSLOOptionalParameters struct {
WithConfiguredAlertIds *bool
}
type GetSLOHistoryOptionalParameters struct {
Target *float64
ApplyCorrection *bool
}
type ListSLOsOptionalParameters struct {
Ids *string
Query *string
TagsQuery *string
MetricsQuery *string
Limit *int64
Offset *int64
}
type SearchSLOOptionalParameters struct {
Query *string
PageSize *int64
PageNumber *int64
IncludeFacets *bool
}type ServiceLevelObjective struct {
CreatedAt *int64
Creator *Creator
Description NullableString
Groups []string
Id *string
ModifiedAt *int64
MonitorIds []int64
MonitorTags []string
Name *string
Query *ServiceLevelObjectiveQuery
Tags []string
Thresholds []SLOThreshold
Type *SLOType
Timeframe *SLOTimeframe
TargetThreshold *float64
WarningThreshold *float64
}
func NewServiceLevelObjective(
name string,
thresholds []SLOThreshold,
type_ SLOType,
) *ServiceLevelObjective// Create a monitor-based SLO
slo := datadogV1.NewServiceLevelObjective(
"API Uptime",
[]datadogV1.SLOThreshold{
{
Target: datadog.PtrFloat64(99.9),
Timeframe: datadogV1.SLOTIMEFRAME_THIRTY_DAYS.Ptr(),
},
},
datadogV1.SLOTYPE_MONITOR,
)
slo.SetMonitorIds([]int64{123456})
slo.SetDescription("API must maintain 99.9% uptime")
req := datadogV1.NewServiceLevelObjectiveRequest(*slo)
resp, r, err := sloApi.CreateSLO(ctx, *req)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating SLO: %v\n", err)
return
}
fmt.Printf("SLO created: %+v\n", resp.GetData())Manage SLO corrections for excluding time periods from SLO calculations.
type ServiceLevelObjectiveCorrectionsApi struct {
// contains filtered or unexported fields
}
func NewServiceLevelObjectiveCorrectionsApi(client *datadog.APIClient) *ServiceLevelObjectiveCorrectionsApifunc (a *ServiceLevelObjectiveCorrectionsApi) CreateSLOCorrection(
ctx context.Context,
body datadogV1.SLOCorrectionCreateRequest,
) (datadogV1.SLOCorrectionResponse, *http.Response, error)Create a new SLO correction.
func (a *ServiceLevelObjectiveCorrectionsApi) DeleteSLOCorrection(
ctx context.Context,
sloCorrectionId string,
) (*http.Response, error)Delete an SLO correction.
func (a *ServiceLevelObjectiveCorrectionsApi) GetSLOCorrection(
ctx context.Context,
sloCorrectionId string,
) (datadogV1.SLOCorrectionResponse, *http.Response, error)Get an SLO correction's details.
func (a *ServiceLevelObjectiveCorrectionsApi) ListSLOCorrection(
ctx context.Context,
o ...ListSLOCorrectionOptionalParameters,
) (datadogV1.SLOCorrectionListResponse, *http.Response, error)List all SLO corrections.
func (a *ServiceLevelObjectiveCorrectionsApi) ListSLOCorrectionWithPagination(
ctx context.Context,
o ...ListSLOCorrectionOptionalParameters,
) (<-chan datadog.PaginationResult[datadogV1.SLOCorrection], func())List all SLO corrections with automatic pagination.
func (a *ServiceLevelObjectiveCorrectionsApi) UpdateSLOCorrection(
ctx context.Context,
sloCorrectionId string,
body datadogV1.SLOCorrectionUpdateRequest,
) (datadogV1.SLOCorrectionResponse, *http.Response, error)Update an SLO correction.
type ListSLOCorrectionOptionalParameters struct {
Offset *int64
Limit *int64
}// Create an SLO correction for a maintenance window
correction := datadogV1.NewSLOCorrectionCreateData(
datadogV1.NewSLOCorrectionCreateRequestAttributes(
datadogV1.SLOCORRECTIONCATEGORY_DEPLOYMENT,
"Planned maintenance",
datadog.PtrInt64(time.Now().Unix()),
datadog.PtrString("my-slo-id"),
),
datadogV1.SLOCORRECTIONTYPE_CORRECTION,
)
correction.Attributes.SetEnd(time.Now().Add(2 * time.Hour).Unix())
req := datadogV1.NewSLOCorrectionCreateRequest(*correction)
resp, r, err := sloCorrectionsApi.CreateSLOCorrection(ctx, *req)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
return
}
fmt.Printf("SLO correction created: %s\n", resp.Data.GetId())Install with Tessl CLI
npx tessl i tessl/golang-github-com-data-dog--datadog-api-client-go-v2@2.54.0