-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
71 lines (57 loc) · 1.44 KB
/
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
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
package main
import (
"flag"
"log"
syslog "gopkg.in/mcuadros/go-syslog.v2"
)
var (
debug bool
)
func receiveSyslog(ch syslog.LogPartsChannel) {
var (
l *logEntry
err error
)
for msg := range ch {
if debug {
log.Printf("%s: %s", msg["hostname"], msg["content"])
}
if l, err = parseSyslogMessage(msg); err != nil {
log.Printf("Unable to parse message: %s", err)
continue
}
if l.jrpc_method != "" {
l.uri = l.jrpc_method
} else {
l.jrpc_method = ""
l.uri = "/"
}
prometheusMetricsRegister(l)
}
}
func main() {
var (
listenSyslog string
listenHTTP string
usePrometheus bool
)
flag.StringVar(&listenSyslog, "listenSyslog", "0.0.0.0:514", "ip:port to listen for syslog messages")
flag.StringVar(&listenHTTP, "listenHTTP", "0.0.0.0:9100", "ip:port to listen for http requests")
flag.BoolVar(&usePrometheus, "usePrometheus", true, "Enable posting metrics to Prometheus")
flag.BoolVar(&debug, "debug", false, "Enable debug")
flag.Parse()
channel := make(syslog.LogPartsChannel)
handler := syslog.NewChannelHandler(channel)
log.Printf("Starting Syslog UDP listener: %s", listenSyslog)
server := syslog.NewServer()
server.SetFormat(syslog.RFC3164)
server.SetHandler(handler)
server.ListenUDP(listenSyslog)
server.Boot()
go receiveSyslog(channel)
if usePrometheus {
log.Printf("Starting Prometheus HTTP listener: %s", listenHTTP)
go prometheusListener(listenHTTP)
}
server.Wait()
}