fix logs client

This commit is contained in:
test
2026-08-31 10:10:30 +02:00
parent c88decaf42
commit b3c0fd2c29
14 changed files with 130 additions and 18 deletions
+32 -3
View File
@@ -371,7 +371,7 @@ class AssetTab extends CommonDBTM
$client_name = (string) ($item->fields['name'] ?? '');
$asset_ip = ServerAsset::extractAssetIp($item);
$cache_key = 'urbackup_data_' . $server->fields['id'] . '_' . $client_name;
$cache_key = 'urbackup_data_' . $server->fields['id'] . '_' . $item::class . '_' . $item->fields['id'];
if (isset($_SESSION[$cache_key]) && $_SESSION[$cache_key]['time'] > time() - 30) {
return $_SESSION[$cache_key]['data'];
}
@@ -725,14 +725,18 @@ class AssetTab extends CommonDBTM
foreach ($logs as $log) {
echo "<tr class='tab_bg_1'>";
echo "<td>" . htmlspecialchars(self::formatTimestamp($log['time'] ?? $log['created'] ?? '')) . "</td>";
echo "<td>" . htmlspecialchars((string) ($log['level'] ?? $log['severity'] ?? '')) . "</td>";
echo "<td>" . htmlspecialchars(self::formatLogLevel($log)) . "</td>";
echo "<td>" . htmlspecialchars((string) ($log['message'] ?? $log['msg'] ?? $log['text'] ?? '')) . "</td>";
echo "</tr>";
}
if (count($api_data['logs']) === 0) {
echo "<tr class='tab_bg_1'><td colspan='3'>";
echo htmlspecialchars(__('No client logs available.', 'urbackup'));
if ($api_data['client_found'] !== false) {
echo htmlspecialchars(__('No client logs available.', 'urbackup'));
} else {
echo htmlspecialchars(__('Client not found on UrBackup server. Check that the asset name matches the client name.', 'urbackup'));
}
echo "</td></tr>";
}
@@ -931,6 +935,31 @@ class AssetTab extends CommonDBTM
return $str;
}
/**
* Format the numeric log level returned by the UrBackup "livelog" API
* into a readable label.
*
* @param array<string, mixed> $log Log entry row
*
* @return string
*/
private static function formatLogLevel(array $log): string
{
$raw = (string) ($log['loglevel'] ?? $log['level'] ?? $log['severity'] ?? '');
if ($raw === '') {
return '';
}
return match ((int) $raw) {
1 => 'ERROR',
2 => 'WARNING',
3 => 'INFO',
4 => 'DEBUG',
default => is_numeric($raw) ? $raw : ucfirst(strtolower($raw)),
};
}
public static function startBackup(CommonDBTM $item, string $type): bool
{
$link = ServerAsset::getLinkForAsset($item::class, (int) $item->fields['id'], false);
+12 -6
View File
@@ -1045,7 +1045,10 @@ class Server extends CommonDBTM
global $DB;
$iterator = $DB->request([
'FROM' => 'glpi_plugin_urbackup_serverassets',
'FROM' => 'glpi_plugin_urbackup_serverassets',
'WHERE' => [
'plugin_urbackup_servers_id' => (int) $server->fields['id'],
],
]);
// Batch-load asset names (one query per itemtype) to avoid N+1 lookups.
@@ -1240,7 +1243,10 @@ class Server extends CommonDBTM
$rootLocationId = LocationHelper::getRootLocationId($serverLocationId);
$linkedIterator = $DB->request([
'FROM' => ServerAsset::getTable(),
'FROM' => ServerAsset::getTable(),
'WHERE' => [
'plugin_urbackup_servers_id' => (int) $server->fields['id'],
],
]);
$linkedAssetKeys = [];
foreach ($linkedIterator as $row) {
@@ -1515,8 +1521,8 @@ JAVASCRIPT;
'INNER JOIN' => [
'glpi_networknames AS nn' => [
'ON' => [
'nn' => 'items_id',
'ipa' => 'id',
'nn' => 'id',
'ipa' => 'items_id',
['AND' => ['ipa.itemtype' => 'NetworkName']],
],
],
@@ -1613,8 +1619,8 @@ JAVASCRIPT;
'INNER JOIN' => [
'glpi_networknames AS nn' => [
'ON' => [
'nn' => 'items_id',
'ipa' => 'id',
'nn' => 'id',
'ipa' => 'items_id',
['AND' => ['ipa.itemtype' => 'NetworkName']],
],
],