1
0
Fork 0
forked from boyska/circolog

Compare commits

...

1 commit

Author SHA1 Message Date
a7809eb09c
Connection parameters from command-line 2018-08-22 23:07:52 +02:00

25
main.go
View file

@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"strconv"
syslog "gopkg.in/mcuadros/go-syslog.v2" syslog "gopkg.in/mcuadros/go-syslog.v2"
"gopkg.in/mcuadros/go-syslog.v2/format" "gopkg.in/mcuadros/go-syslog.v2/format"
@ -40,18 +39,9 @@ func main() {
syslogSocketPath := flag.String("syslogd-socket", "", "The socket to listen to syslog addresses") syslogSocketPath := flag.String("syslogd-socket", "", "The socket to listen to syslog addresses")
// dumpSocketPath := flag.String("dump-socket", "/run/buffer.sock", "The socket that user will connect to in order to receive logs") // dumpSocketPath := flag.String("dump-socket", "/run/buffer.sock", "The socket that user will connect to in order to receive logs")
bufsize := flag.Int("buffer-size", 1000, "Number of messages to keep") bufsize := flag.Int("buffer-size", 1000, "Number of messages to keep")
UDPPort := flag.Int("log-port", 9514, "UDP port where to listen for syslog messages") syslogAddr := flag.String("syslog-addr", "127.0.0.1:9514", "Address:port where to listen for syslog messages")
TCPPort := flag.Int("query-port", 9080, "TCP port where to listen for queries from the buffer") queryAddr := flag.String("query-addr", "127.0.0.1:9080", "Address:port where to bind the query service")
address := flag.String("addr", "127.0.0.1", "Address to bind to")
flag.Parse() flag.Parse()
if *TCPPort > 65535 || *TCPPort < 1 {
fmt.Fprintf(os.Stderr, "Error: selected query-port is out of bounds: %d\n", *TCPPort)
os.Exit(1)
}
if *UDPPort > 65535 || *UDPPort < 1 {
fmt.Fprintf(os.Stderr, "Error: selected log-port is out of bounds: %d\n", *UDPPort)
os.Exit(1)
}
channel := make(chan format.LogParts) channel := make(chan format.LogParts)
handler := syslog.NewChannelHandler(channel) handler := syslog.NewChannelHandler(channel)
@ -62,20 +52,17 @@ func main() {
if *syslogSocketPath != "" { if *syslogSocketPath != "" {
server.ListenUnixgram(*syslogSocketPath) server.ListenUnixgram(*syslogSocketPath)
fmt.Printf("Binding socket `%s` [syslog]\n", *syslogSocketPath) fmt.Printf("Binding socket `%s` [syslog]\n", *syslogSocketPath)
os.Exit(2)
} else { } else {
addr := *address + ":" + strconv.Itoa(*UDPPort) fmt.Printf("Binding address `%s` [syslog]\n", *syslogAddr)
fmt.Printf("Binding address `%s` [syslog]\n", addr) server.ListenUDP(*syslogAddr)
server.ListenUDP(addr)
} }
circbuf = ring.New(*bufsize) circbuf = ring.New(*bufsize)
server.Boot() server.Boot()
go syslogdHandler(channel) go syslogdHandler(channel)
http.HandleFunc("/", httpHandler) http.HandleFunc("/", httpHandler)
listenPortFmt := ":" + strconv.Itoa(*TCPPort) fmt.Printf("Binding address `%s` [http]\n", *queryAddr)
fmt.Printf("Binding address `%s` [http]\n", listenPortFmt) http.ListenAndServe(*queryAddr, nil)
http.ListenAndServe(listenPortFmt, nil)
server.Wait() server.Wait()
} }