Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint for validation of existing monitors #1429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.2",
"regenerated": "2022-04-05 10:17:39.328437",
"spec_repo_commit": "9a0922b9"
"regenerated": "2022-04-05 11:14:23.181836",
"spec_repo_commit": "1bea0809"
},
"v2": {
"apigentools_version": "1.6.2",
"regenerated": "2022-04-05 10:17:39.341191",
"spec_repo_commit": "9a0922b9"
"regenerated": "2022-04-05 11:14:23.204763",
"spec_repo_commit": "1bea0809"
}
}
}
59 changes: 59 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,7 @@ components:
properties:
deleted_monitor_id:
description: ID of the deleted monitor.
example: 666486743
format: int64
type: integer
readOnly: true
Expand Down Expand Up @@ -21650,6 +21651,7 @@ paths:
required: true
schema:
items:
example: 666486743
format: int64
type: integer
type: array
Expand Down Expand Up @@ -21925,6 +21927,7 @@ paths:
name: monitor_id
required: true
schema:
example: 666486743
format: int64
type: integer
- description: Delete the monitor even if it's referenced by other resources
Expand Down Expand Up @@ -21988,6 +21991,7 @@ paths:
name: monitor_id
required: true
schema:
example: 666486743
format: int64
type: integer
- description: When specified, shows additional information about the group
Expand Down Expand Up @@ -22044,6 +22048,7 @@ paths:
name: monitor_id
required: true
schema:
example: 666486743
format: int64
type: integer
requestBody:
Expand Down Expand Up @@ -22145,6 +22150,60 @@ paths:
x-menu-order: 7
x-undo:
type: safe
/api/v1/monitor/{monitor_id}/validate:
post:
description: Validate the monitor provided in the request.
operationId: ValidateExistingMonitor
parameters:
- description: The ID of the monitor
in: path
name: monitor_id
required: true
schema:
example: 666486743
format: int64
type: integer
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Monitor'
description: Monitor request object
required: true
responses:
'200':
content:
application/json:
schema:
example: {}
type: object
description: OK
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Invalid JSON
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/APIErrorResponse'
description: Forbidden
'429':
$ref: '#/components/responses/TooManyRequestsResponse'
security:
- apiKeyAuth: []
appKeyAuth: []
- AuthZ:
- monitors_write
summary: Validate an existing monitor
tags:
- Monitors
x-codegen-request-body-name: body
x-menu-order: 8
x-undo:
type: idempotent
/api/v1/monthly_custom_reports:
get:
description: Get monthly custom reports.
Expand Down
165 changes: 165 additions & 0 deletions api/v1/datadog/api_monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,171 @@ func (a *MonitorsApiService) updateMonitorExecute(r apiUpdateMonitorRequest) (Mo
return localVarReturnValue, localVarHTTPResponse, nil
}

type apiValidateExistingMonitorRequest struct {
ctx _context.Context
ApiService *MonitorsApiService
monitorId int64
body *Monitor
}

/*
* ValidateExistingMonitor Validate an existing monitor
* Validate the monitor provided in the request.
*/
func (a *MonitorsApiService) ValidateExistingMonitor(ctx _context.Context, monitorId int64, body Monitor) (interface{}, *_nethttp.Response, error) {
req := apiValidateExistingMonitorRequest{
ApiService: a,
ctx: ctx,
monitorId: monitorId,
body: &body,
}

return req.ApiService.validateExistingMonitorExecute(req)
}

/*
* Execute executes the request
* @return interface{}
*/
func (a *MonitorsApiService) validateExistingMonitorExecute(r apiValidateExistingMonitorRequest) (interface{}, *_nethttp.Response, error) {
var (
localVarHTTPMethod = _nethttp.MethodPost
localVarPostBody interface{}
localVarFormFileName string
localVarFileName string
localVarFileBytes []byte
localVarReturnValue interface{}
)

localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "MonitorsApiService.ValidateExistingMonitor")
if err != nil {
return localVarReturnValue, nil, GenericOpenAPIError{error: err.Error()}
}

localVarPath := localBasePath + "/api/v1/monitor/{monitor_id}/validate"
localVarPath = strings.Replace(localVarPath, "{"+"monitor_id"+"}", _neturl.PathEscape(parameterToString(r.monitorId, "")), -1)

localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if r.body == nil {
return localVarReturnValue, nil, reportError("body is required and must be specified")
}

// to determine the Content-Type header
localVarHTTPContentTypes := []string{"application/json"}

// set Content-Type header
localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes)
if localVarHTTPContentType != "" {
localVarHeaderParams["Content-Type"] = localVarHTTPContentType
}

// to determine the Accept header
localVarHTTPHeaderAccepts := []string{"application/json"}

// set Accept header
localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts)
if localVarHTTPHeaderAccept != "" {
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}

// body params
localVarPostBody = r.body
if r.ctx != nil {
// API Key Authentication
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
if apiKey, ok := auth["apiKeyAuth"]; ok {
var key string
if apiKey.Prefix != "" {
key = apiKey.Prefix + " " + apiKey.Key
} else {
key = apiKey.Key
}
localVarHeaderParams["DD-API-KEY"] = key
}
}
}
if r.ctx != nil {
// API Key Authentication
if auth, ok := r.ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
if apiKey, ok := auth["appKeyAuth"]; ok {
var key string
if apiKey.Prefix != "" {
key = apiKey.Prefix + " " + apiKey.Key
} else {
key = apiKey.Key
}
localVarHeaderParams["DD-APPLICATION-KEY"] = key
}
}
}
req, err := a.client.PrepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)
if err != nil {
return localVarReturnValue, nil, err
}

localVarHTTPResponse, err := a.client.CallAPI(req)
if err != nil || localVarHTTPResponse == nil {
return localVarReturnValue, localVarHTTPResponse, err
}

localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body)
localVarHTTPResponse.Body.Close()
localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody))
if err != nil {
return localVarReturnValue, localVarHTTPResponse, err
}

if localVarHTTPResponse.StatusCode >= 300 {
newErr := GenericOpenAPIError{
body: localVarBody,
error: localVarHTTPResponse.Status,
}
if localVarHTTPResponse.StatusCode == 400 {
var v APIErrorResponse
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
if localVarHTTPResponse.StatusCode == 403 {
var v APIErrorResponse
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
return localVarReturnValue, localVarHTTPResponse, newErr
}
if localVarHTTPResponse.StatusCode == 429 {
var v APIErrorResponse
err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr.error = err.Error()
return localVarReturnValue, localVarHTTPResponse, newErr
}
newErr.model = v
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
if err != nil {
newErr := GenericOpenAPIError{
body: localVarBody,
error: err.Error(),
}
return localVarReturnValue, localVarHTTPResponse, newErr
}

return localVarReturnValue, localVarHTTPResponse, nil
}

type apiValidateMonitorRequest struct {
ctx _context.Context
ApiService *MonitorsApiService
Expand Down
2 changes: 1 addition & 1 deletion examples/v1/dashboards/CreateDashboard_2308247857.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(),
Time: &datadog.WidgetTime{},
Type: datadog.ALERTGRAPHWIDGETDEFINITIONTYPE_ALERT_GRAPH,
AlertId: "1",
AlertId: "7",
VizType: datadog.WIDGETVIZTYPE_TIMESERIES,
}},
},
Expand Down
2 changes: 1 addition & 1 deletion examples/v1/dashboards/CreateDashboard_2316374332.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func main() {
TitleSize: datadog.PtrString("16"),
TitleAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(),
Type: datadog.ALERTVALUEWIDGETDEFINITIONTYPE_ALERT_VALUE,
AlertId: "1",
AlertId: "7",
Unit: datadog.PtrString("auto"),
TextAlign: datadog.WIDGETTEXTALIGN_LEFT.Ptr(),
Precision: datadog.PtrInt64(2),
Expand Down
61 changes: 61 additions & 0 deletions examples/v1/monitors/ValidateExistingMonitor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Validate an existing monitor returns "OK" response

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 "monitor" in the system
MonitorID, _ := strconv.ParseInt(os.Getenv("MONITOR_ID"), 10, 64)

body := datadog.Monitor{
Name: datadog.PtrString("Example-Validate_an_existing_monitor_returns_OK_response"),
Type: datadog.MONITORTYPE_LOG_ALERT,
Query: `logs("service:foo AND type:error").index("main").rollup("count").by("source").last("5m") > 2`,
Message: datadog.PtrString("some message Notify: @hipchat-channel"),
Tags: &[]string{
"test:examplevalidateanexistingmonitorreturnsokresponse",
"env:ci",
},
Priority: *datadog.NewNullableInt64(datadog.PtrInt64(3)),
Options: &datadog.MonitorOptions{
EnableLogsSample: datadog.PtrBool(true),
EscalationMessage: datadog.PtrString("the situation has escalated"),
EvaluationDelay: *datadog.NewNullableInt64(datadog.PtrInt64(700)),
GroupbySimpleMonitor: datadog.PtrBool(true),
IncludeTags: datadog.PtrBool(true),
Locked: datadog.PtrBool(false),
NewHostDelay: *datadog.NewNullableInt64(datadog.PtrInt64(600)),
NoDataTimeframe: *datadog.NewNullableInt64(nil),
NotifyAudit: datadog.PtrBool(false),
NotifyNoData: datadog.PtrBool(false),
RenotifyInterval: *datadog.NewNullableInt64(datadog.PtrInt64(60)),
RequireFullWindow: datadog.PtrBool(true),
TimeoutH: *datadog.NewNullableInt64(datadog.PtrInt64(24)),
Thresholds: &datadog.MonitorThresholds{
Critical: datadog.PtrFloat64(2),
Warning: *datadog.NewNullableFloat64(datadog.PtrFloat64(1)),
},
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
resp, r, err := apiClient.MonitorsApi.ValidateExistingMonitor(ctx, MonitorID, body)

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `MonitorsApi.ValidateExistingMonitor`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.ValidateExistingMonitor`:\n%s\n", responseContent)
}
3 changes: 1 addition & 2 deletions examples/v1/usage-metering/GetUsageBillableSummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"os"
"time"

datadog "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
)
Expand All @@ -16,7 +15,7 @@ func main() {
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
resp, r, err := apiClient.UsageMeteringApi.GetUsageBillableSummary(ctx, *datadog.NewGetUsageBillableSummaryOptionalParameters().WithMonth(time.Now().AddDate(0, 0, -3)))
resp, r, err := apiClient.UsageMeteringApi.GetUsageBillableSummary(ctx, *datadog.NewGetUsageBillableSummaryOptionalParameters())

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `UsageMeteringApi.GetUsageBillableSummary`: %v\n", err)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-04-04T09:34:37.709Z
Loading