From 68f43bf70f8aeea654d4f1a6d208822c320498e7 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 20 Feb 2024 15:28:36 +0930 Subject: [PATCH] fix: Use updated scan structure !1 --- playbooks/server.yaml | 4 +++- playbooks/tasks/scan_subnet.yaml | 16 +++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/playbooks/server.yaml b/playbooks/server.yaml index 176af38..e28aa87 100644 --- a/playbooks/server.yaml +++ b/playbooks/server.yaml @@ -38,7 +38,9 @@ SELECT id, subnet FROM subnets WHERE scanAgent='{{ mysql_query_agent_details.query_result[0][0].id }}' and - subnet='{{ inbound_data.scan[0].subnet | ip2ipam }}' + subnet='{{ (inbound_data.scan.subnet | split('/'))[0] | ip2ipam }}' + and + mask = '{{ (inbound_data.scan.subnet | split('/'))[1] | int }}' single_transaction: true register: mysql_query_agent_subnets diff --git a/playbooks/tasks/scan_subnet.yaml b/playbooks/tasks/scan_subnet.yaml index 4c70421..a2fc1d3 100644 --- a/playbooks/tasks/scan_subnet.yaml +++ b/playbooks/tasks/scan_subnet.yaml @@ -26,17 +26,23 @@ subnet_scan_results: |- [ {% for scanned_host in ((nmap_scan.stdout | ansible.utils.from_xml) | from_yaml).nmaprun.host %} - {% if scanned_host.address[0]['@addrtype'] | default('') == 'ipv4' %} + {% if + scanned_host.address[0]['@addrtype'] | default('') == 'ipv4' + or + scanned_host.address['@addrtype'] | default('') == 'ipv4' + %} { - {% for cached_host in cached_subnet -%} - {%- if cached_host.ip == scanned_host.address[0]['@addr'] -%} + {% for cached_host in cached_subnet | default([]) -%} + {%- if cached_host.ip == scanned_host.address['@addr'] | default(scanned_host.address[0]['@addr']) -%} "id": {{ cached_host.id }}, {%- endif -%} {%- endfor %} "subnetId": "{{ subnet.id }}", - "ip": "{{ scanned_host.address[0]['@addr'] }}", + "ip": "{{ scanned_host.address['@addr'] | default(scanned_host.address[0]['@addr']) }}", "lastSeen": "{{ nmap_scan.start }}", - "mac": "{{ scanned_host.address[1]['@addr'] | upper }}" + {% 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 %} }, {% endif %} {% endfor %}