Exemple #1
0
func Graylog2ParseLog(line string, remote_addr string) Graylog2Parsed {
	parsed := Graylog2Parsed{}
	now := time.Now()
	parsed.Timestamp = now.Unix()
	parsed.Version = "1.0"
	if strings.Contains(remote_addr, "127.0.0.1") {
		hostname, err := os.Hostname()
		utils.CheckPanic(err, fmt.Sprintf("Unable to get my hostname"))
		parsed.Host = hostname
	} else {
		parsed.Host = remote_addr
	}

	lvl := LvlRegex.FindStringSubmatch(line)
	if len(lvl) >= 2 {
		i, err := strconv.Atoi(lvl[1])
		utils.Check(err, fmt.Sprintf("Unable to convert %s to int", i))
		parsed.Facility = strings.Title(Facility[i/8])
		parsed.Level = i % 8
		parsed.ShortMessage = strings.TrimRight(lvl[2], "\u0000")
	} else {
		parsed.Facility = "Syslog"
		parsed.Level = 6
		parsed.ShortMessage = strings.TrimRight(line, "\u0000")
	}
	return parsed
}
Exemple #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()
}
Exemple #3
0
func (c *Connection) SetupBroker() {
	var err error
	c.conn, c.pub, err = setup(c.Uri, c.Queue)
	utils.CheckPanic(err, "Problem acquiring connection")
}