summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics
diff options
context:
space:
mode:
authorSimon Rettberg2021-12-07 14:56:43 +0100
committerSimon Rettberg2022-03-09 15:06:54 +0100
commit7fb2e4ca050784269e78133cc5a2610e066c660f (patch)
treee614880d2f8189e33da763f70fbc9cf7d09e72cb /modules-available/statistics
parent[eventlog] install: Fix SQL (diff)
downloadslx-admin-7fb2e4ca050784269e78133cc5a2610e066c660f.tar.gz
slx-admin-7fb2e4ca050784269e78133cc5a2610e066c660f.tar.xz
slx-admin-7fb2e4ca050784269e78133cc5a2610e066c660f.zip
[statistics/passthrough] Consider group<->location mapping for KCL
Diffstat (limited to 'modules-available/statistics')
-rw-r--r--modules-available/statistics/inc/hardwareinfo.inc.php10
-rw-r--r--modules-available/statistics/inc/hardwarequery.inc.php27
2 files changed, 34 insertions, 3 deletions
diff --git a/modules-available/statistics/inc/hardwareinfo.inc.php b/modules-available/statistics/inc/hardwareinfo.inc.php
index ed47c153..df33a5f6 100644
--- a/modules-available/statistics/inc/hardwareinfo.inc.php
+++ b/modules-available/statistics/inc/hardwareinfo.inc.php
@@ -29,7 +29,7 @@ class HardwareInfo
$mac = Request::get('mac', '', 'string');
$mac = str_replace(':', '-', $mac);
}
- $res = Database::simpleQuery("SELECT machineuuid, lastseen, cpumodel FROM machine
+ $res = Database::simpleQuery("SELECT machineuuid, lastseen, cpumodel, locationid FROM machine
WHERE machineuuid = :uuid OR macaddr = :mac", ['uuid' => $uuid, 'mac' => $mac]);
$best = null;
foreach ($res as $row) {
@@ -37,11 +37,15 @@ class HardwareInfo
$best = $row;
}
}
- if ($best === null)
+ if ($best === null || ((int)$best['locationid']) === 0)
+ return '';
+ $locations = Location::getLocationRootChain($best['locationid']);
+ if (empty($locations))
return '';
$hw = new HardwareQuery(self::PCI_DEVICE, $best['machineuuid'], true);
// TODO: Get list of enabled pass through groups for this client's location
- $hw->addWhere(true, '@PASSTHROUGH', 'IN', ['GPU', 'GVT']);
+ $hw->addJoin(true, '@PASSTHROUGH', 'passthrough_group_x_location', 'groupid',
+ 'locationid', $locations);
$hw->addGlobalColumn('vendor');
$hw->addGlobalColumn('device');
$hw->addLocalColumn('slot');
diff --git a/modules-available/statistics/inc/hardwarequery.inc.php b/modules-available/statistics/inc/hardwarequery.inc.php
index 6b5662d4..24b27190 100644
--- a/modules-available/statistics/inc/hardwarequery.inc.php
+++ b/modules-available/statistics/inc/hardwarequery.inc.php
@@ -68,6 +68,33 @@ class HardwareQuery
$this->columns[$prop] = "$tid.`value` AS `$prop`";
}
+ public function addJoin(bool $global, string $prop, string $jTable, string $jColumn, string $condColumn = '', $condVal = null)
+ {
+ if (isset($this->columns[$jTable]))
+ return;
+ if (!isset($this->columns[$prop])) {
+ $this->fillTableVars($global, $srcTable, $table, $column);
+ $tid = $this->id();
+ $pid = $this->id();
+ $this->joins[$prop] = "INNER JOIN $table $tid ON ($srcTable.$column = $tid.$column
+ AND $tid.prop = :$pid)";
+ $this->args[$pid] = $prop;
+ $this->columns[$prop] = "$tid.`value` AS `$prop`";
+ }
+ $jtid = $this->id();
+ $cond = '';
+ if (!empty($condColumn)) {
+ $vid = $this->id();
+ if (is_array($condVal)) {
+ $cond = " AND $jtid.`$condColumn` IN (:$vid)";
+ } else {
+ $cond = " AND $jtid.`$condColumn` = :$vid";
+ }
+ $this->args[$vid] = $condVal;
+ }
+ $this->joins[$jTable] = "INNER JOIN $jTable $jtid ON ($jtid.$jColumn = $tid.`value` $cond)";
+ }
+
public function addMachineWhere(string $column, string $op, $value)
{
if (isset($this->columns[$column]))