From 54a516de8a49bdcdd2b95ecbfe2a365a860adaf4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 21 Jan 2019 14:49:54 +0100 Subject: [statistics] Log if client seems to have crashed Log when we reset a client's state in the cron job, as well as if we receive a poweron event even though the state in the DB is still IDLE or OCCUPIED. --- modules-available/statistics/api.inc.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules-available/statistics/api.inc.php') diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 8f5e9fd0..674cc48d 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -161,6 +161,11 @@ if ($type{0} === '~') { // Check for suspicious hardware changes if ($old !== false) { checkHardwareChange($old, $new); + + // Log potential crash + if ($old['state'] === 'IDLE' || $old['state'] === 'OCCUPIED') { + writeClientLog('machine-mismatch-poweron', 'Client sent poweron event, but previous known state is ' . $old['state']); + } } // Write statistics data @@ -403,6 +408,18 @@ function writeStatisticLog($type, $username, $data) )); } +function writeClientLog($type, $description) +{ + global $ip, $uuid; + Database::exec('INSERT INTO clientlog (dateline, logtypeid, clientip, machineuuid, description, extra) VALUES (UNIX_TIMESTAMP(), :type, :client, :uuid, :description, :longdesc)', array( + 'type' => $type, + 'client' => $ip, + 'description' => $description, + 'longdesc' => '', + 'uuid' => $uuid, + )); +} + // For backwards compat, we require the . prefix if ($type{0} === '.') { -- cgit v1.2.3-55-g7522