Esempio n. 1
0
func parseWifi() {

	if parsedAlready {
		log.Info("Re-parsing logs: %s", wifiLogDir)
	} else {
		log.Info("Parsing logs: %s", wifiLogDir)
		parsedAlready = true
	}

	files, err := ioutil.ReadDir(wifiLogDir)
	if err != nil {
		log.StandardError(err)
		return
	}

	if len(files) == 0 {
		log.Error("No files found to parse in %s", wifiLogDir)
		return
	}

	var (
		c, l     int
		current  []byte
		file     *os.File
		filename string
		isPrefix bool
		key      string
		line     []byte
		reader   *bufio.Reader
		received int64
		sent     int64
		session  string
		split    []string
		status   string
		// pending  map[string]string
	)

	startTime := time.Now()

	var i int

	for _, info := range files {
		filename = filepath.Join(wifiLogDir, info.Name())
		log.Info("Parsing: %s", filename)
		file, err = os.Open(filename)
		if err != nil {
			log.StandardError(err)
			return
		}
		reader = bufio.NewReader(file)
		for {
			line, isPrefix, err = reader.ReadLine()
			if err != nil {
				if err == io.EOF {
					break
				}
				log.StandardError(err)
				return
			}
			current = append(current, line...)
			if isPrefix {
				continue
			}
			split = strings.Split(string(current), ",")
			l = len(split)
			c = 6
			session = ""
			status = ""
			received = 0
			sent = 0
			for c < l {
				key = split[c]
				c += 2
				switch key {
				case "40":
					status = split[c+1]
				case "42":
					received, _ = strconv.ParseInt(split[c+1], 10, 64)
				case "43":
					sent, _ = strconv.ParseInt(split[c+1], 10, 64)
				case "44":
					session = split[c+1]
				}
				// log.Info("key: %s", key)
			}
			_ = session
			_ = status
			_ = received
			_ = sent
			current = current[0:0]
			i += 1
			if i >= 0 {
				break
			}
		}
		break
	}

	log.Info("Finished parsing (%s)", time.Since(startTime))

}
Esempio n. 2
0
func StandardError(err error) {
	log.StandardError(err)
	Exit(1)
}