Exemplo n.º 1
0
func handle_data(data string, conn broker.Connection, remote_addr string) {
	if *debug == true {
		fmt.Printf("Received log %s\n", data)
	}

	parsed := syslog.Graylog2ParseLog(&data, &remote_addr)

	if *debug == true {
		fmt.Printf("Sending data %s\n", parsed)
	}
	conn.Send(&parsed)
}
Exemplo n.º 2
0
func main() {
	flag.Parse()
	var err error
	var conn broker.Connection

	config_file := os.Getenv("GOGIX_CONF")
	if strings.TrimSpace(config_file) == "" {
		config_file = "/etc/gogix/gogix.conf"
	}

	Cfg, err = goconfig.ReadConfigFile(config_file)
	utils.CheckPanic(err, "File not found")

	bind_addr, err := Cfg.GetString("server", "bind_addr")
	utils.CheckPanic(err, "Unable to get bind_addr from gogix.conf")
	conn.Queue, err = Cfg.GetString("transport", "queue")
	utils.CheckPanic(err, "Unable to get queue from gogix.conf")
	conn.Uri, err = Cfg.GetString("transport", "uri")
	utils.CheckPanic(err, "Unable to get transport from gogix.conf")
	conn.Expiration, err = Cfg.GetString("transport", "message_ttl")
	utils.CheckPanic(err, "Unable to get message_ttl from gogix.conf")
	addr, err := net.ResolveUDPAddr("udp", bind_addr)
	utils.CheckPanic(err, "Unable to resolve bind address")
	l, err := net.ListenUDP("udp", addr)
	utils.CheckPanic(err, fmt.Sprintf("Unable to bind %s", addr))

	if *debug == true {
		fmt.Printf("Setting-Up Broker %s\n", conn.Uri)
	}
	conn.SetupBroker()
	go conn.ReconnectOnClose()

	for {
		recv := make([]byte, 1024)
		_, remote_addr, err := l.ReadFromUDP(recv)
		utils.Check(err, "Problem receiving data")
		fmt.Println(recv)
		if err == nil {
			ip := fmt.Sprintf("%s", remote_addr.IP)
			go handle_data(string(recv), conn, ip)
		}
	}

	conn.Close()
}