diff options
author | Daniel Langesten <daniel.langest@gmail.com> | 2015-05-18 12:44:38 +0200 |
---|---|---|
committer | Daniel Langesten <daniel.langest@gmail.com> | 2015-05-18 12:44:38 +0200 |
commit | e2bee352dc2c3fbcb4c7f25c19061b95df7adec1 (patch) | |
tree | 3fc8c0733343cc9dfdd8af83522c22d69f66015a /stdin.go | |
parent | 167c922d9c9de72f9f02003be451b4fe8ab0f04a (diff) |
Diffstat (limited to 'stdin.go')
-rw-r--r-- | stdin.go | 58 |
1 files changed, 35 insertions, 23 deletions
@@ -49,34 +49,46 @@ func parseRawData(in <-chan []byte, cfg *Config) <-chan []RawData { } go func() { rDat := make([]RawData, 0) + relevant := false for line := range in { - if len(string(line)) > 0 && !strings.HasPrefix(string(line), "{") { - stlogger.Println("Got message:", strings.TrimSpace(string(line))) - //This should be a break in the output from pmacct - //so we deploy our collected data and set a new timeBin - ival, err := cfg.getInterval() - if err != nil { - stlogger.Println("Could not parse interval: ", err) + if relevant { + if strings.Contains(string(line), "END") { + relevant = false + continue } - timeBin = time.Now().Add(ival / -2) //Make sure we are inside the correct timeBin - //Send the data if we have something to send - if len(rDat) > 0 { - out <- rDat - rDat = make([]RawData, 0) + if len(string(line)) > 0 && !strings.HasPrefix(string(line), "{") { + stlogger.Println("Got message:", strings.TrimSpace(string(line))) + //This should be a break in the output from pmacct + //so we deploy our collected data and set a new timeBin + ival, err := cfg.getInterval() + if err != nil { + stlogger.Println("Could not parse interval: ", err) + } + timeBin = time.Now().Add(ival / -2) //Make sure we are inside the correct timeBin + //Send the data if we have something to send + if len(rDat) > 0 { + out <- rDat + rDat = make([]RawData, 0) + } + continue } - continue - } - var rd RawData - err := json.Unmarshal(line, &rd) - if err != nil { - stlogger.Println("Failed in parsing json:", err) - close(out) - return - } - rd.time = timeBin + var rd RawData + err := json.Unmarshal(line, &rd) + if err != nil { + stlogger.Println("Failed in parsing json:", err) + stlogger.Println("Line failed was:", string(line)) + continue + } + rd.time = timeBin - rDat = append(rDat, rd) + rDat = append(rDat, rd) + } else { + if strings.Contains(string(line), "START") { + relevant = true + continue + } + } } //If there is any unsent data after in is closed we make sure to send it. if len(rDat) > 0 { |