Beschreibung der Änderung
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
#Requires -RunAsAdministrator
|
#Requires -RunAsAdministrator
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Zabbix Agent 2 – Windows Installer / Updater (Version 7.4)
|
# Zabbix Agent 2 - Windows Installer / Updater
|
||||||
#
|
#
|
||||||
# Aufruf:
|
# Aufruf:
|
||||||
# PowerShell -ExecutionPolicy Bypass -File install-update-zabbix-agent.ps1
|
# PowerShell -ExecutionPolicy Bypass -File install-update-zabbix-agent.ps1
|
||||||
@ -8,26 +8,35 @@
|
|||||||
# Interaktiv: Proxy-Auswahl, Hostname-Eingabe, automatische Install/Update-Erkennung
|
# Interaktiv: Proxy-Auswahl, Hostname-Eingabe, automatische Install/Update-Erkennung
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
||||||
# ── Konfiguration (manuell anpassen) ─────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Konfiguration (manuell anpassen)
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
<<<<<<< Updated upstream
|
||||||
$ZabbixServer = "zabbix.server-nb.de" # Zabbix-Server-Adresse
|
$ZabbixServer = "zabbix.server-nb.de" # Zabbix-Server-Adresse
|
||||||
$ZabbixVersion = "7.4.7" # Zabbix-Version (bei neuen Releases anpassen)
|
$ZabbixVersion = "7.4.7" # Zabbix-Version (bei neuen Releases anpassen)
|
||||||
|
=======
|
||||||
|
$ScriptVersion = "1.2" # Skript-Version
|
||||||
|
>>>>>>> Stashed changes
|
||||||
|
|
||||||
# Proxy-Liste – hier manuell pflegen (Name und URL)
|
$ZabbixServer = "zabbix.server-nb.de" # Zabbix-Server-Adresse
|
||||||
|
$ZabbixVersion = "7.4.7" # Zabbix Agent-Version (bei neuen Releases anpassen)
|
||||||
|
|
||||||
|
# Proxy-Liste - hier manuell pflegen (Name und URL)
|
||||||
$ProxyList = @(
|
$ProxyList = @(
|
||||||
@{ Name = "Standort Büro A"; Url = "http://proxy01.example.com:3128" }
|
@{ Name = "Standort Buero A"; Url = "http://proxy01.example.com:3128" }
|
||||||
@{ Name = "Standort Büro B"; Url = "http://proxy02.example.com:3128" }
|
@{ Name = "Standort Buero B"; Url = "http://proxy02.example.com:3128" }
|
||||||
# weitere Proxys einfach hier eintragen:
|
# weitere Proxys einfach hier eintragen:
|
||||||
# @{ Name = "Rechenzentrum"; Url = "http://proxy03.example.com:3128" }
|
# @{ Name = "Rechenzentrum"; Url = "http://proxy03.example.com:3128" }
|
||||||
)
|
)
|
||||||
|
|
||||||
# Installationspfade (normalerweise nicht ändern nötig)
|
# Installationspfade (normalerweise nicht aendern noetig)
|
||||||
$InstallDir = "C:\Program Files\Zabbix Agent 2"
|
|
||||||
$ConfigFile = "$InstallDir\zabbix_agent2.conf"
|
|
||||||
$ServiceName = "Zabbix Agent 2"
|
$ServiceName = "Zabbix Agent 2"
|
||||||
$TempDir = $env:TEMP
|
$TempDir = $env:TEMP
|
||||||
|
|
||||||
# ── Hilfsfunktionen ───────────────────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Hilfsfunktionen
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function Write-Info { param($msg) Write-Host "[INFO] $msg" -ForegroundColor Green }
|
function Write-Info { param($msg) Write-Host "[INFO] $msg" -ForegroundColor Green }
|
||||||
function Write-Warn { param($msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
function Write-Warn { param($msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
|
||||||
@ -36,12 +45,15 @@ function Write-Err { param($msg) Write-Host "[ERROR] $msg" -ForegroundColor Re
|
|||||||
function Show-Header {
|
function Show-Header {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "=============================================" -ForegroundColor Cyan
|
Write-Host "=============================================" -ForegroundColor Cyan
|
||||||
Write-Host " Zabbix Agent 2 $ZabbixVersion – Windows Setup" -ForegroundColor Cyan
|
Write-Host " Zabbix Agent 2 $ZabbixVersion - Windows Setup" -ForegroundColor Cyan
|
||||||
|
Write-Host " Skript-Version: $ScriptVersion" -ForegroundColor Cyan
|
||||||
Write-Host "=============================================" -ForegroundColor Cyan
|
Write-Host "=============================================" -ForegroundColor Cyan
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Installierte Version prüfen ───────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Installierte Version pruefen
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function Get-InstalledVersion {
|
function Get-InstalledVersion {
|
||||||
$reg = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" `
|
$reg = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" `
|
||||||
@ -52,13 +64,15 @@ function Get-InstalledVersion {
|
|||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Proxy-Auswahl ─────────────────────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Proxy-Auswahl
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function Select-Proxy {
|
function Select-Proxy {
|
||||||
Write-Host "Proxy-Einstellungen:" -ForegroundColor Cyan
|
Write-Host "Proxy-Einstellungen:" -ForegroundColor Cyan
|
||||||
Write-Host " [0] Kein Proxy (direkte Verbindung)"
|
Write-Host " [0] Kein Proxy (direkte Verbindung)"
|
||||||
for ($i = 0; $i -lt $ProxyList.Count; $i++) {
|
for ($i = 0; $i -lt $ProxyList.Count; $i++) {
|
||||||
Write-Host " [$($i+1)] $($ProxyList[$i].Name) – $($ProxyList[$i].Url)"
|
Write-Host " [$($i+1)] $($ProxyList[$i].Name) - $($ProxyList[$i].Url)"
|
||||||
}
|
}
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
@ -68,12 +82,15 @@ function Select-Proxy {
|
|||||||
|
|
||||||
if ($choice -eq "0") {
|
if ($choice -eq "0") {
|
||||||
return $null
|
return $null
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
return $ProxyList[[int]$choice - 1].Url
|
return $ProxyList[[int]$choice - 1].Url
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Download ──────────────────────────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Download
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function Get-ZabbixMsi {
|
function Get-ZabbixMsi {
|
||||||
param(
|
param(
|
||||||
@ -93,22 +110,29 @@ function Get-ZabbixMsi {
|
|||||||
$proxy = New-Object System.Net.WebProxy($ProxyUrl, $true)
|
$proxy = New-Object System.Net.WebProxy($ProxyUrl, $true)
|
||||||
$proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
|
$proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
|
||||||
$webClient.Proxy = $proxy
|
$webClient.Proxy = $proxy
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$webClient.Proxy = $null
|
$webClient.Proxy = $null
|
||||||
Write-Info "Direktverbindung (kein Proxy)"
|
Write-Info "Direktverbindung (kein Proxy)"
|
||||||
}
|
}
|
||||||
|
|
||||||
$webClient.DownloadFile($Url, $Destination)
|
$webClient.DownloadFile($Url, $Destination)
|
||||||
Write-Info "Download abgeschlossen: $Destination"
|
Write-Info "Download abgeschlossen: $Destination"
|
||||||
} catch {
|
}
|
||||||
|
catch {
|
||||||
Write-Err "Download fehlgeschlagen: $_"
|
Write-Err "Download fehlgeschlagen: $_"
|
||||||
exit 1
|
exit 1
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
$webClient.Dispose()
|
$webClient.Dispose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── MSI Install / Update ──────────────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# MSI Install / Update
|
||||||
|
# Verwendet ProcessStartInfo direkt - umgeht PS5.1 Quoting-Probleme
|
||||||
|
# bei Leerzeichen in Werten (z.B. Hostname "Tischlerei Terminal")
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function Install-ZabbixMsi {
|
function Install-ZabbixMsi {
|
||||||
param(
|
param(
|
||||||
@ -120,7 +144,6 @@ function Install-ZabbixMsi {
|
|||||||
$action = if ($IsUpdate) { "Update" } else { "Installation" }
|
$action = if ($IsUpdate) { "Update" } else { "Installation" }
|
||||||
Write-Info "Starte $action ..."
|
Write-Info "Starte $action ..."
|
||||||
|
|
||||||
# Bei Update: Dienst stoppen
|
|
||||||
if ($IsUpdate) {
|
if ($IsUpdate) {
|
||||||
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
if ($svc -and $svc.Status -eq "Running") {
|
if ($svc -and $svc.Status -eq "Running") {
|
||||||
@ -130,28 +153,35 @@ function Install-ZabbixMsi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$msiArgs = @(
|
$logFile = "$TempDir\zabbix-install.log"
|
||||||
"/i", $MsiPath,
|
$argString = "/i `"$MsiPath`" /qn /l*v `"$logFile`" " +
|
||||||
"/qn", # Silent
|
"SERVER=`"$ZabbixServer`" " +
|
||||||
"/l*v", "$TempDir\zabbix-install.log",
|
"SERVERACTIVE=`"$ZabbixServer`" " +
|
||||||
"SERVER=$ZabbixServer",
|
"HOSTNAME=`"$Hostname`" " +
|
||||||
"SERVERACTIVE=$ZabbixServer",
|
|
||||||
"HOSTNAME=$Hostname",
|
|
||||||
"LISTENPORT=10050"
|
"LISTENPORT=10050"
|
||||||
)
|
|
||||||
|
|
||||||
$proc = Start-Process -FilePath "msiexec.exe" -ArgumentList $msiArgs -Wait -PassThru
|
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
|
||||||
|
$pinfo.FileName = "msiexec.exe"
|
||||||
|
$pinfo.Arguments = $argString
|
||||||
|
$pinfo.UseShellExecute = $false
|
||||||
|
|
||||||
|
$proc = New-Object System.Diagnostics.Process
|
||||||
|
$proc.StartInfo = $pinfo
|
||||||
|
$proc.Start() | Out-Null
|
||||||
|
$proc.WaitForExit()
|
||||||
|
|
||||||
if ($proc.ExitCode -ne 0) {
|
if ($proc.ExitCode -ne 0) {
|
||||||
Write-Err "MSI $action fehlgeschlagen (ExitCode: $($proc.ExitCode))"
|
Write-Err "MSI $action fehlgeschlagen (ExitCode: $($proc.ExitCode))"
|
||||||
Write-Err "Details: $TempDir\zabbix-install.log"
|
Write-Err "Details: $logFile"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Info "MSI $action erfolgreich."
|
Write-Info "MSI $action erfolgreich."
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Dienst starten ────────────────────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Dienst starten
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
function Start-ZabbixService {
|
function Start-ZabbixService {
|
||||||
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
@ -168,55 +198,49 @@ function Start-ZabbixService {
|
|||||||
return $svc.Status
|
return $svc.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
# ── Hauptprogramm ─────────────────────────────────────────────────────────────
|
# --------------------------------------------------------------------------
|
||||||
|
# Hauptprogramm
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
|
||||||
Show-Header
|
Show-Header
|
||||||
|
|
||||||
# Installierte Version ermitteln
|
|
||||||
$installedVersion = Get-InstalledVersion
|
$installedVersion = Get-InstalledVersion
|
||||||
$isUpdate = $null -ne $installedVersion
|
$isUpdate = $null -ne $installedVersion
|
||||||
|
|
||||||
if ($isUpdate) {
|
if ($isUpdate) {
|
||||||
Write-Info "Installierte Version gefunden: $installedVersion"
|
Write-Info "Installierte Version gefunden: $installedVersion"
|
||||||
Write-Info "Modus: UPDATE auf $ZabbixVersion"
|
Write-Info "Modus: UPDATE auf $ZabbixVersion"
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Write-Info "Kein Zabbix Agent gefunden."
|
Write-Info "Kein Zabbix Agent gefunden."
|
||||||
Write-Info "Modus: NEUINSTALLATION von $ZabbixVersion"
|
Write-Info "Modus: NEUINSTALLATION von $ZabbixVersion"
|
||||||
}
|
}
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
# Hostname abfragen
|
|
||||||
$defaultHostname = $env:COMPUTERNAME
|
$defaultHostname = $env:COMPUTERNAME
|
||||||
$inputHostname = Read-Host "Zabbix-Hostname eingeben [Standard: $defaultHostname]"
|
$inputHostname = Read-Host "Zabbix-Hostname eingeben [Standard: $defaultHostname]"
|
||||||
$agentHostname = if ($inputHostname.Trim() -eq "") { $defaultHostname } else { $inputHostname.Trim() }
|
$agentHostname = if ($inputHostname.Trim() -eq "") { $defaultHostname } else { $inputHostname.Trim() }
|
||||||
Write-Info "Verwende Hostname: $agentHostname"
|
Write-Info "Verwende Hostname: $agentHostname"
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
# Proxy-Auswahl
|
|
||||||
$selectedProxy = Select-Proxy
|
$selectedProxy = Select-Proxy
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
|
|
||||||
# MSI-Download-URL zusammenbauen
|
|
||||||
$arch = "amd64"
|
$arch = "amd64"
|
||||||
$msiFile = "zabbix_agent2-$ZabbixVersion-windows-$arch-openssl.msi"
|
$msiFile = "zabbix_agent2-$ZabbixVersion-windows-$arch-openssl.msi"
|
||||||
$msiUrl = "https://cdn.zabbix.com/zabbix/binaries/stable/" +
|
$msiUrl = "https://cdn.zabbix.com/zabbix/binaries/stable/" +
|
||||||
"$($ZabbixVersion.Split('.')[0..1] -join '.')/$ZabbixVersion/$msiFile"
|
"$($ZabbixVersion.Split('.')[0..1] -join '.')/$ZabbixVersion/$msiFile"
|
||||||
$msiDest = "$TempDir\$msiFile"
|
$msiDest = "$TempDir\$msiFile"
|
||||||
|
|
||||||
# Download
|
|
||||||
Get-ZabbixMsi -Url $msiUrl -Destination $msiDest -ProxyUrl $selectedProxy
|
Get-ZabbixMsi -Url $msiUrl -Destination $msiDest -ProxyUrl $selectedProxy
|
||||||
|
|
||||||
# Installation / Update
|
|
||||||
Install-ZabbixMsi -MsiPath $msiDest -Hostname $agentHostname -IsUpdate $isUpdate
|
Install-ZabbixMsi -MsiPath $msiDest -Hostname $agentHostname -IsUpdate $isUpdate
|
||||||
|
|
||||||
# Temporäre Datei aufräumen
|
|
||||||
Remove-Item -Path $msiDest -Force -ErrorAction SilentlyContinue
|
Remove-Item -Path $msiDest -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# Dienst starten
|
|
||||||
Write-Info "Starte Zabbix-Dienst ..."
|
Write-Info "Starte Zabbix-Dienst ..."
|
||||||
$status = Start-ZabbixService
|
$status = Start-ZabbixService
|
||||||
|
|
||||||
# Ergebnis
|
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "=============================================" -ForegroundColor Cyan
|
Write-Host "=============================================" -ForegroundColor Cyan
|
||||||
Write-Info " Zabbix Agent 2 erfolgreich eingerichtet!"
|
Write-Info " Zabbix Agent 2 erfolgreich eingerichtet!"
|
||||||
|
|||||||
Reference in New Issue
Block a user