-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (35 loc) · 868 Bytes
/
main.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
package main
import (
"io/ioutil"
"net/http"
"os"
log "github.com/sirupsen/logrus"
"github.com/gorilla/mux"
"github.com/nlopes/slack"
)
func webhook(w http.ResponseWriter, r *http.Request) {
reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Fatalln(err)
}
// Send the audit log message to Slack
apiToken := os.Getenv("SLACK_TOKEN")
channelID := os.Getenv("CHANNEL_ID")
sclient := slack.New(apiToken, slack.OptionDebug(true))
attachment := slack.Attachment{
Pretext: "Kubernetes Audit Log",
Color: "#3EB489",
Fields: []slack.AttachmentField{
{
Value: string(reqBody),
},
},
}
sclient.PostMessage(channelID, slack.MsgOptionAttachments(attachment))
}
func main() {
r := mux.NewRouter()
r.HandleFunc("/webhook", webhook).Methods("POST")
log.Info("Starting Server on 0.0.0.0:8080")
http.ListenAndServe(":8080", r)
}