gourmet
gourmet copied to clipboard
#1: attempt a fix
remove the need to read the file in first, append the logfile json contents to the file instead of re-writing it
This won't work since the Connections JSON object is an array. Right now, this is what your changes do:
{
"NetworkInterface": "eno1",
"NetworkAddress": [
"192.168.1.169/24",
"fe80::b7e9:59c1:b3d9:6ba0/64"
],
"Connections": null
}{
"Connections": [
{
"Timestamp": "2019-10-07T19:37:39.082109227-04:00",
"UID": 12935341172492116558,
"SourceIP": "192.168.1.72",
"SourcePort": 5353,
"DestinationIP": "224.0.0.251",
"DestinationPort": 5353,
"TransportType": "udp",
"Analyzers": {}
}
]
}{
"Connections": [
{
"Timestamp": "2019-10-07T19:37:39.082278705-04:00",
"UID": 12935341172492116558,
"SourceIP": "192.168.1.72",
"SourcePort": 5353,
"DestinationIP": "224.0.0.251",
"DestinationPort": 5353,
"TransportType": "udp",
"Analyzers": {}
}
]
}
The logic needs to be a bit more complex so that:
- If this is the first Connection we see, simply append it to the Connections object via Marshal/Unmarshaling the entire file.
- For 2 to n connections, os.Seek() into the file until we are just past the closing curly brace of the previous connection. Then, add a comma and append the new Connection. This will allow us to insert a new Connection into the existing JSON array without having to Unmarshal/Marshal the entire array.
I can finish this up if it's not clear what needs to be done. Thanks for your help!
Sorry, I guess I missed that it's an array. I can work on revising here shortly