-
Notifications
You must be signed in to change notification settings - Fork 6
/
util.go
51 lines (42 loc) · 1.37 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"strconv"
"strings"
)
// parseTincStat creates an object out of tinc log lines
func parseTincStat(loglines []string) (*TincStat, error) {
// Handle Total Bytes
bytes_in_line := strings.Fields(loglines[1])
bytes_out_line := strings.Fields(loglines[2])
totalbytesin, _ := strconv.ParseInt(bytes_in_line[len(bytes_in_line)-1], 10, 64)
totalbytesout, _ := strconv.ParseInt(bytes_out_line[len(bytes_out_line)-1], 10, 64)
// Find and Parse Connections List
var connections []TincConnection
inside_connections_stanza := false
for _, line := range loglines {
if strings.Contains(line, "Connections:") {
inside_connections_stanza = true
continue
}
if strings.Contains(line, "End of connections.") {
inside_connections_stanza = false
break
}
if inside_connections_stanza {
fields := strings.Fields(line)
port, _ := strconv.ParseInt(fields[7], 10, 64)
tinc_conn := TincConnection {
Name: fields[3],
Ip: fields[5],
Port: port,
}
connections = append(connections, tinc_conn)
}
}
ts := &TincStat {
TotalBytesIn: totalbytesin,
TotalBytesOut: totalbytesout,
Connections: connections,
}
return ts, nil
}