diff options
| author | Simon Rettberg | 2021-08-24 16:31:13 +0200 |
|---|---|---|
| committer | Simon Rettberg | 2022-03-09 15:06:25 +0100 |
| commit | 291837061ba13647f49cc32092fd0a3ec89d51ed (patch) | |
| tree | a3aa5d197d052189bc10273ef0d8ae5168f06e24 /modules-available/statistics/api.inc.php | |
| parent | [statistics_reporting] Gather some more os infos (diff) | |
| download | slx-admin-291837061ba13647f49cc32092fd0a3ec89d51ed.tar.gz slx-admin-291837061ba13647f49cc32092fd0a3ec89d51ed.tar.xz slx-admin-291837061ba13647f49cc32092fd0a3ec89d51ed.zip | |
[statistics] Support new json-format of hardware info from client
We now try to use JSON output mode from any tool on the client
to supply information, for easier parsability and hopefully, a more
stable format.
Diffstat (limited to 'modules-available/statistics/api.inc.php')
| -rw-r--r-- | modules-available/statistics/api.inc.php | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php index 04614521..0a194f2e 100644 --- a/modules-available/statistics/api.inc.php +++ b/modules-available/statistics/api.inc.php @@ -1,5 +1,21 @@ <?php +if (Request::any('action') === 'test' && isLocalExecution()) { + $x = new HardwareQuery(HardwareInfo::PCI_DEVICE); + //$x->addCompare(false, 'Memory Slot Occupied', '>=', true, 'Memory Slot Count'); + $x->addWhere(true, 'vendor', '=', '8086'); + $x->addColumn(true, 'device'); + $res = $x->query(); + foreach ($res as $row) { + error_log(json_encode($row)); + } + exit; + HardwareParser::parseMachine('0A5D9E23-80F4-9C43-912C-96D80AE7E80B', + file_get_contents('/tmp/bla.json')); + echo 'Kweries: ' . Database::getQueryCount(); + exit; +} + if (empty($_POST['type'])) die('Missing options.'); $type = mb_strtolower($_POST['type']); @@ -62,7 +78,11 @@ if ($type[0] === '~') { if (!is_string($hostname) || $hostname === $ip) { $hostname = ''; } - $data = Util::cleanUtf8(Request::post('data', '', 'string')); + $data = Util::cleanUtf8(Request::post('json', '', 'string')); + $hasJson = !empty($data); + if (!$hasJson) { + $data = Util::cleanUtf8(Request::post('data', '', 'string')); + } // Prepare insert/update to machine table $new = array( 'machineuuid'=> $uuid, @@ -119,7 +139,7 @@ if ($type[0] === '~') { . ' id44mb = :id44mb,' . ' live_tmpsize = 0, live_swapsize = 0, live_memsize = 0, live_cpuload = 255, live_cputemp = 0,' . ' badsectors = :badsectors,' - . ' data = :data,' + . ' data = ' . ($hasJson ? ':data' : "If(Left(data, 1) = '{', data, :data)") . ',' . ' state = :state ' . " WHERE machineuuid = :machineuuid AND state = :oldstate AND lastseen = :oldlastseen", $new); if ($res === 0) { @@ -151,6 +171,10 @@ if ($type[0] === '~') { $new['locationid'] = $loc; // For Filter Event } + if ($hasJson) { + HardwareParser::parseMachine($uuid, $data); + } + // Check for suspicious hardware changes if ($old !== false) { checkHardwareChange($old, $new); @@ -316,6 +340,7 @@ if ($type[0] === '~') { 'hwid' => $hwid, 'machineuuid' => $uuid, 'devpath' => $port, + 'serial' => '', ), array('disconnecttime' => 0)); $validProps = array(); if (count($screen) > 1) { |
