mirror of
https://github.com/aquasecurity/kube-hunter.git
synced 2026-05-11 11:47:15 +00:00
changed table output to be using the logging module
This commit is contained in:
@@ -75,17 +75,18 @@ class DefaultReporter(object):
|
||||
desc=wrap_last_line(console_trim(self.event.explain(), '| '))
|
||||
))
|
||||
|
||||
def print_tables(self):
|
||||
"""generates report tables and outputs to stdout"""
|
||||
def get_tables(self):
|
||||
"""generates report tables"""
|
||||
output = ""
|
||||
if len(services):
|
||||
print_nodes()
|
||||
output += nodes_table()
|
||||
if not config.mapping:
|
||||
print_services()
|
||||
print_vulnerabilities()
|
||||
output += services_table()
|
||||
output += vulns_table()
|
||||
else:
|
||||
print "\nKube Hunter couldn't find any clusters"
|
||||
# print "\nKube Hunter couldn't find any clusters. {}".format("Maybe try with --active?" if not config.active else "")
|
||||
|
||||
return output
|
||||
|
||||
reporter = DefaultReporter()
|
||||
|
||||
@@ -96,13 +97,11 @@ class SendFullReport(object):
|
||||
self.event = event
|
||||
|
||||
def execute(self):
|
||||
print "\nReport:"
|
||||
print "{}\n".format("-" * MAX_TABLE_WIDTH)
|
||||
reporter.print_tables()
|
||||
logging.info("\nReport:\n{div}\n{tables}".format(div="-" * MAX_TABLE_WIDTH, tables=reporter.get_tables()))
|
||||
|
||||
|
||||
""" Tables Generation """
|
||||
def print_nodes():
|
||||
def nodes_table():
|
||||
nodes_table = PrettyTable(["Type", "Location"], hrules=ALL)
|
||||
nodes_table.align="l"
|
||||
nodes_table.max_width=MAX_TABLE_WIDTH
|
||||
@@ -117,12 +116,10 @@ def print_nodes():
|
||||
if service.event_id not in id_memory:
|
||||
nodes_table.add_row(["Node/Master", service.host])
|
||||
id_memory.append(service.event_id)
|
||||
print "Nodes"
|
||||
print nodes_table
|
||||
print
|
||||
return "\nNodes\n{}\n".format(nodes_table)
|
||||
|
||||
|
||||
def print_services():
|
||||
def services_table():
|
||||
services_table = PrettyTable(["Service", "Location", "Description"], hrules=ALL)
|
||||
services_table.align="l"
|
||||
services_table.max_width=MAX_TABLE_WIDTH
|
||||
@@ -132,12 +129,11 @@ def print_services():
|
||||
services_table.header_style="upper"
|
||||
for service in services:
|
||||
services_table.add_row([service.get_name(), "{}:{}{}".format(service.host, service.port, service.get_path()), service.explain()])
|
||||
print "Detected Services"
|
||||
print services_table
|
||||
print
|
||||
|
||||
return "\nDetected Services\n{}\n".format(services_table)
|
||||
|
||||
|
||||
def print_vulnerabilities():
|
||||
def vulns_table():
|
||||
column_names = ["Location", "Category", "Vulnerability", "Description", "Evidence"]
|
||||
vuln_table = PrettyTable(column_names, hrules=ALL)
|
||||
vuln_table.align="l"
|
||||
@@ -150,7 +146,5 @@ def print_vulnerabilities():
|
||||
row = ["{}:{}".format(vuln.host, vuln.port) if vuln.host else "", vuln.category.name, vuln.get_name(), vuln.explain()]
|
||||
evidence = str(vuln.evidence)[:EVIDENCE_PREVIEW] + "..." if len(str(vuln.evidence)) > EVIDENCE_PREVIEW else str(vuln.evidence)
|
||||
row.append(evidence)
|
||||
vuln_table.add_row(row)
|
||||
print "Vulnerabilities"
|
||||
print vuln_table
|
||||
print
|
||||
vuln_table.add_row(row)
|
||||
return "\nVulnerabilities\n{}\n".format(vuln_table)
|
||||
|
||||
Reference in New Issue
Block a user