首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我不了解Downtime API是如何工作的,我正在尝试自动安排downtime

我不了解Downtime API是如何工作的,我正在尝试自动安排downtime
EN

Stack Overflow用户
提问于 2021-11-03 00:47:22
回答 1查看 47关注 0票数 0

当涉及到DataDog Downtime API时,文档非常不清楚。我的示例基于以下文档:https://docs.datadoghq.com/api/latest/downtimes/#schedule-a-downtime

我设置了以下环境变量:

代码语言:javascript
复制
    DD_APP_TOKEN: Your datadog application token.
    DD_API_TOKEN: Your datadog API token.
    DD_SITE: The address of the DD API server.  Usually "datadoghq.com"

我的示例代码:

代码语言:javascript
复制
import (
    "context"
    "encoding/json"
    "fmt"
    "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
    "github.com/slack-go/slack"
    "os"
    "time"
)

func main() {
    ctx := datadog.NewDefaultContext(context.Background())

    var DataDogFiltersByTag = []string{
        "printing",
        "OTIS",
        "env:production",
    }

    Message := "Downtime Test"
    var ctime int64 = time.Now().Unix()     // Current Time
    var dtime int64 = ctime + (45 * 60)     // 45 minutes

    body := *datadog.NewDowntime() // Downtime | Schedule a downtime request body.
    body.Message = &Message
    body.Start = &ctime
    end := datadog.NullableInt64{}
    end.Set(&dtime)
    body.End = end
    body.MonitorTags = &DataDogFiltersByTag

    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)
    }
    // response from `CreateDowntime`: Downtime
    responseContent, _ := json.MarshalIndent(resp, "", "  ")
    fmt.Fprintf(os.Stdout, "Response from DowntimesApi.CreateDowntime:\n%s\n", responseContent)
}

这将导致以下错误消息:

代码语言:javascript
复制
/private/var/folders/p0/jbhf5p4n3f3c3rc5rc_rc6400000gn/T/GoLand/___6go_build_ClusterUpgradeNotification
Error when calling `DowntimesApi.CreateDowntime`: 400 Bad Request
Full HTTP response: &{400 Bad Request 400 HTTP/1.1 1 1 map[Cache-Control:[no-cache] Connection:[keep-alive] Content-Length:[39] Content-Security-Policy:[frame-ancestors 'self'; report-uri https://api.datadoghq.com/csp-report] Content-Type:[application/json] Date:[Wed, 03 Nov 2021 00:33:09 GMT] Pragma:[no-cache] Strict-Transport-Security:[max-age=15724800;] X-Content-Type-Options:[nosniff] X-Frame-Options:[SAMEORIGIN]] {{"errors": ["Invalid scope parameter"]}} 39 [] false false map[] 0xc00019a800 0xc0003342c0}
Response from DowntimesApi.CreateDowntime:
{}

Process finished with the exit code 1
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-04 15:24:11

作用域是datadog.CreateDowntime()中的必需参数。添加body.SetScope([]string{"*"})解决了我的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69818484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档