From 4c631c67f94a208ff60641df4fe1f8912cb3512b Mon Sep 17 00:00:00 2001 From: Jon Date: Thu, 22 Feb 2024 20:10:13 +0930 Subject: [PATCH] feat(agent): if hostname present in nmap scan report, add to report for server !8 #4 --- playbooks/tasks/scan_subnet.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/playbooks/tasks/scan_subnet.yaml b/playbooks/tasks/scan_subnet.yaml index 9ad9ba3..25ebcd8 100644 --- a/playbooks/tasks/scan_subnet.yaml +++ b/playbooks/tasks/scan_subnet.yaml @@ -43,6 +43,13 @@ "subnetId": "{{ subnet.id }}", "ip": "{{ scanned_host.address['@addr'] | default(scanned_host.address[0]['@addr']) }}", "lastSeen": "{{ nmap_scan.start }}", + {% if scanned_host.hostnames.hostname is defined %} + {% if '.' in scanned_host.hostnames.hostname['@name'] | string %} + "hostname": "{{ (scanned_host.hostnames.hostname['@name'] | split('.'))[0] }}", + {% else %} + "hostname": "{{ scanned_host.hostnames.hostname['@name'] }}", + {% endif %} + {% endif %} {% if scanned_host.address['@addrtype'] | default(scanned_host.address[1]['@addrtype']) == 'mac' %} "mac": "{{ scanned_host.address['@addr'] | default(scanned_host.address[1]['@addr']) | upper }}" {% endif %}