fix(striker-ui-api): use hosts as core of host detail select query to avoid empty return

main
Tsu-ba-me 1 year ago
parent 53f169ad5c
commit 3f9548f33e
  1. 32
      striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts

@ -42,41 +42,41 @@ const setCvar = (
export const buildQueryHostDetail: BuildQueryDetailFunction = ({ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
keys: hostUUIDs = '*', keys: hostUUIDs = '*',
} = {}) => { } = {}) => {
const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'AND b.host_uuid'); const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'AND a.host_uuid');
stdout(`condHostUUIDs=[${condHostUUIDs}]`); stdout(`condHostUUIDs=[${condHostUUIDs}]`);
const query = ` const query = `
SELECT SELECT
b.host_name, a.host_name,
b.host_type, a.host_type,
b.host_uuid, a.host_uuid,
a.variable_name, b.variable_name,
a.variable_value, b.variable_value,
SUBSTRING( SUBSTRING(
a.variable_name, '${CVAR_PREFIX_PATTERN}([^:]+)' b.variable_name, '${CVAR_PREFIX_PATTERN}([^:]+)'
) as cvar_name, ) as cvar_name,
SUBSTRING( SUBSTRING(
a.variable_name, '${CVAR_PREFIX_PATTERN}([a-z]{2,3})\\d+' b.variable_name, '${CVAR_PREFIX_PATTERN}([a-z]{2,3})\\d+'
) AS network_type, ) AS network_type,
SUBSTRING( SUBSTRING(
a.variable_name, '${CVAR_PREFIX_PATTERN}[a-z]{2,3}\\d+_(link\\d+)' b.variable_name, '${CVAR_PREFIX_PATTERN}[a-z]{2,3}\\d+_(link\\d+)'
) AS network_link, ) AS network_link,
c.network_interface_uuid c.network_interface_uuid
FROM variables AS a FROM hosts AS a
JOIN hosts AS b LEFT JOIN variables AS b
ON a.variable_source_uuid = b.host_uuid ON b.variable_source_uuid = a.host_uuid
LEFT JOIN network_interfaces AS c LEFT JOIN network_interfaces AS c
ON a.variable_name LIKE '%link%_mac%' ON b.variable_name LIKE '%link%_mac%'
AND a.variable_value = c.network_interface_mac_address AND b.variable_value = c.network_interface_mac_address
AND b.host_uuid = c.network_interface_host_uuid AND a.host_uuid = c.network_interface_host_uuid
WHERE ( WHERE (
variable_name LIKE '${CVAR_PREFIX}%' variable_name LIKE '${CVAR_PREFIX}%'
OR variable_name = 'install-target::enabled' OR variable_name = 'install-target::enabled'
) )
${condHostUUIDs} ${condHostUUIDs}
ORDER BY cvar_name ASC, ORDER BY cvar_name ASC,
a.variable_name ASC;`; b.variable_name ASC;`;
const afterQueryReturn: QueryResultModifierFunction = const afterQueryReturn: QueryResultModifierFunction =
buildQueryResultModifier((output) => { buildQueryResultModifier((output) => {

Loading…
Cancel
Save