From e2521f405d930326ea677459b2f02a88f769bd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Gr=C3=BCssing?= Date: Fri, 19 Jun 2026 09:35:01 +0200 Subject: [PATCH] Fix: Agent-Rollout downloadete immer globale AGENT_VERSION statt Gruppen-Ziel (v2.5.0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - downloadSetup() nutzte process.env.AGENT_VERSION statt der Patch-Gruppen- Zielversion → Staged Rollout (Test/Pilot/Produktion) hatte nie funktioniert, jeder Agent bekam beim Auto-Update immer dieselbe globale Version - Fix: downloadSetup() löst jetzt per ?hostname=X die Gruppen-Zielversion auf, exakt wie checkin() es bereits tat - ApiService.DownloadSetupAsync() schickt jetzt den Hostnamen mit - Version: 2.4.0 → 2.5.0 Co-Authored-By: Claude Sonnet 4.6 --- agent-cs/AgentWorker.cs | 2 +- agent-cs/IT-Nexus-Agent.csproj | 4 ++-- agent-cs/Services/ApiService.cs | 4 ++-- agent-cs/Services/CommandExecutor.cs | 2 +- agent-cs/setup.iss | 2 +- .../controllers/monitoringAgent.controller.js | 21 ++++++++++++++++++- frontend/src/pages/PatchManagementPage.jsx | 2 +- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/agent-cs/AgentWorker.cs b/agent-cs/AgentWorker.cs index 70845fa..1f44a89 100644 --- a/agent-cs/AgentWorker.cs +++ b/agent-cs/AgentWorker.cs @@ -6,7 +6,7 @@ namespace ITNexusAgent; public class AgentWorker { - private const string Version = "2.4.0"; + private const string Version = "2.5.0"; private const string DataDir = @"C:\ProgramData\IT Nexus Agent"; private const string ConfigPath = @"C:\ProgramData\IT Nexus Agent\config.json"; private const string StatusPath = @"C:\ProgramData\IT Nexus Agent\status.json"; diff --git a/agent-cs/IT-Nexus-Agent.csproj b/agent-cs/IT-Nexus-Agent.csproj index c483d07..8a9fc34 100644 --- a/agent-cs/IT-Nexus-Agent.csproj +++ b/agent-cs/IT-Nexus-Agent.csproj @@ -7,8 +7,8 @@ true IT-Nexus-Agent ITNexusAgent - 2.3.0 - 2.3.0.0 + 2.5.0 + 2.5.0.0 enable enable false diff --git a/agent-cs/Services/ApiService.cs b/agent-cs/Services/ApiService.cs index 1b5e6ac..b43da5d 100644 --- a/agent-cs/Services/ApiService.cs +++ b/agent-cs/Services/ApiService.cs @@ -65,9 +65,9 @@ public class ApiService(string serverUrl, string agentKey) return await resp.Content.ReadAsByteArrayAsync(); } - public async Task DownloadSetupAsync() + public async Task DownloadSetupAsync(string hostname) { - var req = BuildRequest(HttpMethod.Get, "/api/monitoring/agent-setup"); + var req = BuildRequest(HttpMethod.Get, $"/api/monitoring/agent-setup?hostname={Uri.EscapeDataString(hostname)}"); var resp = await _http.SendAsync(req); resp.EnsureSuccessStatusCode(); return await resp.Content.ReadAsByteArrayAsync(); diff --git a/agent-cs/Services/CommandExecutor.cs b/agent-cs/Services/CommandExecutor.cs index 780206d..5683408 100644 --- a/agent-cs/Services/CommandExecutor.cs +++ b/agent-cs/Services/CommandExecutor.cs @@ -125,7 +125,7 @@ public class CommandExecutor(ApiService api, string hostname, string dataDir, st private async Task UpdateAgent() { - var bytes = await _api.DownloadSetupAsync(); + var bytes = await _api.DownloadSetupAsync(_hostname); if (bytes.Length < 512 * 1024) return "Download fehlgeschlagen - Installer zu klein"; var setupPath = Path.Combine(_dataDir, "IT-Nexus-Agent-Setup-Update.exe"); diff --git a/agent-cs/setup.iss b/agent-cs/setup.iss index d85dfbb..46a273d 100644 --- a/agent-cs/setup.iss +++ b/agent-cs/setup.iss @@ -1,5 +1,5 @@ #define MyAppName "IT Nexus Agent" -#define MyAppVersion "2.4.0" +#define MyAppVersion "2.5.0" #define MyAppPublisher "Cereda Systems GmbH" #define MyAppURL "https://it-nexus.cereda-systems.de" #define MyAppExeName "IT-Nexus-Agent.exe" diff --git a/backend/src/controllers/monitoringAgent.controller.js b/backend/src/controllers/monitoringAgent.controller.js index 73206b6..5a4b43d 100644 --- a/backend/src/controllers/monitoringAgent.controller.js +++ b/backend/src/controllers/monitoringAgent.controller.js @@ -212,7 +212,26 @@ const downloadSetup = asyncHandler(async (req, res) => { const path = require('path'); const fs = require('fs'); - const version = process.env.AGENT_VERSION || '2.0.0'; + + // Zielversion: Gruppen-spezifisch (staged rollout) oder globaler Default — gleiche Logik wie checkin() + let version = process.env.AGENT_VERSION || '2.0.0'; + const hostname = req.query.hostname; + if (hostname) { + try { + const db = getDatabase(); + const agent = db.prepare('SELECT id FROM monitoring_agents WHERE hostname = ?').get(hostname); + const groupRow = agent && db.prepare(` + SELECT pg.target_agent_version + FROM patch_agent_groups pag + JOIN patch_groups pg ON pg.id = pag.group_id + WHERE pag.agent_id = ? + ORDER BY pg.sort_order ASC + LIMIT 1 + `).get(agent.id); + if (groupRow?.target_agent_version) version = groupRow.target_agent_version; + } catch { /* kein Gruppe zugewiesen → global */ } + } + const setupPath = path.join(__dirname, `../../agent/IT-Nexus-Agent-Setup-v${version}.exe`); if (!fs.existsSync(setupPath)) { return res.status(404).json({ status: 'error', message: 'Setup nicht gefunden' }); diff --git a/frontend/src/pages/PatchManagementPage.jsx b/frontend/src/pages/PatchManagementPage.jsx index 7ed5310..cc187c5 100644 --- a/frontend/src/pages/PatchManagementPage.jsx +++ b/frontend/src/pages/PatchManagementPage.jsx @@ -5,7 +5,7 @@ import { useAuth } from '../context/AuthContext'; const ANN_TYPES = { maintenance: { icon: '🔧', label: 'Wartung', color: '#f59e0b' }, warning: { icon: '⚠️', label: 'Warnung', color: '#ef4444' }, info: { icon: 'ℹ️', label: 'Info', color: '#6366f1' } }; -const LATEST_AGENT_VERSION = '2.4.0'; +const LATEST_AGENT_VERSION = '2.5.0'; const SEVERITY_LABELS = { critical: 'Kritisch', important: 'Wichtig', moderate: 'Moderat', low: 'Niedrig', all: 'Alle' }; const SEVERITY_COLORS = { critical: '#EF4444', important: '#F59E0B', moderate: '#3B82F6', low: '#6B7280', all: '#0D9488' }; const COMMAND_LABELS = { check_updates: '🔍 Update-Scan', install_updates: '⬇️ Installation', reboot: '🔄 Neustart', upgrade_win11: '🪟 Win 11 Upgrade', update_agent: '⬆️ Agent-Update' };