summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/statisticsfilter.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2022-04-27 16:22:12 +0200
committerSimon Rettberg2022-04-27 16:22:12 +0200
commit6b67d8e49c659d1f5946334933efde09398f5510 (patch)
tree9718770776b8386d682b5fc4f8c3ff47e4bcb5bc /modules-available/statistics/inc/statisticsfilter.inc.php
parent[statistics] Honor pci device revision for passthrough display (diff)
downloadslx-admin-6b67d8e49c659d1f5946334933efde09398f5510.tar.gz
slx-admin-6b67d8e49c659d1f5946334933efde09398f5510.tar.xz
slx-admin-6b67d8e49c659d1f5946334933efde09398f5510.zip
[statistics] Add filters for pciid/hwdb
Diffstat (limited to 'modules-available/statistics/inc/statisticsfilter.inc.php')
-rw-r--r--modules-available/statistics/inc/statisticsfilter.inc.php65
1 files changed, 56 insertions, 9 deletions
diff --git a/modules-available/statistics/inc/statisticsfilter.inc.php b/modules-available/statistics/inc/statisticsfilter.inc.php
index 1c3df9af..59c5e833 100644
--- a/modules-available/statistics/inc/statisticsfilter.inc.php
+++ b/modules-available/statistics/inc/statisticsfilter.inc.php
@@ -62,6 +62,25 @@ abstract class StatisticsFilter
}
/**
+ * Needed for joins with the hardware tables, to use the HardwareQueryColumn afterwards.
+ * The HardwareQuery class should probably be extended/rewritten to be more versatile in
+ * this regard.
+ */
+ public static function addHardwareJoin(array &$args, array &$joins, string $hwtype = null): string
+ {
+ $joins['mxhw'] = ' INNER JOIN machine_x_hw mxhw ON (mxhw.disconnecttime = 0 AND mxhw.machineuuid = m.machineuuid)';
+ $key = self::getNewKey('foo');
+ $shw = self::getNewKey('shw');
+ if ($hwtype === null) {
+ $joins[] = " INNER JOIN statistic_hw $shw ON (mxhw.hwid = {$shw}.hwid)";
+ } else {
+ $joins[] = " INNER JOIN statistic_hw $shw ON (mxhw.hwid = {$shw}.hwid AND {$shw}.hwtype = :$key)";
+ $args[$key] = $hwtype;
+ }
+ return $shw;
+ }
+
+ /**
* To be called by DatabaseFilter::whereClause() when building actual query.
* @param string $operator operator to use
* @param string[]|string $argument argument to compare against
@@ -252,8 +271,10 @@ abstract class StatisticsFilter
'live_swapfree' => new SimpleStatisticsFilter('live_swapfree', self::OP_ORDINAL, 'MiB'),
'live_memfree' => new SimpleStatisticsFilter('live_memfree', self::OP_ORDINAL, 'MiB'),
'live_tmpfree' => new SimpleStatisticsFilter('live_tmpfree', self::OP_ORDINAL, 'MiB'),
+ 'live_id45free' => new SimpleStatisticsFilter('live_id45free', self::OP_ORDINAL, 'MiB'),
'standbycrash' => new StandbyCrashStatisticsFilter(),
'pcidev' => new PciDeviceStatisticsFilter(),
+ 'anydev' => new AnyHardwarePropStatisticsFilter(),
];
if (Module::isAvailable('locations')) {
self::$columns['location'] = new LocationStatisticsFilter();
@@ -637,31 +658,57 @@ class PciDeviceStatisticsFilter extends StatisticsFilter
public function whereClause(string $operator, $argument, array &$args, array &$joins): string
{
- if (!preg_match('/^([0-9a-f]{4})(?::([0-9a-f]{4}))?$/i', $argument, $out)) {
+ // vendor[:device][,class]
+ if (!preg_match('/^(?<v>[0-9a-f]{4})(?::(?<d>[0-9a-f]{4}))?(?:,(?<c>[0-9a-f]{4}))?$/i', $argument, $out)) {
Message::addError('invalid-pciid', $argument);
return '0';
}
- $vendor = $out[1];
- $device = $out[2] ?? '';
+ $vendor = $out['v'];
+ $device = $out['d'] ?? '';
+ $class = $out['c'] ?? '';
// basic join for hw_x_machine
- $joins[] = ' INNER JOIN machine_x_hw mxhw ON (mxhw.disconnecttime = 0 AND mxhw.machineuuid = m.machineuuid)';
- $key = $key = self::getNewKey('foo');
- $joins[] = " INNER JOIN statistic_hw shw ON (mxhw.hwid = shw.hwid AND shw.hwtype = :$key)";
- $args[$key] = HardwareInfo::PCI_DEVICE;
+ $shw = StatisticsFilter::addHardwareJoin($args, $joins, HardwareInfo::PCI_DEVICE);
$_ = [];
$c = new HardwareQueryColumn(true, 'vendor');
$c->addCondition($operator, $vendor);
- $c->generate($joins, $_, $args);
+ $c->generate($joins, $_, $args, [], $shw);
if (!empty($device)) {
$c = new HardwareQueryColumn(true, 'device');
$c->addCondition($operator, $device);
- $c->generate($joins, $_, $args);
+ $c->generate($joins, $_, $args, [], $shw);
+ }
+ if (!empty($class)) {
+ $c = new HardwareQueryColumn(true, 'class');
+ $c->addCondition($operator, $class);
+ $c->generate($joins, $_, $args, [], $shw);
}
return '1';
}
}
+class AnyHardwarePropStatisticsFilter extends StatisticsFilter
+{
+
+ public function __construct()
+ {
+ parent::__construct(null, ['=']);
+ }
+
+ public function whereClause(string $operator, $argument, array &$args, array &$joins): string
+ {
+ $shw = StatisticsFilter::addHardwareJoin($args, $joins);
+ $val = self::getNewKey('val');
+ $key1 = self::getNewKey('hw');
+ $joins[] = "LEFT JOIN statistic_hw_prop $key1 ON (`$key1`.`value` LIKE :$val AND `$key1`.hwid = `$shw`.hwid)";
+ $key2 = self::getNewKey('hw');
+ $joins[] = "LEFT JOIN machine_x_hw_prop $key2 ON (`$key2`.`value` LIKE :$val AND `$key2`.machinehwid = mxhw.machinehwid)";
+ $args[$val] = '%' . str_replace('%', '_', $argument) . '%';
+ return "((`$key1`.`value` IS NOT NULL) OR (`$key2`.`value` IS NOT NULL))";
+ }
+
+}
+
class DatabaseFilter
{
/** @var StatisticsFilter