From 5c23e7d7e1c9ade9755c530c9320ad7e5b463413 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 1 Dec 2017 12:30:23 +0100 Subject: [statistics, roomplanner, locationinfo] Ignore machines with runmode:isclient==0 --- modules-available/locationinfo/inc/infopanel.inc.php | 10 +++++++++- modules-available/roomplanner/inc/pvsgenerator.inc.php | 13 +++++++++++-- modules-available/statistics/api.inc.php | 1 - modules-available/statistics/hooks/cron.inc.php | 11 ++++++++--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php index dacf860f..aa4741ee 100644 --- a/modules-available/locationinfo/inc/infopanel.inc.php +++ b/modules-available/locationinfo/inc/infopanel.inc.php @@ -83,6 +83,12 @@ class InfoPanel $idList = array_keys($array); } + $ignoreList = array(); + if (Module::isAvailable('runmode')) { + // Ignore clients with special runmode not marked as still being a client + $ignoreList = RunMode::getAllClients(false, true); + } + $positionCol = $withPosition ? 'm.position,' : ''; $query = "SELECT m.locationid, m.machineuuid, $positionCol m.logintime, m.lastseen, m.lastboot, m.state FROM machine m WHERE m.locationid IN (:idlist)"; @@ -90,6 +96,8 @@ class InfoPanel // Iterate over matching machines while ($row = $dbquery->fetch(PDO::FETCH_ASSOC)) { + if (isset($ignoreList[$row['machineuuid']])) + continue; settype($row['locationid'], 'int'); if (!isset($array[$row['locationid']])) { $array[$row['locationid']] = array('id' => $row['locationid'], 'machines' => array()); @@ -219,4 +227,4 @@ class InfoPanel return $result; } -} \ No newline at end of file +} diff --git a/modules-available/roomplanner/inc/pvsgenerator.inc.php b/modules-available/roomplanner/inc/pvsgenerator.inc.php index 6dc9b648..6df7c10e 100644 --- a/modules-available/roomplanner/inc/pvsgenerator.inc.php +++ b/modules-available/roomplanner/inc/pvsgenerator.inc.php @@ -54,9 +54,18 @@ class PvsGenerator /* collect names and build room blocks - filter empty rooms while at it */ $roomNames = array(); $roomBlocks = ''; + $overrides = []; foreach ($rooms as $room) { - if (is_null($room['notnull']) || isset($room['skip']) // Not leaf - || empty($room['managerip'])) // rooms without managerips don't make sense + if (is_null($room['notnull']) || isset($room['skip'])) // Not leaf + continue; + if (Module::isAvailable('runmode')) { + $pc = RunMode::getForMode('roomplanner', $room['locationid']); + if (!empty($pc)) { + $pc = array_pop($pc); + $room['managerip'] = $pc['clientip']; + } + } + if (empty($room['managerip'])) // rooms without managerips don't make sense continue; $roomBlock = PvsGenerator::generateRoomBlock($room); if ($roomBlock === false) diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 7b5678de..a614658a 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -79,7 +79,6 @@ if ($type{0} === '~') { 'id44mb' => $id44mb, 'badsectors' => $badsectors, 'data' => $data, - 'hostname' => $hostname, 'state' => 'IDLE', ); // Create/update machine entry diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php index eb88173d..4df7b0d4 100644 --- a/modules-available/statistics/hooks/cron.inc.php +++ b/modules-available/statistics/hooks/cron.inc.php @@ -4,9 +4,14 @@ function logstats() { $NOW = time(); $cutoff = $NOW - 86400 * 30; - $known = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $cutoff"); - $on = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE state IN ('IDLE', 'OCCUPIED')"); - $used = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE state = 'OCCUPIED'"); + $join = $where = ''; + if (Module::get('runmode') !== false) { + $join = 'LEFT JOIN runmode r USING (machineuuid)'; + $where = 'AND (r.isclient IS NULL OR r.isclient <> 0)'; + } + $known = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE m.lastseen > $cutoff $where"); + $on = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE m.state IN ('IDLE', 'OCCUPIED') $where"); + $used = Database::queryFirst("SELECT Count(*) AS val FROM machine m $join WHERE m.state = 'OCCUPIED' $where"); Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array( 'now' => $NOW, 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'], -- cgit v1.2.3-55-g7522