diff options
Diffstat (limited to 'modules-available/eventlog/inc/filterruleprocessor.inc.php')
-rw-r--r-- | modules-available/eventlog/inc/filterruleprocessor.inc.php | 65 |
1 files changed, 51 insertions, 14 deletions
diff --git a/modules-available/eventlog/inc/filterruleprocessor.inc.php b/modules-available/eventlog/inc/filterruleprocessor.inc.php index c49c0d01..22df1d11 100644 --- a/modules-available/eventlog/inc/filterruleprocessor.inc.php +++ b/modules-available/eventlog/inc/filterruleprocessor.inc.php @@ -9,6 +9,25 @@ class FilterRuleProcessor 'live_swapfree', 'live_id45free', 'live_cpuload', 'live_cputemp', 'badsectors', 'hostname', 'currentrunmode', 'currentsession', 'currentuser', 'notes', 'standbysem']; + const HW_QUERIES = [ + 'ram_max' => [HardwareInfo::MAINBOARD, 'Memory Maximum Capacity'], + 'ram_slots' => [HardwareInfo::MAINBOARD, 'Memory Slot Count'], + 'ram_manufacturer' => [HardwareInfo::RAM_MODULE, 'Manufacturer'], + 'ram_part_no' => [HardwareInfo::RAM_MODULE, 'Part Number'], + 'ram_speed' => [HardwareInfo::RAM_MODULE, 'Speed'], + 'ram_size' => [HardwareInfo::RAM_MODULE, 'Size'], + 'ram_type' => [HardwareInfo::RAM_MODULE, 'Type'], + 'pci_class' => [HardwareInfo::PCI_DEVICE, 'class'], + 'pci_vendor' => [HardwareInfo::PCI_DEVICE, 'vendor'], + 'pci_device' => [HardwareInfo::PCI_DEVICE, 'device'], + 'hdd_ifspeed' => [HardwareInfo::HDD, 'interface_speed//max'], + 'hdd_blocksize' => [HardwareInfo::HDD, 'physical_block_size'], + 'hdd_rpm' => [HardwareInfo::HDD, 'rotation_rate'], + 'hdd_size' => [HardwareInfo::HDD, 'size'], + 'hdd_sata_version' => [HardwareInfo::HDD, 'sata_version'], + 'hdd_model' => [HardwareInfo::HDD, 'model'], + ]; + /* * filter: * [ @@ -76,6 +95,8 @@ class FilterRuleProcessor } // Iterate over matches in $data - can be multiple if path contains '*' foreach ($items as $item) { + if (is_array($item)) + continue; $match = self::matches($item, $filter); if ($match === null) continue; @@ -150,26 +171,42 @@ class FilterRuleProcessor return $return; } if (!array_key_exists($pathElement, $data) - && (isset($data['clientip']) || isset($data['machineuuid'])) && in_array($pathElement, self::MACHINE_COLUMNS)) { - if ($pathElement !== 'machineuuid' && isset($data['machineuuid'])) { - $row = Database::queryFirst("SELECT " . implode(',', self::MACHINE_COLUMNS) - . " FROM machine WHERE machineuuid = :uuid", ['uuid' => $data['machineuuid']]); - } elseif ($pathElement !== 'clientip' && isset($data['clientip'])) { - $row = Database::queryFirst("SELECT " . implode(',', self::MACHINE_COLUMNS) - . " FROM machine WHERE clientip = :ip ORDER BY lastseen DESC LIMIT 1", ['ip' => $data['clientip']]); - } else { - $row = false; - } - if ($row !== false) { - error_log('Additional client data fetched on the fly'); - $data += $row; + && (isset($data['clientip']) || isset($data['machineuuid']))) { + // An unknown key was requested, but we have clientip or machineuuid.... + if (in_array($pathElement, self::MACHINE_COLUMNS)) { + // Key matches a column from machine table, try to fetch it + if ($pathElement !== 'machineuuid' && isset($data['machineuuid'])) { + $row = Database::queryFirst("SELECT " . implode(',', self::MACHINE_COLUMNS) + . " FROM machine WHERE machineuuid = :uuid", ['uuid' => $data['machineuuid']]); + } elseif ($pathElement !== 'clientip' && isset($data['clientip'])) { + $row = Database::queryFirst("SELECT " . implode(',', self::MACHINE_COLUMNS) + . " FROM machine WHERE clientip = :ip ORDER BY lastseen DESC LIMIT 1", ['ip' => $data['clientip']]); + } else { + $row = false; + } + if ($row !== false) { + error_log('Additional client data fetched on the fly'); + $data += $row; + } + } elseif (isset($data['machineuuid']) + && isset(self::HW_QUERIES[$pathElement]) && Module::isAvailable('statistics')) { + // Key matches a predefined hwinfo property, resolve.... + $q = new HardwareQuery(self::HW_QUERIES[$pathElement][0], $data['machineuuid']); + $q->addGlobalColumn(self::HW_QUERIES[$pathElement][1]); + $res = $q->query(); + if ($res !== false) { + $row = $res->fetch(); + if ($row !== false) { + $data[$pathElement] = $row[self::HW_QUERIES[$pathElement][1]]; + } + } } } if (!array_key_exists($pathElement, $data)) return []; if (empty($path) && !is_array($data[$pathElement])) return [$data[$pathElement]]; - if (!empty($path) && is_array($data[$pathElement])) + if (is_array($data[$pathElement])) return self::get($path, $data[$pathElement]); return []; // No match } |