diff options
author | Simon Rettberg | 2022-05-10 15:49:58 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-05-10 15:49:58 +0200 |
commit | 988ff2ca8229662615c13a9bc4cca0d9263ba5ec (patch) | |
tree | 04ad652acc49558866971ea9076ae49c404a9653 /modules-available/statistics/pages | |
parent | [statistics] Don't try to check MBR partition IDs for non-MBR drives (diff) | |
download | slx-admin-988ff2ca8229662615c13a9bc4cca0d9263ba5ec.tar.gz slx-admin-988ff2ca8229662615c13a9bc4cca0d9263ba5ec.tar.xz slx-admin-988ff2ca8229662615c13a9bc4cca0d9263ba5ec.zip |
[statistics] Show HDD count in list view
Diffstat (limited to 'modules-available/statistics/pages')
-rw-r--r-- | modules-available/statistics/pages/list.inc.php | 46 | ||||
-rw-r--r-- | modules-available/statistics/pages/machine.inc.php | 2 |
2 files changed, 27 insertions, 21 deletions
diff --git a/modules-available/statistics/pages/list.inc.php b/modules-available/statistics/pages/list.inc.php index 4d4da2b6..4eac2ee5 100644 --- a/modules-available/statistics/pages/list.inc.php +++ b/modules-available/statistics/pages/list.inc.php @@ -30,23 +30,32 @@ class SubPage Module::isAvailable('js_stupidtable'); $filterSet->makeFragments($where, $join, $args); $xtra = ''; - if ($filterSet->isNoId44Filter()) { - $xtra .= ', data'; - } if (Module::isAvailable('runmode')) { $xtra .= ', runmode.module AS rmmodule, runmode.isclient'; if (strpos($join, 'runmode') === false) { $join .= ' LEFT JOIN runmode ON (m.machineuuid = runmode.machineuuid) '; } } - $res = Database::simpleQuery("SELECT m.machineuuid, m.locationid, m.macaddr, m.clientip, m.lastseen, + $allRows = Database::queryAll("SELECT m.machineuuid, m.locationid, m.macaddr, m.clientip, m.lastseen, m.logintime, m.state, m.currentuser, m.currentrunmode, m.realcores, m.mbram, m.kvmstate, m.cpumodel, m.id44mb, m.hostname, m.notes IS NOT NULL AS hasnotes, m.badsectors, Count(s.machineuuid) AS confvars $xtra FROM machine m LEFT JOIN setting_machine s ON (m.machineuuid = s.machineuuid) $join WHERE $where GROUP BY m.machineuuid", $args); - $rows = array(); - $singleMachine = 'none'; + // If filter results in just one result, redirect to machine details + if (count($allRows) === 1) { + Util::redirect('?do=statistics&uuid=' . $allRows[0]['machineuuid']); + } + // Gather additional info that would be ugly to fetch via joins above + $uuids = array_column($allRows, 'machineuuid'); + $machineWithHdds = Database::queryKeyValueList("SELECT mxx.machineuuid, Count(s.hwid) AS num + FROM statistic_hw s + INNER JOIN machine_x_hw AS mxx ON (s.hwid = mxx.hwid AND s.hwtype = :type + AND mxx.disconnecttime = 0 AND mxx.machineuuid IN (:ids)) + GROUP BY mxx.machineuuid", + ['type' => HardwareInfo::HDD, 'ids' => $uuids]); + $machineWithConfigOverrides = Database::queryKeyValueList("SELECT machineuuid, Count(machineuuid) AS num + FROM setting_machine WHERE machineuuid IN (:ids) GROUP BY machineuuid", ['ids' => $uuids]); // TODO: Cannot disable checkbox for those where user has no permission, since we got multiple actions now // We should pass these lists to the output and add some JS magic // Either disable the delete/reboot/... buttons as soon as at least one "forbidden" client is selected (potentially annoying) @@ -59,12 +68,8 @@ class SubPage // Only make client clickable if user is allowed to view details page $detailsAllowedLocations = User::getAllowedLocations("machine.view-details"); $location = self::buildLocationLookup(); - foreach ($res as $row) { - if ($singleMachine === 'none') { - $singleMachine = $row['machineuuid']; - } else { - $singleMachine = false; - } + $rows = []; + foreach ($allRows as &$row) { $row['link_details'] = in_array($row['locationid'], $detailsAllowedLocations); //$row['firstseen'] = Util::prettyTime($row['firstseen']); $row['lastseen_int'] = $row['lastseen']; @@ -83,10 +88,14 @@ class SubPage if (empty($row['hostname'])) { $row['hostname'] = $row['clientip']; } - if (isset($row['data'])) { - if (!preg_match('#^Disk.* /dev/[^d].* (bytes$|sectors,)#m', $row['data'])) { - $row['nohdd'] = true; - } + if (isset($machineWithConfigOverrides[$row['machineuuid']])) { + $row['confvars'] = $machineWithConfigOverrides[$row['machineuuid']]; + } + if (isset($machineWithHdds[$row['machineuuid']])) { + $row['hddcount'] = $machineWithHdds[$row['machineuuid']]; + } + if (isset($row['data']) && !$row['data']) { + $row['nohdd'] = true; } $row['cpumodel'] = preg_replace('/\(R\)|\(TM\)|\bintel\b|\bamd\b|\bcpu\b|dual-core|\bdual\s+core\b|\bdual\b|\bprocessor\b/i', ' ', $row['cpumodel']); if (!empty($row['rmmodule'])) { @@ -116,10 +125,7 @@ class SubPage if ($row['locationid'] > 0) { $row['location'] = $location[$row['locationid']]; } - $rows[] = $row; - } - if ($singleMachine !== false && $singleMachine !== 'none') { - Util::redirect('?do=statistics&uuid=' . $singleMachine); + $rows[] =& $row; } $data = array( 'rowCount' => count($rows), diff --git a/modules-available/statistics/pages/machine.inc.php b/modules-available/statistics/pages/machine.inc.php index 798a5a83..9e51d9f9 100644 --- a/modules-available/statistics/pages/machine.inc.php +++ b/modules-available/statistics/pages/machine.inc.php @@ -71,7 +71,7 @@ class SubPage User::assertPermission('machine.view-details', (int)$client['locationid']); // Hack: Get raw collected data if (Request::get('raw', false)) { - Header('Content-Type: text/plain; charset=utf-8'); + Header('Content-Type: application/json'); die($client['data']); } // Parse data |