Update parsing for reporting

This commit is contained in:
geoffrey 2023-06-06 21:23:47 +02:00
parent 7e2c6b3ee8
commit 8b2e9cbd29

@ -22,7 +22,7 @@ class Parsing(ParsingBase):
lines = data.splitlines() lines = data.splitlines()
numLines = 1 numLines = 1
self._constructResults(filename='/etc/sysctl.conf') self._constructReports(filename='/etc/sysctl.conf')
vulnerabilityFound = dict() vulnerabilityFound = dict()
@ -53,24 +53,26 @@ class Parsing(ParsingBase):
# And check if the flag is specified and need to put on the sysctl config # And check if the flag is specified and need to put on the sysctl config
for entry in vulnerabilityFound: for entry in vulnerabilityFound:
obj = vulnerabilityFound[entry] obj = vulnerabilityFound[entry]
self._reports[entry]['result'] = dict()
if obj['occurence'] > 0: if obj['occurence'] > 0:
print(entry) #print(entry)
print(obj) #print(obj)
if obj['current_value'] != obj['recommand_value']: if obj['current_value'] != obj['recommand_value']:
self._reports[entry]['result'] = "failed" self._reports[entry]['result']['result'] = "failed"
self._reports[entry]['message'] = \ #self._reports[entry]['message'] = \
f"You specify this value {obj['current_value']}" \ # f"You specify this value {obj['current_value']}" \
", you should use this value {obj['recommand_value']}" # ", you should use this value {obj['recommand_value']}"
else: else:
self._reports[entry]['result'] = "success" self._reports[entry]['result']['result'] = "failed"
else: else:
# No find the flag, we recommand to enable it # No find the flag, we recommand to enable it
self._reports[entry]['message'] = "" self._reports[entry]['result']['result'] = "failed"
# We can generate the report # We can generate the report
print(self._reports) print(self._reports)
print("") print("")
print(vulnerabilityFound) from json import dumps
print(dumps(vulnerabilityFound, indent=4))
def _parsingFile(self, line, obj, vulnerabilityFound) -> bool: def _parsingFile(self, line, obj, vulnerabilityFound) -> bool:
""" """
@ -92,7 +94,7 @@ class Parsing(ParsingBase):
return result return result
def _constructResults(self, filename): def _constructReports(self, filename):
""" """
Construct dictionary for result of the tests Construct dictionary for result of the tests
Each entry contains: Each entry contains: