package
2.2.0+incompatible
Repository: https://github.com/erda-project/erda.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

  • 消息格式 #+BEGIN_SRC type LabelKey string

type Message struct { Sender string json:"sender" Content interface{} json:"content" Labels map[LabelKey]interface{} json:"labels" Time int64 json:"time,omitempty" // UnixNano } #+END_SRC

** 发往目的地 对于发往不同目的地的消息,在 Labels 中指定 *** 钉钉 #+BEGIN_SRC dest := []string{"", ""} label = map[LabelKey]interface{}{"DINGDING": dest} #+END_SRC

*** HTTP #+BEGIN_SRC dest := []string{"", ""} label =map[LabelKey]interface{}{"HTTP": dest} #+END_SRC

以上 2 个 label 可以合在一起, 这样一条消息就会同时发送到 钉钉 和 http 回调

  • 消息写入方式

** HTTP API

  • url

=http://diceeventbox.marathon.l4lb.thisdcos.directory:9528/api/dice/eventbox/message/create=

** 写入 ETCD

*** 使用eventbox封装的API函数 **** go Package =github.com/erda-project/erda/modules/eventbox/api= **** usage #+BEGIN_SRC var notifier, err := api.New(sender, nil) //... error handle // send notifier.Send(content, api.WithDest(map[string]interface{}{"HTTP": []string{"URL"}})) // send another one notifier.Send(content, api.WithDest(map[string]interface{}{"HTTP": []string{"URL"}})) #+END_SRC

*** 直接写入 ETCD **** etcd endpoints #+BEGIN_SRC http://diceetcd-clusteretcd0.marathon.l4lb.thisdcos.directory:2379,http://diceetcd-clusteretcd1.marathon.l4lb.thisdcos.directory:2379,http://diceetcd-clusteretcd2.marathon.l4lb.thisdcos.directory:2379 #+END_SRC **** KEY =/eventbox/messages/= - TIME-UNIXNANO: =time.Now().UnixNano()= **** VALUE type =Message= struct

  • 消息 Labels 列表
    • HTTP

      http 回调形式的消息 #+BEGIN_SRC HTTP:["http://xxx", "https://yyy"] #+END_SRC

    • HTTP-HEADERS

      额外自定义的http回调时候的headers #+BEGIN_SRC HTTP-HEADERS: {"KEY1":"V1", "K2":"V2"} #+END_SRC

    • WEBHOOK

      其他服务触发 webhook 时候所需带上的 label

      详细看下面 =Webhook= 部分的说明 #+BEGIN_SRC WEBHOOK: { "event":"runtime", "action": "create", "org": "1", "project": "2", }

#+END_SRC

  • DINGDING

    发送 钉钉 形式的消息 #+BEGIN_SRC DINGDING: ["https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx"] #+END_SRC

  • MARKDOWN 钉钉消息使用markdown格式 #+BEGIN_SRC MARKDOWN: {"title": "xxx"} #+END_SRC

  • AT

    发送 钉钉 消息时候 at 人 #+BEGIN_SRC AT: { "atMobiles": [ "1825718XXXX" ], "isAtAll": false } #+END_SRC

  • Webhook 由 dice 组件触发各类事件,发送消息至 eventbox , 然后 eventbox 依据实现注册的 webhook ,发送事件至 webhook 中记录的 URL

** 其他服务触发webhook方式 同样使用上述 =消息写入方式= 中描述的2种方式(http 或 写etcd)

不同的是: 在消息的 =Labels= 中增加 key 为 =WEBHOOK= , value 为 #+BEGIN_SRC type EventLabel struct { Event string json:"event" Action string json:"action" Org string json:"orgID" // maybe not exist, then set it to 'default' Project string json:"projectID" }

e.g. { "event":"runtime", "action": "create", "orgID": "1", "projectID": "2", } #+END_SRC

最终, 发送至 webhook 中 URL 的实际json为: #+BEGIN_SRC type EventMessage struct { Event string json:"event" Action string json:"action" OrgID string json:"orgID" ProjectID string json:"projectID" // content 结构跟具体 event 相关 Content json.RawMessage json:"content" TimeStamp string json:"timestamp" }

e.g. { "event": "runtime", "action": "create", "orgID": "1", "projectID": "2", "content": "这里的内容为其他服务所发送的消息内容", "timestamp": "2006-1-2 12:23:34" } #+END_SRC