change system custom reports to use line wrapping arrays with a window function

This commit is contained in:
Oliver Gorwits
2023-12-06 07:20:58 +00:00
parent 8397eabe50
commit a068960b51

View File

@@ -283,8 +283,13 @@ system_reports:
columns: columns:
- { ip: 'Device IP', _searchable: true } - { ip: 'Device IP', _searchable: true }
- { vlans: 'VLAN List' } - { vlans: 'VLAN List' }
bind_params: ['chunk_size']
query: | query: |
SELECT ip, array_to_string(array_agg(DISTINCT vlan::integer ORDER BY vlan::integer ASC), ', ') AS vlans SELECT ip, array_agg(vlans) AS vlans FROM (
SELECT ip, array_to_string(array_agg(vlan), ', ') AS vlans, (x / COALESCE(NULLIF(?,''), '20') ::integer) AS chunk FROM (
SELECT *, (row_number() over (partition by ip)) AS x FROM (
SELECT DISTINCT ip, vlan
FROM device_port_vlan dpv FROM device_port_vlan dpv
WHERE native IS false WHERE native IS false
AND vlan <> 1 AND vlan <> 1
@@ -294,16 +299,23 @@ system_reports:
AND dpv2.vlan = dpv.vlan AND dpv2.vlan = dpv.vlan
AND native IS true AND native IS true
) = 0 ) = 0
GROUP BY ip ORDER BY ip, vlan)
ORDER BY ip
) GROUP BY ip, chunk
) GROUP BY ip ORDER BY ip
- tag: vlansneverconfigured - tag: vlansneverconfigured
category: VLAN category: VLAN
label: 'VLANs Known but Not Configured' label: 'VLANs Known but Not Configured'
columns: columns:
- { ip: 'Device IP', _searchable: true } - { ip: 'Device IP', _searchable: true }
- { vlans: 'VLAN List' } - { vlans: 'VLAN List' }
bind_params: ['chunk_size']
query: | query: |
SELECT ip, array_to_string(array_agg(DISTINCT dv.vlan::integer ORDER BY dv.vlan::integer ASC), ', ') AS vlans SELECT ip, array_agg(vlans) AS vlans FROM (
SELECT ip, array_to_string(array_agg(vlan), ', ') AS vlans, (x / COALESCE(NULLIF(?,''), '20') ::integer) AS chunk FROM (
SELECT *, (row_number() over (partition by ip)) AS x FROM (
SELECT DISTINCT ip, vlan
FROM device_vlan dv FROM device_vlan dv
WHERE NOT EXISTS ( WHERE NOT EXISTS (
SELECT FROM device_port_vlan dpv SELECT FROM device_port_vlan dpv
@@ -311,17 +323,23 @@ system_reports:
AND dpv.vlan = dv.vlan AND dpv.vlan = dv.vlan
) )
AND vlan NOT IN (1002, 1003, 1004, 1005) AND vlan NOT IN (1002, 1003, 1004, 1005)
GROUP BY ip ORDER BY ip, vlan)
ORDER BY ip
) GROUP BY ip, chunk
) GROUP BY ip ORDER BY ip
- tag: vlansunused - tag: vlansunused
category: VLAN category: VLAN
label: 'VLANs No Longer Used' label: 'VLANs No Longer Used'
columns: columns:
- { ip: 'Device IP', _searchable: true } - { ip: 'Device IP', _searchable: true }
- { vlans: 'VLAN List' } - { vlans: 'VLAN List' }
bind_params: ['free'] bind_params: ['chunk_size', 'free']
query: | query: |
SELECT dpv.ip, array_to_string(array_agg(DISTINCT dpv.vlan::integer ORDER BY dpv.vlan::integer ASC), ', ') AS vlans SELECT ip, array_agg(vlans) AS vlans FROM (
SELECT ip, array_to_string(array_agg(vlan), ', ') AS vlans, (x / COALESCE(NULLIF(?,''), '20') ::integer) AS chunk FROM (
SELECT *, (row_number() over (partition by ip)) AS x FROM (
SELECT DISTINCT ip, vlan
FROM device_port_vlan dpv FROM device_port_vlan dpv
WHERE dpv.native IS false WHERE dpv.native IS false
AND dpv.vlan <> 1 AND dpv.vlan <> 1
@@ -339,8 +357,10 @@ system_reports:
< COALESCE(NULLIF(?,''), '3 months') ::interval < COALESCE(NULLIF(?,''), '3 months') ::interval
) )
) = 0 ) = 0
GROUP BY dpv.ip ORDER BY dpv.ip, dpv.vlan)
ORDER BY dpv.ip
) GROUP BY ip, chunk
) GROUP BY ip ORDER BY ip
- tag: devicevlancount - tag: devicevlancount
category: VLAN category: VLAN
label: 'VLAN Count per Device' label: 'VLAN Count per Device'