Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
089a0ed11c | |||
33a035cf6b | |||
1e8f3901d4 | |||
b0619f4b8f | |||
82b8f535bb | |||
f89212b1cb | |||
93d40b7432 | |||
3ed00b733e | |||
953a97610d | |||
0d11c40e21 | |||
46f25ea616 | |||
181a3bdc44 | |||
667de0a41b | |||
4d19ead2f1 | |||
87b9296317 | |||
b005a31aab | |||
15b0ddb068 | |||
8f7ed4888a | |||
cf879ac81b |
2
.cz.yaml
2
.cz.yaml
@ -4,5 +4,5 @@ commitizen:
|
||||
prerelease_offset: 1
|
||||
tag_format: $version
|
||||
update_changelog_on_bump: false
|
||||
version: 0.2.0-a2
|
||||
version: 0.3.0
|
||||
version_scheme: semver
|
||||
|
@ -19,6 +19,8 @@ variables:
|
||||
DOCKER_IMAGE_PUBLISH_REGISTRY: docker.io/nofusscomputing
|
||||
DOCKER_IMAGE_PUBLISH_URL: https://hub.docker.com/r/nofusscomputing/$DOCKER_IMAGE_PUBLISH_NAME
|
||||
|
||||
RELEASE_ADDITIONAL_ACTIONS_BUMP: ./.gitlab/additional_actions_bump.sh
|
||||
|
||||
|
||||
include:
|
||||
|
||||
@ -28,6 +30,7 @@ include:
|
||||
ref: development
|
||||
file:
|
||||
- .gitlab-ci_common.yaml
|
||||
- conventional_commits/.gitlab-ci.yml
|
||||
- template/ansible-collection.gitlab-ci.yaml
|
||||
- template/mkdocs-documentation.gitlab-ci.yaml
|
||||
# ToDo: update gitlabCI jobs for collections workflow
|
||||
|
13
.gitlab/additional_actions_bump.sh
Normal file
13
.gitlab/additional_actions_bump.sh
Normal file
@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
|
||||
sed -E "/http_agent: nfc-phpipam-scan-agent/s/\/(.+)/\/$(cz version --project)/g" -i playbooks/tasks/scan_subnet.yaml;
|
||||
|
||||
git add playbooks/tasks/scan_subnet.yaml;
|
||||
|
||||
git status;
|
||||
|
||||
sed -E "/http_agent: nfc-phpipam-scan-agent/s/\/(.+)/\/$(cz version --project)/g" -i playbooks/tasks/api_call.yaml;
|
||||
|
||||
git add playbooks/tasks/api_call.yaml;
|
||||
|
||||
git status;
|
40
CHANGELOG.md
40
CHANGELOG.md
@ -1,19 +1,29 @@
|
||||
## 0.2.0-a2 (2024-02-23)
|
||||
## 0.3.0 (2024-02-25)
|
||||
|
||||
### Feat
|
||||
|
||||
- **server**: DNS Reverse Lookup for IP Address'
|
||||
- **server**: Convert scanned time within scan report to UTC
|
||||
|
||||
### Fix
|
||||
|
||||
- **ci**: http user_agent version set during version bump
|
||||
- **server**: Time of last access for scan agent to use 'now'
|
||||
|
||||
## 0.2.0 (2024-02-24)
|
||||
|
||||
### Feat
|
||||
|
||||
- **server**: Update the time of last access for scan agent
|
||||
- **scanner**: Add scanner timezone to scan report
|
||||
- **scanner**: don't include PTR DNS records as hostname
|
||||
- **scanner**: for ssl cert validation when uploading to server
|
||||
- **scanner**: if an auth token has been set, fail non-https communication with server
|
||||
- **scanner**: Set user http user agent to <name>/<version>
|
||||
- **server**: scanner identity confirmation
|
||||
- **server**: update subnet discovery date/time
|
||||
- **server**: move config of variables to vars file
|
||||
- **agent**: move config of variables to vars file
|
||||
|
||||
### Refactor
|
||||
|
||||
- **server**: don't process scan results in parallel
|
||||
|
||||
## 0.2.0-a1 (2024-02-22)
|
||||
|
||||
### Feat
|
||||
|
||||
- **server**: if hostname in scan report, update the database
|
||||
- **agent**: if hostname present in nmap scan report, add to report for server
|
||||
- **agent**: showsubnet address in logs when conducting subnet actions
|
||||
@ -26,17 +36,13 @@
|
||||
- **agent**: only attempt to scan subnet if subnets were returned
|
||||
- **agent**: cater for api call that returns nothing
|
||||
- **docker**: ensure correct variable used to install package
|
||||
- **build**: ensure the correct tags and architectures are published
|
||||
|
||||
### Refactor
|
||||
|
||||
- **server**: don't process scan results in parallel
|
||||
- **api_call**: use var name that makes more sense
|
||||
|
||||
## 0.1.2-a1 (2024-02-21)
|
||||
|
||||
### Fix
|
||||
|
||||
- **build**: ensure the correct tags and architectures are published
|
||||
|
||||
## 0.1.1 (2024-02-21)
|
||||
|
||||
### Fix
|
||||
@ -48,7 +54,6 @@
|
||||
### Feat
|
||||
|
||||
- **docker**: adjust scanner job to run every 5 mins
|
||||
- **docs**: add initial doc layout and CI jobs
|
||||
|
||||
### Fix
|
||||
|
||||
@ -56,4 +61,3 @@
|
||||
- **ci**: ensure correct github sync repo is used
|
||||
- **ci**: ensure docker build and publish occurs
|
||||
- Don't process results if scan report is empty
|
||||
- **docs**: correct nav link
|
||||
|
@ -32,6 +32,8 @@ This collection is available on Ansible Galaxy and can be installed with `ansibl
|
||||
|
||||
Prefer to use our [docker](docker.md) image? It's available on Docker Hub `docker pull nofusscomputing/phpipam-scan-agent:latest`.
|
||||
|
||||
There is no timezone support within phpIPAM. Due to this it's recommended that you setup phpIPAM, the database and the scanner component to use UTC (GMT +00:00) timezone or that all components be setup to use the same timezone.
|
||||
|
||||
|
||||
## Features
|
||||
|
||||
@ -50,9 +52,11 @@ The following features are available or planned to be implmented:
|
||||
!!! info
|
||||
It's only possible to obtain a MAC Address if the scanner is on the same L2 network (Broadcast Domain). Within the docs you will find the different methods available to achieve this.
|
||||
|
||||
- [**ToDo** Remote Network Scanning](https://gitlab.com/nofusscomputing/projects/ansible/collections/phpipam_scan_agent/-/issues/1)
|
||||
- [Remote Network Scanning](scanner.md#remote-network-scannning)
|
||||
|
||||
- [**ToDo** Resolve DNS names](https://gitlab.com/nofusscomputing/projects/ansible/collections/phpipam_scan_agent/-/issues/4)
|
||||
- [Resolve DNS names](index.md#Resolve-dns-names)
|
||||
|
||||
- [Timezone Normalization](server.md#timezone-normalization)
|
||||
|
||||
|
||||
## phpIPAM Features
|
||||
@ -75,6 +79,27 @@ When this setting is enabled, the scanner will scan the entire subnet that has b
|
||||
This is displayed within the subnet interface next to the `Discover new hosts` field. Whenever a scan report is received by the server this filed is updated to reflect the last scan time.
|
||||
|
||||
|
||||
### Resolve DNS names
|
||||
|
||||
- Location `Subnet -> Resolve DNS names`
|
||||
|
||||
When this setting is enabled, DNS resolution for the hostname for any IP found will be conducted. If you have setup nameservers (`Administration -> Nameservers`) and assigned them to the subnet, they will be used for name resolution. If no nameservers are configured for the subnet, the host's nameservers where the scanner is running from will be used. BY default within phpIPAM, DNS Resolution is turned off for a subnet and as such the scanner will not resolve IP address DNS names.
|
||||
|
||||
!!! info
|
||||
The FQDN for an IP that is retured is not used as the hostname. **Only** the first octet. i.e. if the reverse DNS lookup returns a FQDN of `my_hostname.domainname.tld`, the hostname for the IP address will be set to `my_hostname`
|
||||
|
||||
|
||||
### Scan Agent
|
||||
|
||||
- Location `Administration -> Scan agents [Last access]`
|
||||
|
||||
This is displayed within the Scan Agent table in column `Last access`. When ever the scanner checks in, the time of the checkin is used to update the field.
|
||||
|
||||
- Location `Subnet -> Scan agent [Last Check]`
|
||||
|
||||
This is displayed within the subnet interface next to `Scan agent` field. When ever the scanner checks in, the time of the checkin is used to update the field.
|
||||
|
||||
|
||||
## Development Notes
|
||||
|
||||
Contributions to this project are welcome. Below you will find some useful commands for use during development.
|
||||
|
@ -38,14 +38,15 @@ nofusscomputing_phpipam_scan_agent:
|
||||
|
||||
http_port: 5000 # Optional, Integer. http port to connect to the server.
|
||||
http_server: http://127.0.0.1 # Optional, Integer. url with protocol of the Scan Server to connect to.
|
||||
auth_token: # Optional, String. The Scan-Agent server authentication token.
|
||||
|
||||
cache_expire_time: 1800 # Optional, Integer. Time in seconds to expire the phpIPAM cache.
|
||||
epoch_time_offset: 0 # optional, int. Value in seconds to offset the time
|
||||
|
||||
# phpIPAM Scan Agent Settings
|
||||
client_token: # Mandatory, String client api token to connect to phpIPAM API [client_token]
|
||||
client_name: # Mandatory, String. The scanner name as set in phpIPAM interface [client_name]
|
||||
scanagent_code: # Mandatory, String. Scan Agent Code as set in phpIPAM interface [scanagent_code]
|
||||
client_token: # Mandatory, String client api token to connect to phpIPAM API
|
||||
client_name: # Mandatory, String. The scanner name as set in phpIPAM interface
|
||||
scanagent_code: # Mandatory, String. Scan Agent Code as set in phpIPAM interface
|
||||
|
||||
|
||||
```
|
||||
@ -93,3 +94,15 @@ The scanner component has the following workflow:
|
||||
1. upload scan report to configured Server.
|
||||
|
||||
1. workflow complete.
|
||||
|
||||
|
||||
## Remote network Scannning
|
||||
|
||||
Once the [server component](server.md#remote-network-scannning) has been setup, the client can be installed/used from any network. Even a network that is isolated from the server. Only caveat is that the client can communicate with the server. To ensure that the client can connect to the server set the `auth_token` to match that of the server.
|
||||
|
||||
There is no true confirmation of the servers identity outside of confirming the TLS Certificate is trusted. Due to this fact, you're advised to use your own CA to sign the server components TLS Certificate. By doing this only you can issue a certificate to the server component. All that is required is to ensure that your CA certificate is within the trusted certificates of the machine that is running the agent.
|
||||
|
||||
!!! danger "Security"
|
||||
Failing to secure the server component communication with TLS will allow anyone with direct access to the line of communication to view the `auth_token`. Anyone who has the `auth_token` will be able to upload data to the server.
|
||||
|
||||
In an attempt to mitigate this, the scanner will fail to communicate with the server if you have set an `auth_token` and attempt non-TLS communication with the server.
|
||||
|
@ -29,14 +29,15 @@ The variables described below, if optional the value specified here is the defau
|
||||
nofusscomputing_phpipam_scan_server:
|
||||
|
||||
# phpIPAM MariaDB/MySQL Variables
|
||||
mysql_host: # Mandatory, String. IP/DNS of host to connect. [nfc_c_]
|
||||
mysql_port: 3306 # Optional, Integer. port to use for connection. [nfc_c_]
|
||||
mysql_user: # Mandatory, String. User to authenticate with. [nfc_c_]
|
||||
mysql_password: # Mandatory, String. Password for the user to connect with. [nfc_c_]
|
||||
mysql_host: # Mandatory, String. IP/DNS of host to connect.
|
||||
mysql_port: 3306 # Optional, Integer. port to use for connection.
|
||||
mysql_user: # Mandatory, String. User to authenticate with.
|
||||
mysql_password: # Mandatory, String. Password for the user to connect with.
|
||||
|
||||
|
||||
# Server Component Variables
|
||||
http_port: 5000 # Optional, Integer. The port for the Server component to listen for connections.
|
||||
auth_token: # Optional, String. Token used to authentication Agents.
|
||||
|
||||
```
|
||||
|
||||
@ -56,3 +57,17 @@ The Server componet has the following workflow:
|
||||
- _if no results found, no further processing occurs_
|
||||
|
||||
1. Update the phpIPAM MariaDB/MySQL database directly
|
||||
|
||||
|
||||
## Remote network Scannning
|
||||
|
||||
Remote network scanning is possible with the Scan-Agent. The server must be setup and have connectivity to the phpIPAM MariaDB/MySQL database. Currently the server does not perform secure communication. As such you are strongly encouraged to setup the server component behind a reverse proxy that conducts the TLS termination.
|
||||
|
||||
The [scan](scanner.md#remote-network-scannning) and server component must be setup with the same `auth_token`. It is this token that provides a means to ensure that what the server is receiving, is from an authorized client.
|
||||
|
||||
!!! danger "Security"
|
||||
Failing to secure the server component communication with TLS will allow anyone with direct access to the line of communication to view the `auth_token`. Anyone who has the `auth_token` will be able to upload data to the server.
|
||||
|
||||
## Timezone normalization
|
||||
|
||||
As there is no support within phpIPAM for different timezones. The server component when receiving updates from scanners, will convert any time found to UTC (GMT +00:00). This is required so that phpIPAM features that rely on time, function as they should. This setup requires that machine or docker containers for phpIPAM and the MySQL/MariaDB database both have their timezones set to UTC. If you don't wish for any timezone conversion to be done, ensure that where ever all components, including the scan server component, share the same timezone.
|
||||
|
@ -6,6 +6,7 @@
|
||||
ansible.eda.webhook:
|
||||
host: 0.0.0.0
|
||||
port: "{{ nofusscomputing_phpipam_scan_server.http_port | default(5000) | int }}"
|
||||
token: "{{ nofusscomputing_phpipam_scan_server.auth_token | default('no-token-set') }}"
|
||||
|
||||
rules:
|
||||
|
||||
|
@ -8,7 +8,7 @@ namespace: nofusscomputing
|
||||
name: phpipam_scan_agent
|
||||
|
||||
# The version of the collection. Must be compatible with semantic versioning
|
||||
version: 0.2.0-a2
|
||||
version: 0.3.0
|
||||
|
||||
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
||||
readme: README.md
|
||||
|
Submodule gitlab-ci updated: 34c81c9849...41eeb7badd
@ -16,3 +16,5 @@ nofusscomputing_phpipam_scan_agent:
|
||||
client_token: # Mandatory, String client api token to connect to phpIPAM API [client_token]
|
||||
client_name: # Mandatory, String. The scanner name as set in phpIPAM interface [client_name]
|
||||
scanagent_code: # Mandatory, String. Scan Agent Code as set in phpIPAM interface [scanagent_code]
|
||||
|
||||
# auth_token: # Optional, String. The Scan-Agent server authentication token.
|
||||
|
@ -11,3 +11,5 @@ nofusscomputing_phpipam_scan_server:
|
||||
|
||||
# Server Component Variables
|
||||
# http_port: 5000 # Optional, Integer. The port for the Server component to listen for connections.
|
||||
|
||||
# auth_token: # Optional, String. Token used to authentication Agents.
|
@ -82,3 +82,4 @@
|
||||
api_address: addresses
|
||||
api_subnets: subnets
|
||||
api_scanagents: tools/scanagents
|
||||
api_nameservers: tools/nameservers
|
||||
|
@ -38,6 +38,24 @@
|
||||
register: mysql_query_agent_details
|
||||
|
||||
|
||||
- name: Update Scan Agent Last seen
|
||||
community.mysql.mysql_query:
|
||||
login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}"
|
||||
login_port: "{{ nofusscomputing_phpipam_scan_server.mysql_port | default(3306) | int }}"
|
||||
login_user: "{{ nofusscomputing_phpipam_scan_server.mysql_user }}"
|
||||
login_password: "{{ nofusscomputing_phpipam_scan_server.mysql_password }}"
|
||||
|
||||
login_db: 'phpipam'
|
||||
query: |-
|
||||
UPDATE
|
||||
scanAgents
|
||||
SET
|
||||
last_access = '{{ ('%Y-%m-%d %H:%M:%S' | strftime) }}'
|
||||
WHERE
|
||||
id = '{{ mysql_query_agent_details.query_result[0][0].id }}'
|
||||
single_transaction: true
|
||||
|
||||
|
||||
- name: Confirm Subnet Assignment
|
||||
community.mysql.mysql_query:
|
||||
login_host: "{{ nofusscomputing_phpipam_scan_server.mysql_host }}"
|
||||
|
@ -49,6 +49,8 @@
|
||||
cached_file.stat.exists
|
||||
|
||||
|
||||
# Note: Dont edit http_agent version as the build pipeline updates automagically!!
|
||||
# see ci variable 'RELEASE_ADDITIONAL_ACTIONS_BUMP'
|
||||
- name: >
|
||||
PHPIPAM API Call - {{ api_path }}{%- if api_query_string is defined -%}
|
||||
/?{{ api_query_string }}
|
||||
@ -61,6 +63,7 @@
|
||||
{%- endif %}
|
||||
headers:
|
||||
token: "{{ api_token }}"
|
||||
http_agent: nfc-phpipam-scan-agent/0.3.0
|
||||
return_content: true
|
||||
status_code:
|
||||
- 200
|
||||
|
@ -1,12 +1,5 @@
|
||||
---
|
||||
|
||||
- name: Scan subnet - {{ subnet.address }}
|
||||
ansible.builtin.command:
|
||||
cmd: nmap -sn "{{ subnet.address }}" -oX -
|
||||
become: true
|
||||
register: nmap_scan
|
||||
|
||||
|
||||
- name: Get subnets Address'
|
||||
ansible.builtin.include_tasks:
|
||||
file: tasks/api_call.yaml
|
||||
@ -17,15 +10,72 @@
|
||||
api_query_string: "filter_by=subnetId&filter_value={{ subnet.id }}"
|
||||
|
||||
|
||||
- name: Load Subnet - {{ subnet.address }}
|
||||
- name: Register Subnet API Call
|
||||
ansible.builtin.set_fact:
|
||||
cached_subnet: "{{ lookup('file', cache_filepath) }}"
|
||||
cacheable: false
|
||||
subnet_api_call: "{{ api_call }}"
|
||||
subnet_cache_filepath: "{{ cache_filepath }}"
|
||||
api_call: ''
|
||||
|
||||
|
||||
- name: Get subnet Name Servers
|
||||
ansible.builtin.include_tasks:
|
||||
file: tasks/api_call.yaml
|
||||
vars:
|
||||
api_client_name: "{{ nofusscomputing_phpipam_scan_agent.client_name }}"
|
||||
api_token: "{{ nofusscomputing_phpipam_scan_agent.client_token }}"
|
||||
api_path: "{{ api_nameservers }}"
|
||||
api_query_string: "filter_by=id&filter_value={{ subnet.nameserverId }}"
|
||||
when: >
|
||||
subnet.nameserverId is defined
|
||||
and
|
||||
subnet.resolveDNS | int == 1
|
||||
|
||||
|
||||
- name: Load Nameservers - {{ subnet.address }}
|
||||
ansible.builtin.set_fact:
|
||||
subnet_name_servers: "{{ lookup('file', cache_filepath) }}"
|
||||
cacheable: false
|
||||
no_log: true
|
||||
when: >
|
||||
subnet.nameserverId is defined
|
||||
and
|
||||
subnet.resolveDNS | int == 1
|
||||
and
|
||||
api_call.status | default(0) | int != 404
|
||||
|
||||
|
||||
- name: Scan subnet - {{ subnet.address }}
|
||||
ansible.builtin.command:
|
||||
cmd: >
|
||||
nmap -sn "{{ subnet.address }}" {% if
|
||||
subnet_name_servers is defined
|
||||
and
|
||||
subnet.resolveDNS | int == 1
|
||||
-%}
|
||||
--dns-servers {% for nameserver in subnet_name_servers -%}
|
||||
{% for name_server in nameserver.namesrv1 | split(';') %}
|
||||
{{ name_server }},
|
||||
{%- endfor -%}
|
||||
{%- endfor -%}
|
||||
{%- elif subnet.resolveDNS | int == 1 -%}
|
||||
--system-dns
|
||||
{%- else -%}
|
||||
-n
|
||||
{%- endif %} -oX -
|
||||
become: true
|
||||
register: nmap_scan
|
||||
|
||||
|
||||
- name: Load Subnet - {{ subnet.address }}
|
||||
ansible.builtin.set_fact:
|
||||
cached_subnet: "{{ lookup('file', subnet_cache_filepath) }}"
|
||||
cacheable: false
|
||||
no_log: true
|
||||
when: >
|
||||
subnet_api_call.status | default(0) | int != 404
|
||||
|
||||
|
||||
- name: Process Scan Results - {{ subnet.address }}
|
||||
ansible.builtin.set_fact:
|
||||
subnet_scan_results: |-
|
||||
@ -44,29 +94,77 @@
|
||||
{%- endfor %}
|
||||
"subnetId": "{{ subnet.id }}",
|
||||
"ip": "{{ scanned_host.address['@addr'] | default(scanned_host.address[0]['@addr']) }}",
|
||||
"lastSeen": "{{ nmap_scan.start }}",
|
||||
"lastSeen": "{{ (nmap_scan.start | split('.'))[0] }}",
|
||||
|
||||
{% if scanned_host.hostnames.hostname is defined %}
|
||||
{% if '.' in scanned_host.hostnames.hostname['@name'] | string %}
|
||||
|
||||
{% set ip_address = scanned_host.address['@addr'] | default(scanned_host.address[0]['@addr']) | split('.') %}
|
||||
|
||||
{% if
|
||||
'.' in scanned_host.hostnames.hostname['@name'] | string
|
||||
and
|
||||
(ip_address[0] + '-' + ip_address[1] + '-' + ip_address[2] + '-' + ip_address[3]) not in scanned_host.hostnames.hostname['@name'] | string
|
||||
and
|
||||
(ip_address[3] + '-' + ip_address[2] + '-' + ip_address[1] + '-' + ip_address[0]) not in scanned_host.hostnames.hostname['@name'] | string
|
||||
%}
|
||||
|
||||
"hostname": "{{ (scanned_host.hostnames.hostname['@name'] | split('.'))[0] }}",
|
||||
{% else %}
|
||||
|
||||
{% elif
|
||||
'.' not in scanned_host.hostnames.hostname['@name'] | string
|
||||
and
|
||||
(ip_address[0] + '-' + ip_address[1] + '-' + ip_address[2] + '-' + ip_address[3]) not in scanned_host.hostnames.hostname['@name'] | string
|
||||
and
|
||||
(ip_address[3] + '-' + ip_address[2] + '-' + ip_address[1] + '-' + ip_address[0]) not in scanned_host.hostnames.hostname['@name'] | string
|
||||
%}
|
||||
|
||||
"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 %}
|
||||
},
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
]
|
||||
|
||||
|
||||
- name: Force Failure for non-HTTPS Communication
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- |-
|
||||
not
|
||||
(
|
||||
(
|
||||
'http:' in (nofusscomputing_phpipam_scan_agent.http_server | default(nfc_c_http_server) | string)
|
||||
and
|
||||
'http://127.0.0.1' not in (nofusscomputing_phpipam_scan_agent.http_server | default(nfc_c_http_server) | string)
|
||||
)
|
||||
and
|
||||
nofusscomputing_phpipam_scan_agent.auth_token | default('no-token-set') != 'no-token-set'
|
||||
)
|
||||
fail_msg: 'Failing task as an attempt was made to communicate with the server over a non-encrypted channel'
|
||||
success_msg: 'OK'
|
||||
|
||||
|
||||
- name: To JSON - {{ subnet.address }}
|
||||
ansible.builtin.set_fact:
|
||||
subnet_scan_results: "{{ subnet_scan_results | from_yaml }}"
|
||||
|
||||
|
||||
# Note: Dont edit http_agent version as the build pipeline updates automagically!!
|
||||
# see ci variable 'RELEASE_ADDITIONAL_ACTIONS_BUMP'
|
||||
- name: Upload Scan Results - {{ subnet.address }}
|
||||
ansible.builtin.uri:
|
||||
headers:
|
||||
Authorization: "Bearer {{ nofusscomputing_phpipam_scan_agent.auth_token | default('no-token-set') }}"
|
||||
http_agent: nfc-phpipam-scan-agent/0.3.0
|
||||
url: "{{
|
||||
nofusscomputing_phpipam_scan_agent.http_server | default(nfc_c_http_server)
|
||||
}}:{{ nofusscomputing_phpipam_scan_agent.http_port | default(nfc_c_http_port) }}/"
|
||||
@ -76,6 +174,8 @@
|
||||
"code": "{{ nofusscomputing_phpipam_scan_agent.scanagent_code }}",
|
||||
"scan": {
|
||||
"subnet": "{{ subnet.address }}",
|
||||
"results": "{{ subnet_scan_results }}"
|
||||
"results": "{{ subnet_scan_results }}",
|
||||
"tz": "{{ '%z' | strftime }}"
|
||||
}
|
||||
}
|
||||
validate_certs: true # Ensure always true
|
||||
|
@ -1,5 +1,41 @@
|
||||
---
|
||||
|
||||
- name: Convert Scan Time to Local Time
|
||||
ansible.builtin.set_fact:
|
||||
scan_time: |-
|
||||
{%- if inbound_data.scan.tz != ('%z' | strftime | string) -%}
|
||||
|
||||
{%- set adjust_time = scan_address.ipaddress.lastSeen -%}
|
||||
|
||||
{%- if ('%z' | strftime)[0:1] == '+' -%}
|
||||
|
||||
{{
|
||||
'%Y-%m-%d %H:%M:%S' | strftime(
|
||||
(adjust_time | to_datetime).strftime('%s') | int -
|
||||
(
|
||||
(inbound_data.scan.tz[1:3] | int * 3600) + (inbound_data.scan.tz[3:5] | int * 60)
|
||||
) | int
|
||||
)
|
||||
}}
|
||||
|
||||
{%- else -%}
|
||||
|
||||
{{
|
||||
'%Y-%m-%d %H:%M:%S' | strftime((adjust_time | to_datetime).strftime('%s') | int +
|
||||
(
|
||||
(inbound_data.scan.tz[1:3] | int * 3600) + (inbound_data.scan.tz[3:5] | int * 60)
|
||||
) | int)
|
||||
}}
|
||||
|
||||
{%- endif -%}
|
||||
|
||||
{%- else -%}
|
||||
|
||||
{{ scan_address.ipaddress.lastSeen }}
|
||||
|
||||
{%- endif %}
|
||||
cacheable: false
|
||||
|
||||
|
||||
- name: "Update IP Address' found - {{ scan_address.ipaddress.ip }}"
|
||||
community.mysql.mysql_query:
|
||||
@ -16,7 +52,7 @@
|
||||
|
||||
UPDATE ipaddresses
|
||||
SET
|
||||
lastSeen = '{{ scan_address.ipaddress.lastSeen }}'
|
||||
lastSeen = '{{ scan_time }}'
|
||||
|
||||
{% if scan_address.ipaddress.hostname | default('') != '' %},
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
UPDATE
|
||||
subnets
|
||||
SET
|
||||
lastDiscovery = '{{ inbound_data.scan.results[0].lastSeen }}'
|
||||
lastDiscovery = '{{ ('%Y-%m-%d %H:%M:%S' | strftime) }}'
|
||||
WHERE
|
||||
subnet = '{{ (inbound_data.scan.subnet | split('/'))[0] | ip2ipam }}'
|
||||
single_transaction: true
|
||||
|
@ -23,7 +23,9 @@
|
||||
ansible.builtin.set_fact:
|
||||
nfc_c_scan_agent_subnets: "{{ nfc_c_scan_agent_subnets + [{
|
||||
'id': network.id,
|
||||
'address': network.subnet + '/' + network.mask
|
||||
'address': network.subnet + '/' + network.mask,
|
||||
'nameserverId': network.nameserverId,
|
||||
'resolveDNS': network.resolveDNS
|
||||
}] }}"
|
||||
loop: "{{ lookup('file', cache_filepath) | default ([]) }}"
|
||||
loop_control:
|
||||
|
Reference in New Issue
Block a user