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

Data segmentation in JSON file #81

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

Nawtest
Copy link
Contributor

@Nawtest Nawtest commented Feb 27, 2024

Hello, I have added the 'Detail' block to the JSON file to separate, as much as possible, the data in the report. Additionally, I have modified the returns by adding a count with the number of validations performed to calculate KPIs.

Here examples:

image

image

image

New methods for creating the detailed structure and generating the corresponding JSON.
…otals.

The 'detail' block is added to segment the reported data, and all returns are modified to have the totals checked by each validator, thus enabling data collection for KPIs.

root = xml.etree.ElementTree.fromstring(obj_xml_string)

list_atr_remove = ['loc']
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add a comment here as to why you're removing the 'loc' attribute

Copy link
Contributor Author

@Nawtest Nawtest Feb 28, 2024

Choose a reason for hiding this comment

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

Okay, I'll add a comment, but I'll also comment it here just in case you see another solution. The issue is that they've added the 'loc' attribute, and now the script doesn't retrieve the data properly from the XML. Here's an example.

image

What I've done is clean the XML of attributes. I did it this way in case they add other attributes later on.

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for explaining

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the long response time, my work and personal lives have both been very busy.

I was doing some testing and noticed a problem:
Some validators retrieve attributes, like the name, as is done here: https://github.com/moshekaplan/palo_alto_firewall_analyzer/blob/main/src/palo_alto_firewall_analyzer/validators/misleading_objects.py#L27 :

address_dict = xml_object_to_dict(address_entry)
entry_name = address_dict['entry']['@name']

Therefore, removing the attributes breaks at least that validator - probably more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, no problem at all, I understand this is a hobby, there are more important things. I don't understand what you mean, I've been testing and I wasn't getting any errors, well, except for my files,... but the only tag I remove is 'loc' and I make it nominal, I don't remove any other name or anything. Could you provide some kind of example of your tests? As I mentioned, with the exported files I've been working with, both with the '@loc' tag and without it, I haven't had any issues. Thanks.

Copy link
Owner

Choose a reason for hiding this comment

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

Sorry for the super-delayed follow-up on this.

Say I have an address object with a single IP-netmask of 127.0.0.1.

The old code (now called with xml_object_to_dict1) would result in a dict like the following:

(Pdb) xml_object_to_dict1(address_entry)
{'entry': {'@name': 'ip-127.0.0.1', 'ip-netmask': '127.0.0.1'}}

The new code (what in this PR is called xml_object_to_dict) removes the @name attribute, resulting in the following:

(Pdb) xml_object_to_dict(address_entry)
{'entry': {'ip-netmask': '127.0.0.1'}}

This is problematic because of code that accesses the @name attribute, like:
https://github.com/Nawtest/palo_alto_firewall_analyzer/blob/main/src/palo_alto_firewall_analyzer/validators/misleading_objects.py#L28 :

entry_name = address_dict['entry']['@name']

Because the @name attribute is missing, the dictionary access fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okiz, don't worry, I'll review it. It's strange to me that this attribute gets removed; the one I remove is '@loc'. I'll check it to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi, I am checking the code, and I don't understand why removing the 'loc' tag causes an error when looking for the 'name' tag. It is true that in my XML files, there are some entries without the 'name' tag. I added an if statement to check the issue, and this is the result:

  • if not delete the 'loc' tag, member is:
    image

  • if delete the 'loc' tag, and include a if, the json generated is:
    image

This example my file:
image

Not include 'name' tag

@Nawtest
Copy link
Contributor Author

Nawtest commented Mar 14, 2024

I remove the check of output-format = None, and fixed problem with function parsed to json

@moshekaplan
Copy link
Owner

Would you be able to resolve the conflicts so I can review it for merging?

@Nawtest
Copy link
Contributor Author

Nawtest commented Apr 5, 2024

Hi, I've resolved the conflicts but logically, due to having made structural changes, the tests are failing. I'm reviewing them and adding the correct returns.

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