fix
This commit is contained in:
41
internal/ingest/syslog_udp.go
Normal file
41
internal/ingest/syslog_udp.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package ingest
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/ops/logs/internal/config"
|
||||
)
|
||||
|
||||
func StartSyslogUDP() {
|
||||
addr := strings.TrimSpace(config.Spec.Ingest.SyslogListenAddr)
|
||||
if addr == "" {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
pc, err := net.ListenPacket("udp", addr)
|
||||
if err != nil {
|
||||
log.Printf("logs: syslog UDP listen %s: %v", addr, err)
|
||||
return
|
||||
}
|
||||
defer pc.Close()
|
||||
log.Printf("logs: syslog listening UDP %s", addr)
|
||||
buf := make([]byte, 65536)
|
||||
for {
|
||||
n, remote, err := pc.ReadFrom(buf)
|
||||
if err != nil {
|
||||
log.Printf("logs: syslog read: %v", err)
|
||||
continue
|
||||
}
|
||||
udpAddr, _ := remote.(*net.UDPAddr)
|
||||
if udpAddr == nil {
|
||||
continue
|
||||
}
|
||||
p := make([]byte, n)
|
||||
copy(p, buf[:n])
|
||||
a := *udpAddr
|
||||
Global.HandleSyslog(&a, p)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user