Skip to content

Commit

Permalink
Change: Rename internal var hostname to host_ip
Browse files Browse the repository at this point in the history
The internal variable "hostname" of the scan report transformation is
renamed to "host_ip" to later avoid confusion with the actual hostname.
  • Loading branch information
timopollmeier committed Nov 28, 2023
1 parent 9afd2b8 commit b53a637
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pheme/transformation/scanreport/gvmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __group_refs(refs: Dict[str, str]) -> Dict:
return refs_ref


def __get_hostname_from_result(result) -> str:
def __get_host_ip_from_result(result) -> str:
if isinstance(result, str):
return result
if isinstance(result, dict):
Expand Down Expand Up @@ -179,8 +179,8 @@ def transform_key(prefix: str, vic: Dict) -> Dict:
return {f"{prefix}_{key}": value for key, value in vic.items()}

def per_result(result):
hostname = __get_hostname_from_result(result)
host_dict = by_host.get(hostname, {})
host_ip = __get_host_ip_from_result(result)
host_dict = by_host.get(host_ip, {})
threat = result.get("threat", "unknown")
port = result.get("port")
nvt = transform_key("nvt", result.get("nvt", {}))
Expand Down Expand Up @@ -209,28 +209,28 @@ def per_result(result):
ports = set(ports + [port])
equipment["ports"] = ports
if not equipment.get("os"):
equipment["os"] = host_information_lookup.get(hostname, {}).get(
equipment["os"] = host_information_lookup.get(host_ip, {}).get(
"os", "unknown"
)

# needs hostname, high, medium, low
# needs host_ip, high, medium, low
host_threats = host_threat_count.get(
hostname, {threat: 0 for threat in __threats}
host_ip, {threat: 0 for threat in __threats}
)
threat_index = __threat_index_lookup.get(threat)
if threat_index is not None:
threat_count[threat_index] += 1
if host_threats.get(threat) is not None:
host_threats[threat] += 1
host_threat_count[hostname] = host_threats
host_threat_count[host_ip] = host_threats

# needs high, medium, low

# severity 1 to 10
host_severities = host_severity_count.get(hostname, [0] * 10)
host_severities = host_severity_count.get(host_ip, [0] * 10)
if severity > 0:
host_severities[int(severity) - 1] += 1
host_severity_count[hostname] = host_severities
host_severity_count[host_ip] = host_severities

def per_note(note):
result_notes = new_host_result.get("notes", [])
Expand Down Expand Up @@ -273,8 +273,8 @@ def per_override(override):
for override in overrides:
per_override(override)

by_host[hostname] = {
"host": hostname,
by_host[host_ip] = {
"host": host_ip,
"threats": __host_threat_overview(host_threats),
"severities": __host_severity_overview(host_severities),
"equipment": equipment,
Expand Down

0 comments on commit b53a637

Please sign in to comment.