summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/api.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/api.inc.php')
-rw-r--r--modules-available/statistics/api.inc.php30
1 files changed, 23 insertions, 7 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index 52dbe284..a945cdf5 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -1,6 +1,7 @@
<?php
if (Request::any('action') === 'test' && isLocalExecution()) {
+ $uuid = Request::any('uuid', '', 'string');
/*
error_log(HardwareInfo::getKclModifications());
exit;
@@ -14,8 +15,11 @@ if (Request::any('action') === 'test' && isLocalExecution()) {
}
exit;
*/
- HardwareParser::parseMachine('0A5D9E23-80F4-9C43-912C-96D80AE7E80B',
- file_get_contents('/tmp/bla.json'));
+ $data = file_get_contents('/tmp/bla.json');
+ Database::exec(
+ "UPDATE machine SET data = :data WHERE machineuuid = :uuid",
+ ['uuid' => $uuid, 'data' => $data]);
+ HardwareParser::parseMachine($uuid, json_decode($data, true));
echo 'Kweries: ' . Database::getQueryCount();
exit;
}
@@ -82,9 +86,21 @@ if ($type[0] === '~') {
if (!is_string($hostname) || $hostname === $ip) {
$hostname = '';
}
+ $json = false;
$data = Util::cleanUtf8(Request::post('json', '', 'string'));
- $hasJson = !empty($data) && $data[0] === '{';
- if (!$hasJson) {
+ if (!empty($data) && $data[0] === '{') {
+ $json = json_decode($data, true);
+ if (!is_array($json)) {
+ $json = false;
+ } else {
+ $json['cpu'] = [
+ 'sockets' => Request::post('sockets', 0, 'int'),
+ 'cores' => $realcores,
+ 'threads' => Request::post('vcores', 0, 'int'),
+ ];
+ }
+ }
+ if ($json === false) {
$data = Util::cleanUtf8(Request::post('data', '', 'string'));
}
// Prepare insert/update to machine table
@@ -143,7 +159,7 @@ if ($type[0] === '~') {
. ' id44mb = :id44mb,'
. ' live_tmpsize = 0, live_swapsize = 0, live_memsize = 0, live_cpuload = 255, live_cputemp = 0,'
. ' badsectors = :badsectors,'
- . ' data = ' . ($hasJson ? ':data' : "If(Left(data, 1) = '{', data, :data)") . ','
+ . ' data = ' . ($json !== false ? ':data' : "If(Left(data, 1) = '{', data, :data)") . ','
. ' state = :state '
. " WHERE machineuuid = :machineuuid AND state = :oldstate AND lastseen = :oldlastseen", $new);
if ($res === 0) {
@@ -175,8 +191,8 @@ if ($type[0] === '~') {
$new['locationid'] = $loc; // For Filter Event
}
- if ($hasJson) {
- HardwareParser::parseMachine($uuid, $data);
+ if ($json !== false) {
+ HardwareParser::parseMachine($uuid, $json);
}
// Check for suspicious hardware changes