diff options
author | Simon Rettberg | 2022-09-12 09:58:19 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-09-12 09:58:19 +0200 |
commit | caa63fb08ec97f660487286ec878d991a475dd90 (patch) | |
tree | a8ac11246e5a471aba7307c1fc4a395ea162a1d8 /modules-available/eventlog/hooks/cron.inc.php | |
parent | [eventlog] Add nic speed and duplex to filtering options (diff) | |
download | slx-admin-caa63fb08ec97f660487286ec878d991a475dd90.tar.gz slx-admin-caa63fb08ec97f660487286ec878d991a475dd90.tar.xz slx-admin-caa63fb08ec97f660487286ec878d991a475dd90.zip |
[eventlog] Add machine data to collected notification samples
Diffstat (limited to 'modules-available/eventlog/hooks/cron.inc.php')
-rw-r--r-- | modules-available/eventlog/hooks/cron.inc.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/modules-available/eventlog/hooks/cron.inc.php b/modules-available/eventlog/hooks/cron.inc.php index bf7ced17..72aa4f76 100644 --- a/modules-available/eventlog/hooks/cron.inc.php +++ b/modules-available/eventlog/hooks/cron.inc.php @@ -27,3 +27,41 @@ if (mt_rand(1, 10) === 1) { } } } + +// Add missing/virtual columns to sample data +$todo = Database::simpleQuery("SELECT sampleid, data FROM notification_sample WHERE extended = 0 LIMIT 10"); +foreach ($todo as $sample) { + $data = json_decode($sample['data'], true); + // First, add all the machine columns + if (isset($data['machineuuid'])) { + $row = Database::queryFirst("SELECT " . implode(',', FilterRuleProcessor::MACHINE_COLUMNS) + . " FROM machine WHERE machineuuid = :uuid", ['uuid' => $data['machineuuid']]); + } elseif (isset($data['clientip'])) { + $row = Database::queryFirst("SELECT " . implode(',', FilterRuleProcessor::MACHINE_COLUMNS) + . " FROM machine WHERE clientip = :ip ORDER BY lastseen DESC LIMIT 1", ['ip' => $data['clientip']]); + } else { + $row = false; + } + if ($row !== false) { + $data += $row; + } + // Add virtual statistics columns + if (isset($data['machineuuid']) && Module::isAvailable('statistics')) { + foreach (FilterRuleProcessor::HW_QUERIES as $key => $elem) { + if (isset($data[$key])) + continue; // Already present... + $q = new HardwareQuery($elem[0], $data['machineuuid']); + $q->addColumn($elem[2], $elem[1]); + $res = $q->query(); + if ($res !== false) { + $row = $res->fetch(); + if ($row !== false && $row[$elem[1]] !== null) { + $data[$key] = $row[$elem[1]]; + } + } + } + } + // Finally, update entry + Database::exec("UPDATE notification_sample SET extended = 1, data = :data WHERE sampleid = :id", + ['id' => $sample['sampleid'], 'data' => json_encode($data)]); +}
\ No newline at end of file |