-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharvester.go
47 lines (41 loc) · 1.09 KB
/
harvester.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
package main
import (
"fmt"
"net/http"
"github.com./gin-gonic/gin"
"github.com./rs/zerolog/log"
)
type HarvesterNotify struct {
Hostname string `json:"hostname"`
IPAddrV4 string `json:"ipv4"`
IPAddrV6 string `json:"ipv6"`
MACAddr string `json:"mac"`
VIP string `json:"vip"`
Version string `json:"version"`
Msg string `json:"msg"`
}
const harvesterServerChanPath = "/harvester-serverchan/:event"
func harvesterServerChanHandler(c *gin.Context) {
event := c.Param("event")
var notify HarvesterNotify
err := c.ShouldBind(¬ify)
if err != nil {
log.Error().Err(err)
}
if err = harvesterToServerchan(¬ify, event); err != nil {
log.Error().Err(err)
}
c.String(http.StatusOK, "")
return
}
func harvesterToServerchan(notify *HarvesterNotify, event string) error {
title := fmt.Sprintf("[%s install %s]", notify.Hostname, event)
description := fmt.Sprintf(`
hostname: %s
event: %s
ipv4: %s
ipv6: %s
mac: %s`, notify.Hostname, event, notify.IPAddrV4, notify.IPAddrV6, notify.MACAddr)
log.Debug().Str("title", title).Msg(description)
return sendToServerChan(title, description)
}