发送事件到Datadog

huangapple go评论129阅读模式
英文:

Send Event to Datadog

问题

很抱歉,我只能为您提供翻译服务,无法为您提供代码方面的帮助。如果您需要帮助创建/跟踪事件,请参考您提供的链接中的结构体和文档,填写相应的变量。如果您在使用过程中遇到问题,建议您查阅相关文档或寻求开发者社区的帮助。祝您顺利完成任务!

英文:

Unfortunately there is not an official Go Datadog API. I am currently using this one instead https://github.com/zorkian/go-datadog-api. Datadog forked the first version of it and recommend using it.

I am able to connect to my Dashboard:

  1. client := datadog.NewClient("...", "...")
  2. dash, err := client.GetDashboard(...)
  3. if err != nil {
  4. log.Fatalf("fatal: %s\n", err)
  5. }

But I do not know how to send create/track an event. This is my current approach but if fails badly.

  1. c := datadog.Client{}
  2. title := "Abc"
  3. e := datadog.Event{ Title: &title }
  4. c.PostEvent(&e)

From my understanding and the missing documentation, I would have to fill out some of these variables in this struct (https://github.com/zorkian/go-datadog-api/blob/master/events.go)

  1. // Event is a single event.
  2. // all fields will be filled out.
  3. type Event struct {
  4. Id *int `json:"id,omitempty"`
  5. Title *string `json:"title,omitempty"`
  6. Text *string `json:"text,omitempty"`
  7. Time *int `json:"date_happened,omitempty"` // UNIX time.
  8. Priority *string `json:"priority,omitempty"`
  9. AlertType *string `json:"alert_type,omitempty"`
  10. Host *string `json:"host,omitempty"`
  11. Aggregation *string `json:"aggregation_key,omitempty"`
  12. SourceType *string `json:"source_type_name,omitempty"`
  13. Tags []string `json:"tags,omitempty"`
  14. Url *string `json:"url,omitempty"`
  15. Resource *string `json:"resource,omitempty"`
  16. EventType *string `json:"event_type,omitempty"`
  17. }

Can you please help me with that?

答案1

得分: 1

在你发布的代码中:

  1. c := datadog.Client{}

这似乎是创建一个空的客户端对象。

你应该使用datadog.NewClient("...", "...")来创建一个带有你的密钥的客户端,就像你在第一个代码片段中发布的那样:

  1. c := datadog.NewClient("...", "...")

此外,你应该检查返回的错误,因为它会给你更多的提示来解决问题:

  1. _, err := c.PostEvent(&e)
  2. if err != nil {
  3. log.Fatalf("fatal: %s\n", err)
  4. }
英文:

In the code you posted:

  1. c := datadog.Client{}

This seems to be creating an empty client object.

Shouldn't you be creating a client with your keys using datadog.NewClient("...", "...") as in the first code snippet you posted?

  1. c := datadog.NewClient("...", "...")

Also, you should check the error returned as that will give you more hints to troubleshoot the issue:

  1. _, err := c.PostEvent(&e)
  2. if err != nil {
  3. log.Fatalf("fatal: %s\n", err)
  4. }

`

huangapple
  • 本文由 发表于 2017年7月21日 15:53:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/45232107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定