Files
IT_Tool/build-agent.ps1
Claude Agent 4c40e88718 feat: Phase 8 — Network Discovery + Windows Dev-Setup-Skripte
Network Discovery:
- Go Agent: internal/scanner/scanner.go mit TCP-Sweep (Port 445/80/22/443),
  ARP-Tabellen-Parser (Windows: arp -a, Linux: /proc/net/arp), Reverse-DNS,
  50 gleichzeitige Goroutines mit Semaphore
- Go Agent main.go: COMMAND_TYPE_NETWORK_SCAN Case → scanner.Scan() → JSON stdout
- Backend: NetworkDevice Model (Id, AgentId, IpAddress, MacAddress, Hostname,
  Vendor, IsManaged, FirstSeen, LastSeen)
- Backend: EF Migration AddNetworkDevices + Index auf IpAddress + MacAddress
- Backend: NetworkDevicesController GET /api/v1/network-devices + DELETE /{id}
- Backend: AgentGrpcService.ProcessNetworkScanResultAsync — upsert via MAC,
  IsManaged=true wenn IP einem bekannten Agent entspricht
- Frontend: NetworkPage.tsx mit Scan-Panel, Device-Tabelle, Filter, Delete
- Frontend: App.tsx — 'Netzwerk' Nav-Eintrag mit Network Icon

Windows Dev-Setup:
- dev-start.ps1 — Startet Docker/Postgres, EF-Migrationen, Backend+Frontend
  in separaten PowerShell-Fenstern; Voraussetzungen-Check (docker/dotnet/node/go)
- dev-stop.ps1 — Stoppt alle NexusRMM-Prozesse + PostgreSQL Container
- build-agent.ps1 — Baut nexus-agent.exe (Windows) + optional nexus-agent-linux

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 14:53:35 +01:00

170 lines
5.4 KiB
PowerShell

#Requires -Version 5.1
<#
.SYNOPSIS
Baut den NexusRMM Agent für Windows (und optional Linux/amd64)
.DESCRIPTION
Sucht die Go-Binary, baut den Agent für Windows und optional für Linux.
Erstellt eine Standard-Konfigurationsdatei, wenn noch keine vorhanden ist.
.PARAMETER Linux
Baut zusätzlich eine Linux-Binary (nexus-agent-linux).
.EXAMPLE
.\build-agent.ps1
.\build-agent.ps1 -Linux
#>
param(
[switch]$Linux
)
$ErrorActionPreference = "Stop"
$AgentDir = "D:\001_Projekte\IT_Tool\Agent"
$ConfigFile = "$AgentDir\nexus-agent.yaml"
# ---------------------------------------------------------------------------
# Helper
# ---------------------------------------------------------------------------
function Write-Step { param($msg) Write-Host "`n==> $msg" -ForegroundColor Cyan }
function Write-OK { param($msg) Write-Host " [OK] $msg" -ForegroundColor Green }
function Write-Warn { param($msg) Write-Host " [!] $msg" -ForegroundColor Yellow }
function Write-Fail { param($msg) Write-Host " [FEHLER] $msg" -ForegroundColor Red }
function Format-FileSize {
param([long]$Bytes)
if ($Bytes -ge 1MB) { return "{0:N1} MB" -f ($Bytes / 1MB) }
return "{0:N0} KB" -f ($Bytes / 1KB)
}
# ---------------------------------------------------------------------------
# 1. Go-Binary finden
# ---------------------------------------------------------------------------
Write-Step "Suche Go-Installation..."
# Kandidaten: expliziter Standardpfad zuerst, dann PATH
$goCandidates = @(
"C:\Program Files\Go\bin\go.exe",
"C:\Go\bin\go.exe"
)
$goExe = $null
foreach ($candidate in $goCandidates) {
if (Test-Path $candidate) {
$goExe = $candidate
break
}
}
if ($null -eq $goExe) {
# Fallback: PATH
$fromPath = Get-Command "go" -ErrorAction SilentlyContinue
if ($null -ne $fromPath) {
$goExe = $fromPath.Source
}
}
if ($null -eq $goExe) {
Write-Fail "Go wurde nicht gefunden. Bitte Go installieren (https://go.dev/dl/) oder PATH prüfen."
exit 1
}
$goVersion = & $goExe version
Write-OK "Go gefunden: $goExe"
Write-OK "Version: $goVersion"
# ---------------------------------------------------------------------------
# 2. Ins Agent-Verzeichnis wechseln
# ---------------------------------------------------------------------------
if (-not (Test-Path $AgentDir)) {
Write-Fail "Agent-Verzeichnis nicht gefunden: $AgentDir"
exit 1
}
Push-Location $AgentDir
try {
# -----------------------------------------------------------------------
# 3. Windows-Build
# -----------------------------------------------------------------------
Write-Step "Baue Windows-Binary (nexus-agent.exe)..."
$env:GOOS = "windows"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "0"
$winOut = "$AgentDir\nexus-agent.exe"
& $goExe build -ldflags="-s -w" -o $winOut ./cmd/agent/
if ($LASTEXITCODE -ne 0) {
Write-Fail "Windows-Build fehlgeschlagen."
exit 1
}
$winSize = (Get-Item $winOut).Length
Write-OK "Windows-Binary erstellt:"
Write-OK " Pfad: $winOut"
Write-OK " Groesse: $(Format-FileSize $winSize)"
# -----------------------------------------------------------------------
# 4. Linux-Build (optional)
# -----------------------------------------------------------------------
if ($Linux) {
Write-Step "Baue Linux-Binary (nexus-agent-linux)..."
$env:GOOS = "linux"
$env:GOARCH = "amd64"
$env:CGO_ENABLED = "0"
$linuxOut = "$AgentDir\nexus-agent-linux"
& $goExe build -ldflags="-s -w" -o $linuxOut ./cmd/agent/
if ($LASTEXITCODE -ne 0) {
Write-Fail "Linux-Build fehlgeschlagen."
exit 1
}
$linuxSize = (Get-Item $linuxOut).Length
Write-OK "Linux-Binary erstellt:"
Write-OK " Pfad: $linuxOut"
Write-OK " Groesse: $(Format-FileSize $linuxSize)"
} else {
Write-Warn "Linux-Build übersprungen. Mit -Linux Parameter ausführen um Linux-Binary zu bauen."
}
} finally {
# Umgebungsvariablen zurücksetzen
Remove-Item Env:\GOOS -ErrorAction SilentlyContinue
Remove-Item Env:\GOARCH -ErrorAction SilentlyContinue
Remove-Item Env:\CGO_ENABLED -ErrorAction SilentlyContinue
Pop-Location
}
# ---------------------------------------------------------------------------
# 5. Konfigurationsdatei erstellen (nur wenn nicht vorhanden)
# ---------------------------------------------------------------------------
Write-Step "Prüfe Konfigurationsdatei..."
if (Test-Path $ConfigFile) {
Write-OK "Konfiguration bereits vorhanden: $ConfigFile (wird nicht überschrieben)"
} else {
Write-Warn "Keine Konfigurationsdatei gefunden. Erstelle Standard-Konfiguration..."
$defaultConfig = @"
# NexusRMM Agent Konfiguration
server_address: localhost:5001
heartbeat_interval: 30
tls_enabled: false
mesh_enabled: false
mesh_central_url: ""
"@
Set-Content -Path $ConfigFile -Value $defaultConfig -Encoding UTF8
Write-OK "Konfiguration erstellt: $ConfigFile"
}
# ---------------------------------------------------------------------------
# 6. Zusammenfassung
# ---------------------------------------------------------------------------
Write-Host ""
Write-Host "Build abgeschlossen." -ForegroundColor Green
Write-Host "Agent starten: .\Agent\nexus-agent.exe" -ForegroundColor Yellow
Write-Host "Konfiguration: $ConfigFile" -ForegroundColor Yellow