-
Notifications
You must be signed in to change notification settings - Fork 0
/
dingding.go
74 lines (66 loc) · 1.66 KB
/
dingding.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
type Markdown struct {
Title string `json:"title"`
Text string `json:"text"`
}
type Message struct {
Msgtype string `json:"msgtype"`
Markdown `json:"markdown"`
}
//var user string
//var branch string
//var action string
//func init() {
// flag.StringVar(&user, "user", "Wangyijie", "build user")
// flag.StringVar(&user, "u", "Wangyijie", "build user")
// flag.StringVar(&branch, "branch", "develop", "build branch")
// flag.StringVar(&branch, "b", "develop", "build branch")
// flag.StringVar(&action, "action", "", "action task")
// flag.StringVar(&action, "a", "", "action task")
// flag.Parse()
//}
func send(namespace, pod, reason string) {
var st string
st = template(namespace, pod, reason)
markdown1 := Markdown{
Title: "测试部署检查",
Text: st,
}
message1 := Message{
Msgtype:"markdown",
Markdown: markdown1,
}
dingUrl := "https://oapi.dingtalk.com/robot/send?access_token=2e7ba0145b1bf885c2e75ba0e458ff2b204b2c41d641ebe7ee734fcb73ae88f0"
b, err := json.Marshal(message1)
if err != nil{
fmt.Println("message err:", err)
}
body := bytes.NewBuffer([]byte(b))
res, err := http.Post(dingUrl, "application/json;chartset=utf-8",body)
if err != nil {
log.Fatal(err)
return
}
result, err := ioutil.ReadAll(res.Body)
_ = res.Body.Close()
if err != nil {
log.Fatal(err)
return
}
fmt.Printf("%s", result)
}
func template(namespace, pod, reason string) string {
st := namespace + " " + pod + " status Exception: \n" +
"> kubectl get pods -n" + namespace + "\n\n" +
"> kubectl logs "+ pod + " -n " + namespace + "\n\n" +
"> " + reason
return st
}