Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1: attempt a fix #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

#1: attempt a fix #7

wants to merge 1 commit into from

Conversation

j4ng5y
Copy link

@j4ng5y j4ng5y commented Oct 4, 2019

remove the need to read the file in first, append the logfile json contents to the file instead of re-writing it

…n contents to the file instead of re-writing it
@spitfire55
Copy link
Collaborator

spitfire55 commented Oct 7, 2019

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:

  1. If this is the first Connection we see, simply append it to the Connections object via Marshal/Unmarshaling the entire file.
  2. 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!

@j4ng5y
Copy link
Author

j4ng5y commented Oct 8, 2019

Sorry, I guess I missed that it's an array. I can work on revising here shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants