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

feat(iftop): add iftop-scanning #484

Merged

Conversation

georgettica
Copy link
Contributor

this is not even an MVP, but I would like it to exist to allow per client json aggregation

also, a future use is a stream response

this is not even an MVP, but I would like it to exist to allow per client json aggregation

also, a future use is a stream response
@georgettica georgettica mentioned this pull request Nov 20, 2023
jc/parsers/iftop.py Outdated Show resolved Hide resolved
jc/parsers/iftop.py Outdated Show resolved Hide resolved
@georgettica georgettica force-pushed the georgettica/feature/iftop branch from 1ce10b1 to c5c9858 Compare December 4, 2023 14:58
@georgettica georgettica changed the title [WIP] feat(iftop): add iftop-scanning feat(iftop): add iftop-scanning Dec 4, 2023
@georgettica georgettica force-pushed the georgettica/feature/iftop branch from c5c9858 to 338c4a0 Compare December 4, 2023 15:03
@georgettica georgettica marked this pull request as ready for review December 4, 2023 15:03
@georgettica
Copy link
Contributor Author

@kellyjonbrazil this was at last done and has tests, now we can move towards merging this

@georgettica
Copy link
Contributor Author

code currently does not pass, but works locally :) I will fix the issue with the test tomorrow :)

Comment on lines 181 to 192
# for backwards compatibility, preset all fields to None
interface_obj: Dict = {
"device": None,
"ip_address": None,
"mac_address": None,
"clients": None,
"total_send_rate": None,
"total_receive_rate": None,
"total_send_and_receive_rate": None,
"peak_rate": None,
"cumulative_rate": None,
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this section. This was for backwards compatibility for another parser.

"cumulative_rate": None,
}

interface_item: Dict = interface_obj.copy()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a normal empty dict. I was just copying in the other parser so it would keep the default values for backward compatibility.

@kellyjonbrazil
Copy link
Owner

Looking good!

@georgettica
Copy link
Contributor Author

@kellyjonbrazil fixed review comments and tests still pass :)

@georgettica
Copy link
Contributor Author

I am not sure if it's needed, but I needed the filesize to be converted to int bytes, so I added the functionality

I can extract the code to a generic location in utils if you deem it helpful @kellyjonbrazil

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete the completion scripts as I auto generate them with the documentation.

Copy link
Owner

@kellyjonbrazil kellyjonbrazil Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe not delete them, but revert them back to original. You should only need to update the parser.py file and the lib.py file for a new parser. I'll handle all the documentation and completion updates when creating the release. This will make the PR smaller and easier to reason about.

requirements.txt Outdated
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't introduce any new requirements/dependencies. There may be a way to vendor this in or create our own function that does something similar.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we can pull the tokenize() function and the parse_size() functions from the library. If you want, you can put them directly in the parser and I'll move them to utils.py later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@georgettica
Copy link
Contributor Author

I expected that we won't add new requirements, and I am ok with reverting the completions.

I will do these in a few hours and ping, hopefully we can merge this today 🤞

@kellyjonbrazil
Copy link
Owner

Sweet! I'm on a plane now coming at you from 30k feet and will be traveling a bit this week, so I may be able to merge this later this week or this weekend. Also, I can possibly take your work and turn this into a streaming parser.

@georgettica
Copy link
Contributor Author

I am ok with this as long as we are fine with merging this first.
I am currently using my repo and branch for internal work but I would rather have it be upstream, so others can enjoy it aswell :)
enjoy your travels and flight.

as it is already almost mid week this also soundslike a short time to wait.

@@ -0,0 +1,622 @@
"""jc - JSON Convert `iftop` command output parser

No `iftop` options are supported.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there only certain options that are supported or can we remove this if all options are supported? From the example and tests it looks like at least some options are supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I just didn't read this 🤦‍♂️
I'll see if I can fix it via the web browser.

To be honest I just always pipe it in because it requires sudo and I didn't want to run jc as sufo

@kellyjonbrazil kellyjonbrazil changed the base branch from master to dev December 8, 2023 02:19
@kellyjonbrazil kellyjonbrazil merged commit 0e7ebf4 into kellyjonbrazil:dev Dec 8, 2023
21 checks passed
@georgettica georgettica deleted the georgettica/feature/iftop branch December 10, 2023 10:01
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