[RESOLVED] MAC Address Match with Iface

Share your SQL query ideas for reporting in the WAPT Enterprise console here
Forum Rules
Community Forum Rules
* English support on www.reddit.com/r/wapt
* French community support is available on this forum
* Please prefix the topic title with [RESOLVED] if it is resolved.
* Please do not edit a topic that is tagged [RESOLVED]. Open a new topic referencing the old one.
* Specify the installed WAPT version, full version, and build number (2.2.1.11957 / 2.2.2.12337 / etc.) as well as the Enterprise/Discovery edition.
* Versions 1.8.2 and earlier are no longer supported. The only questions accepted regarding version 1.8.2 are related to upgrading to a supported version (2.1, 2.2, etc.).
* Specify the server OS (Linux/Windows) and version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019).
* Specify the OS of the administration/package creation machine and the machine with the problematic agent, if applicable (Windows 7/10/11/Debian 11/etc.).
* Avoid asking multiple questions when opening a topic, otherwise it may be ignored. If there are multiple topics, open separate topics, preferably one after the other and not all at the same time (i.e., do not spam the forum).
* Include code snippets, screenshots, and other images directly in the post. Links to Pastebin, Bitly, and other third-party sites will be systematically removed.
* As with any community forum, support is provided voluntarily by members. If you require commercial support, you can contact Tranquil IT's sales department at 02.40.97.57.55
Locked
gavit
Messages: 25
Registration: Apr 30, 2020 - 4:21 p.m.

June 22, 2022 - 11:37

Good morning,

In an 802.1.X project, I would need to retrieve all the MAC addresses of my computer network.
More specifically, the MAC address of the Ethernet card and the WIFI card.

The problem is that PCs have up to 38 MAC addresses.
I would need to list them all and put them next to their card name (enps, eth, etc...)
But we cannot do:

Code: Select all

 host_info->'networking'->*->'mac' as mac,
How can I proceed?

Given that my code currently looks like this:

Code: Select all

select
distinct
host_info->'networking'->0->'mac' as mac,
host_info->'networking'->0->'iface' as iface,
computer_name
FROM hosts
Sincerely,
VITTAZ Gaëtan
User avatar
htouvet
WAPT Expert
Messages: 436
Registration: March 16, 2015 - 10:48
Contact :

June 22, 2022 - 5:38 PM

Good morning,
To make "advanced" queries on JSON, in the manner of XPath for XML, you need to add the "jsquery" module to PostgreSQL.

On Debian, to install it: (if postgresql 13 is installed)

Code: Select all

apt install postgresql-13-jsquery 
sudo -u postgres psql wapt -c "CREATE EXTENSION jsquery;"
Then the SQL query:

Something like this:

Code: Select all

SELECT
  computer_fqdn,
  t.*
FROM
  hosts,
  jsonb_to_recordset(host_info->'networking') as t
    (mac text, iface text);
                                
Tranquil IT
gavit
Messages: 25
Registration: Apr 30, 2020 - 4:21 p.m.

June 23, 2022 - 1:16 PM

Good morning,

Thank you very much for the quick response, the SQL query works perfectly!
For MAC and Linux computers, there are no problems mounting.
But for Windows PCs, I have the following feedback:
  • [ {6858AE84-3B6D-4D45-8D00-B9AFAA8D578E} (example)/list]

    I tried to adapt the query for the WMI table, therefore for Windows clients

    Code: Select all

    SELECT
      computer_fqdn,
      t.*
    FROM
      hosts,
      jsonb_to_recordset(wmi->'Win32_NetworkAdapter') as t
        (MACAddress text, ProductName text);
        

    This does not retrieve the information; the MACAddress and ProductName fields remain empty.

    Do you have a solution for reinstalling Windows PCs?
    Or a solution that would retrieve the correct data in one request without having to make one request for Windows and another request for Linux/MAC.

    Sincerely,
    VITTAZ Gaëtan
User avatar
sfonteneau
WAPT Expert
Messages: 2318
Registered: July 10, 2014 - 11:52 PM
Contact :

June 29, 2022 - 10:28 PM

Not far! ;)

Code: Select all

SELECT
  computer_fqdn,
  t.*
FROM
  hosts,
  jsonb_to_recordset(wmi->'Win32_NetworkAdapter') as t
    ("MACAddress" text, "ProductName" text);          
So, for example:

Code: Select all

SELECT
  computer_fqdn,
  t.*
FROM
  hosts,
  jsonb_to_recordset(wmi->'Win32_NetworkAdapter') as t("MACAddress" text, "ProductName" text)
  WHERE t."ProductName" !~* 'vpn'
  AND t."ProductName" !~* 'bluetooth'
  AND t."ProductName" !~* 'Virtual Adapter'
  AND t."ProductName" !~* 'WAN Miniport'
  AND t."ProductName" !~* 'TAP-Windows Adapter V9'
  AND t."ProductName" !~* 'VirtualBox Host-Only Ethernet Adapter'
  AND t."ProductName" !~* 'XenServer PV Network Device'
  AND t."ProductName" !~* 'RAS Async Adapter'
  AND (t."MACAddress" <> '') ;
Locked