不幸的是,没有官方的Go Datadog API。我目前正在使用这个而不是https://github.com/zorkian/go-datadog-api。 Datadog分叉了它的第一个版本,并建议使用它。
我能够连接到我的仪表板:
client := datadog.NewClient("...", "...")
dash, err := client.GetDashboard(...)
if err != nil {
log.Fatalf("fatal: %s\n", err)
}
但是我不知道如何发送创建/跟踪事件。这是我目前的方法,但是如果失败很严重。
c := datadog.Client{}
title := "Abc"
e := datadog.Event{ Title: &title }
c.PostEvent(&e)
根据我的理解和缺少的文档,我将不得不在此结构(https://github.com/zorkian/go-datadog-api/blob/master/events.go)中填写其中一些变量
// Event is a single event.
// all fields will be filled out.
type Event struct {
Id *int `json:"id,omitempty"`
Title *string `json:"title,omitempty"`
Text *string `json:"text,omitempty"`
Time *int `json:"date_happened,omitempty"` // UNIX time.
Priority *string `json:"priority,omitempty"`
AlertType *string `json:"alert_type,omitempty"`
Host *string `json:"host,omitempty"`
Aggregation *string `json:"aggregation_key,omitempty"`
SourceType *string `json:"source_type_name,omitempty"`
Tags []string `json:"tags,omitempty"`
Url *string `json:"url,omitempty"`
Resource *string `json:"resource,omitempty"`
EventType *string `json:"event_type,omitempty"`
}
你能帮我吗?
最佳答案
在您发布的代码中:
c := datadog.Client{}
这似乎正在创建一个空的客户端对象。
您不应该像在您发布的第一个代码段中那样使用
datadog.NewClient("...", "...")
用密钥创建客户端吗?c := datadog.NewClient("...", "...")
另外,您应该检查返回的错误,因为这将给您更多提示以解决问题:
_, err := c.PostEvent(&e)
if err != nil {
log.Fatalf("fatal: %s\n", err)
}
`
关于json - 发送事件到Datadog,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45232107/