json - 发送事件到 Datadog

标签 json go struct datadog

不幸的是,没有官方的 Go Datadog API。我目前正在使用这个 https://github.com/zorkian/go-datadog-api . Datadog fork了第一个版本,推荐使用。

我能够连接到我的仪表板:

    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("...", "...") 使用您的 key 创建客户端?

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/

相关文章:

java - 反序列化 json,将子类对象提升到顶层而不是嵌套类

在循环内创建 json 对象的 Jquery 代码

go - LiteIDE GDB 与 Golang

c++ - 在 C++ 中初始化结构中的 const 数组

python - 基于平台分割数据(来自文本/json文件)(使用Python)

javascript - Firebase Web 客户端将 JSON 上传到 Cloud Storage

go - 使用Go从Firestore获取单个文档的惯用方式是什么?

http - 在 Golang 中使用 http.Client.Do 的空 HTTP 响应

c++ - 运行时错误 : Template variable

C++在函数中使用指向结构的指针