|
| 1 | +-- |
| 2 | +-- Copyright (c) 2022--2025 SUSE LLC |
| 3 | +-- |
| 4 | +-- This software is licensed to you under the GNU General Public License, |
| 5 | +-- version 2 (GPLv2). There is NO WARRANTY for this software, express or |
| 6 | +-- implied, including the implied warranties of MERCHANTABILITY or FITNESS |
| 7 | +-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 |
| 8 | +-- along with this software; if not, see |
| 9 | +-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 10 | +-- |
| 11 | + |
| 12 | +DROP VIEW IF EXISTS InventoryReport; |
| 13 | + |
| 14 | +CREATE OR REPLACE VIEW InventoryReport AS |
| 15 | + -- CTEs to group all one to many relationship joining values with ; as separator |
| 16 | + WITH Entitlements AS ( |
| 17 | + SELECT mgm_id, system_id, string_agg(system_group_id || ' - ' || name, ';') AS entitlements |
| 18 | + FROM systementitlement |
| 19 | + GROUP BY mgm_id, system_id |
| 20 | + ), Groups AS ( |
| 21 | + SELECT mgm_id, system_id, string_agg(system_group_id || ' - ' || group_name, ';') AS system_groups |
| 22 | + FROM SystemGroupMember |
| 23 | + GROUP BY mgm_id, system_id |
| 24 | + ), ConfigChannels AS ( |
| 25 | + SELECT mgm_id, system_id, string_agg(config_channel_id || ' - ' || name, ';') AS configuration_channels |
| 26 | + FROM SystemConfigChannel |
| 27 | + GROUP BY mgm_id, system_id |
| 28 | + ), Channels AS ( |
| 29 | + SELECT mgm_id, system_id, string_agg(channel_id || ' - ' || name, ';') AS software_channels |
| 30 | + FROM SystemChannel |
| 31 | + GROUP BY mgm_id, system_id |
| 32 | + ), V6Addresses AS ( |
| 33 | + SELECT mgm_id, system_id, interface_id, string_agg(address || ' (' || scope || ')', ';') AS ip6_addresses |
| 34 | + FROM SystemNetAddressV6 |
| 35 | + GROUP BY mgm_id, system_id, interface_id |
| 36 | + ) |
| 37 | + SELECT System.mgm_id |
| 38 | + , System.system_id |
| 39 | + , System.profile_name |
| 40 | + , System.hostname |
| 41 | + , System.minion_id |
| 42 | + , System.machine_id |
| 43 | + , System.registered_by |
| 44 | + , System.registration_time |
| 45 | + , System.last_checkin_time |
| 46 | + , System.last_boot_time |
| 47 | + , System.kernel_version |
| 48 | + , System.organization |
| 49 | + , System.architecture |
| 50 | + , System.hardware |
| 51 | + , SystemNetInterface.name AS primary_interface |
| 52 | + , SystemNetInterface.hardware_address AS hardware_address |
| 53 | + , SystemNetAddressV4.address AS ip_address |
| 54 | + , V6Addresses.ip6_addresses |
| 55 | + , ConfigChannels.configuration_channels |
| 56 | + , Entitlements.entitlements |
| 57 | + , Groups.system_groups |
| 58 | + , SystemVirtualdata.host_system_id AS virtual_host |
| 59 | + , SystemVirtualdata.virtual_system_id IS NULL AS is_virtualized |
| 60 | + , SystemVirtualdata.instance_type_name AS virt_type |
| 61 | + , Channels.software_channels |
| 62 | + , COALESCE(SystemOutdated.packages_out_of_date, (0)::bigint) AS packages_out_of_date |
| 63 | + , COALESCE(SystemOutdated.errata_out_of_date, (0)::bigint) AS errata_out_of_date |
| 64 | + , COALESCE(SystemOutdated.extra_pkg_count, (0)::bigint) AS extra_pkg_count |
| 65 | + , SystemOutdated.status AS status |
| 66 | + , System.synced_date |
| 67 | + FROM System |
| 68 | + LEFT JOIN SystemVirtualdata ON ( System.mgm_id = SystemVirtualdata.mgm_id AND System.system_id = SystemVirtualdata.virtual_system_id ) |
| 69 | + LEFT JOIN SystemOutdated ON ( System.mgm_id = SystemOutdated.mgm_id AND System.system_id = SystemOutdated.system_id ) |
| 70 | + LEFT JOIN SystemNetInterface ON (System.mgm_id = SystemNetInterface.mgm_id AND System.system_id = SystemNetInterface.system_id AND SystemNetInterface.primary_interface) |
| 71 | + LEFT JOIN SystemNetAddressV4 ON (System.mgm_id = SystemNetAddressV4.mgm_id AND System.system_id = SystemNetAddressV4.system_id AND SystemNetInterface.interface_id = SystemNetAddressV4.interface_id) |
| 72 | + LEFT JOIN V6Addresses ON (System.mgm_id = V6Addresses.mgm_id AND System.system_id = V6Addresses.system_id AND SystemNetInterface.interface_id = V6Addresses.interface_id) |
| 73 | + LEFT JOIN Entitlements ON ( System.mgm_id = entitlements.mgm_id AND System.system_id = entitlements.system_id ) |
| 74 | + LEFT JOIN Groups ON ( System.mgm_id = Groups.mgm_id AND System.system_id = Groups.system_id ) |
| 75 | + LEFT JOIN ConfigChannels ON ( System.mgm_id = ConfigChannels.mgm_id AND System.system_id = ConfigChannels.system_id ) |
| 76 | + LEFT JOIN Channels ON ( System.mgm_id = Channels.mgm_id AND System.system_id = Channels.system_id ) |
| 77 | + ORDER BY System.mgm_id, System.system_id |
| 78 | +; |
0 commit comments