1
0
Fork 0
forked from boyska/circolog
circolog/cmd/circologd/main.go

64 lines
1.9 KiB
Go
Raw Normal View History

2018-08-22 18:47:00 +02:00
package main
import (
"flag"
"fmt"
2018-08-23 02:08:53 +02:00
"net"
2018-08-22 18:47:00 +02:00
"net/http"
2018-08-22 23:51:59 +02:00
"os"
2018-08-22 18:47:00 +02:00
2018-08-23 01:21:53 +02:00
"git.lattuga.net/boyska/circolog"
2018-08-22 18:47:00 +02:00
syslog "gopkg.in/mcuadros/go-syslog.v2"
)
func main() {
2018-08-22 23:51:59 +02:00
var err error
2018-08-22 18:47:00 +02:00
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")
bufsize := flag.Int("buffer-size", 1000, "Number of messages to keep")
syslogAddr := flag.String("syslog-addr", "127.0.0.1:9514", "Address:port where to listen for syslog messages")
queryAddr := flag.String("query-addr", "127.0.0.1:9080", "Address:port where to bind the query service")
2018-08-23 02:08:53 +02:00
querySocket := flag.String("query-socket", "", "Path to a unix domain socket for the HTTP server; recommended for security reasons!")
2018-08-22 18:47:00 +02:00
flag.Parse()
2018-08-23 01:21:53 +02:00
hub := circolog.NewHub(*bufsize)
handler := syslog.NewChannelHandler(hub.LogMessages)
2018-08-22 18:47:00 +02:00
server := syslog.NewServer()
server.SetFormat(syslog.RFC5424)
server.SetHandler(handler)
if *syslogSocketPath != "" {
2018-08-22 23:51:59 +02:00
if err = server.ListenUnixgram(*syslogSocketPath); err != nil {
fmt.Fprintln(os.Stderr, "argh", err)
os.Exit(1)
}
2018-08-22 21:05:37 +02:00
fmt.Printf("Binding socket `%s` [syslog]\n", *syslogSocketPath)
2018-08-22 20:56:43 +02:00
} else {
fmt.Printf("Binding address `%s` [syslog]\n", *syslogAddr)
2018-08-22 23:51:59 +02:00
if err = server.ListenUDP(*syslogAddr); err != nil {
fmt.Fprintln(os.Stderr, "argh", err)
os.Exit(1)
}
2018-08-22 18:47:00 +02:00
}
2018-08-22 23:51:59 +02:00
if err = server.Boot(); err != nil {
fmt.Fprintln(os.Stderr, "argh", err)
os.Exit(1)
}
go hub.Run()
2018-08-22 18:47:00 +02:00
2018-08-23 12:25:07 +02:00
setupHTTP(hub)
2018-08-23 02:08:53 +02:00
if *querySocket != "" {
fmt.Printf("Binding address `%s` [http]\n", *querySocket)
unixListener, err := net.Listen("unix", *querySocket)
if err != nil {
fmt.Fprintln(os.Stderr, "Error binding HTTP unix domain socket", err)
}
defer os.Remove(*querySocket)
http.Serve(unixListener, nil)
} else {
fmt.Printf("Binding address `%s` [http]\n", *queryAddr)
http.ListenAndServe(*queryAddr, nil)
}
2018-08-22 18:47:00 +02:00
server.Wait()
}