From 7d1c91321ce7ba1df0b57ff573e46a9b96bcca98 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 7 Jul 2020 16:39:42 +0200 Subject: [statistics] Keep track of client runmode --- modules-available/statistics/api.inc.php | 8 ++++++++ modules-available/statistics/install.inc.php | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index af773a61..30e0ebc8 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -98,6 +98,10 @@ if ($type{0} === '~') { $new['hostname'] = $hostname; $moresql .= ' hostname = :hostname,'; } + if (($runmode = Request::post('runmode', false, 'string')) !== false) { + $new['currentrunmode'] = $runmode; + $moresql .= ' currentrunmode = :currentrunmode,'; + } $new['oldstate'] = $old['state']; $new['oldlastseen'] = $old['lastseen']; $res = Database::exec('UPDATE machine SET ' @@ -219,6 +223,10 @@ if ($type{0} === '~') { $strUpdateBoottime .= ' live_' . $item . ' = :_' . $item . ', '; $params['_' . $item] = ceil(Request::post($item, 0, 'int') / 1024); } + if (($runmode = Request::post('runmode', false, 'string')) !== false) { + $params['currentrunmode'] = $runmode; + $strUpdateBoottime .= ' currentrunmode = :currentrunmode, '; + } // Figure out what's happening - state changes if ($used === 0 && $old['state'] !== 'IDLE') { if ($old['state'] === 'OCCUPIED' && $sessionLength === 0) { diff --git a/modules-available/statistics/install.inc.php b/modules-available/statistics/install.inc.php index 2831905d..a1dd3305 100644 --- a/modules-available/statistics/install.inc.php +++ b/modules-available/statistics/install.inc.php @@ -273,5 +273,15 @@ while ($row = $res2->fetch(PDO::FETCH_ASSOC)) { $res[] = tableAddConstraint('setting_machine', 'machineuuid', 'machine', 'machineuuid', 'ON UPDATE CASCADE ON DELETE CASCADE'); +// 2020-06-29: Track current runmode (as reported by client) +if (!tableHasColumn('machine', 'currentrunmode')) { + $ret = Database::exec("ALTER TABLE `machine` + ADD COLUMN `currentrunmode` varchar(30) NOT NULL DEFAULT '' AFTER `hostname`"); + if ($ret === false) { + finalResponse(UPDATE_FAILED, 'Adding live_cpuload column to machine table failed: ' . Database::lastError()); + } + $res[] = UPDATE_DONE; +} + // Create response responseFromArray($res); -- cgit v1.2.3-55-g7522