From d4b533ffeeed3ce0a4310c3079993e88a42193c7 Mon Sep 17 00:00:00 2001 From: Steffen Ritter Date: Fri, 5 Nov 2021 12:41:39 +0100 Subject: [statistics_reporting] Always send a minimal report Even if reporting is disabled send an absolute minimal report which includes at least the satellite version but nothing more. This is just for tracking how many servers are in use. --- .../statistics_reporting/hooks/cron.inc.php | 30 ++++++------- .../statistics_reporting/inc/remotereport.inc.php | 52 +++++++++++----------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/modules-available/statistics_reporting/hooks/cron.inc.php b/modules-available/statistics_reporting/hooks/cron.inc.php index 14597f7d..7336b7d1 100644 --- a/modules-available/statistics_reporting/hooks/cron.inc.php +++ b/modules-available/statistics_reporting/hooks/cron.inc.php @@ -1,25 +1,23 @@ "statistics", "data" => $statisticsReport); + $params = array("action" => "statistics", "data" => $statisticsReport); - $result = Download::asStringPost(CONFIG_REPORTING_URL, $params, 30, $code); + $result = Download::asStringPost(CONFIG_REPORTING_URL, $params, 30, $code); - if ($code != 200) { - EventLog::warning("Statistics Reporting failed: " . $code, $result); - } else { - EventLog::info('Statistics report sent to ' . CONFIG_REPORTING_URL); - } - $nextReporting = strtotime("+7 days", $nextReporting); + if ($code != 200) { + EventLog::warning("Statistics Reporting failed: " . $code, $result); + } else { + EventLog::info('Statistics report sent to ' . CONFIG_REPORTING_URL); } -} \ No newline at end of file + $nextReporting = strtotime("+7 days", $nextReporting); +} diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php index 376691dd..98f366b6 100644 --- a/modules-available/statistics_reporting/inc/remotereport.inc.php +++ b/modules-available/statistics_reporting/inc/remotereport.inc.php @@ -69,32 +69,34 @@ class RemoteReport * @return array wrapped up statistics, ready for reporting */ public static function generateReport(int $to, $days = false) { - if ($days === false) { - $days = [7, 30, 90]; - } - GetData::$salt = bin2hex(Util::randomBytes(20, false)); - GetData::$lowerTimeBound = 7; - GetData::$upperTimeBound = 20; $result = array(); - foreach ($days as $day) { - if (isset($result['days' . $day])) - continue; - $from = strtotime("-{$day} days", $to); - GetData::$from = $from; - GetData::$to = $to; - $data = array('total' => GetData::total(GETDATA_ANONYMOUS)); - $data['perLocation'] = array_values(GetData::perLocation(GETDATA_ANONYMOUS)); - $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); - $data['tsFrom'] = $from; - $data['tsTo'] = $to; - $data['dozmod'] = Queries::getDozmodStats($from, $to); - $data['machines'] = Queries::getAggregatedMachineStats($from); - $data['exams'] = Queries::getExamStats($from, $to); - $data['baseSystem'] = Queries::getBaseSystemStats($from, $to); - $data['runmode'] = Queries::getRunmodeStats($from, $to); - $result['days' . $day] = $data; + if (RemoteReport::isReportingEnabled()) { + if ($days === false) { + $days = [7, 30, 90]; + } + GetData::$salt = bin2hex(Util::randomBytes(20, false)); + GetData::$lowerTimeBound = 7; + GetData::$upperTimeBound = 20; + foreach ($days as $day) { + if (isset($result['days' . $day])) + continue; + $from = strtotime("-{$day} days", $to); + GetData::$from = $from; + GetData::$to = $to; + $data = array('total' => GetData::total(GETDATA_ANONYMOUS)); + $data['perLocation'] = array_values(GetData::perLocation(GETDATA_ANONYMOUS)); + $data['perVM'] = GetData::perVM(GETDATA_ANONYMOUS); + $data['tsFrom'] = $from; + $data['tsTo'] = $to; + $data['dozmod'] = Queries::getDozmodStats($from, $to); + $data['machines'] = Queries::getAggregatedMachineStats($from); + $data['exams'] = Queries::getExamStats($from, $to); + $data['baseSystem'] = Queries::getBaseSystemStats($from, $to); + $data['runmode'] = Queries::getRunmodeStats($from, $to); + $result['days' . $day] = $data; + } + $result['server'] = self::getLocalHardware(); } - $result['server'] = self::getLocalHardware(); $result['version'] = CONFIG_FOOTER; return $result; } @@ -127,4 +129,4 @@ class RemoteReport return $data; } -} \ No newline at end of file +} -- cgit v1.2.3-55-g7522