From b30e5adf524333bf5bc392e6bc0446598394c5f0 Mon Sep 17 00:00:00 2001 From: Erenalp06 Date: Fri, 12 Jul 2024 09:23:05 +0300 Subject: [PATCH 1/2] online/offline windows zabbix agent installation scripts --- zabbix-offline-3.ps1 | 98 ++++++++++++++++++++++++++++++++++++++++++++ zabbix-online-2.ps1 | 98 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 zabbix-offline-3.ps1 create mode 100644 zabbix-online-2.ps1 diff --git a/zabbix-offline-3.ps1 b/zabbix-offline-3.ps1 new file mode 100644 index 0000000..d691a48 --- /dev/null +++ b/zabbix-offline-3.ps1 @@ -0,0 +1,98 @@ +# Zabbix sunucu IP adresini belirleyin +$ZABBIX_SERVER_IP = "" + +# Dizin ve dosya yollarını belirleyin +$zabbixAgentDirectory = "C:\Program Files\zabbix-agent" +$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition +$zipFile = Join-Path -Path $scriptDirectory -ChildPath "zabbix-agent.zip" + +# Program Files içinde Zabbix Agent dizinini oluşturun +if (-not (Test-Path $zabbixAgentDirectory)) { + New-Item -ItemType Directory -Path $zabbixAgentDirectory -Force | Out-Null +} + +# Gerekli dosyaları indir +$zabbixAgentUrl = "https://cdn.zabbix.com/zabbix/binaries/stable/6.0/6.0.12/zabbix_agent-6.0.12-windows-amd64.zip" +$vcRedistUrl = "https://aka.ms/vs/17/release/vc_redist.x64.exe" +$snmpwalkUrl = "https://github.com/limanmys/zabbix-agent-slient/releases/download/snmp/snmpwalk.exe" + +Invoke-WebRequest -Uri $zabbixAgentUrl -OutFile "$scriptDirectory\zabbix-agent.zip" +Invoke-WebRequest -Uri $vcRedistUrl -OutFile "$scriptDirectory\vc_redist.x64.exe" +Invoke-WebRequest -Uri $snmpwalkUrl -OutFile "$scriptDirectory\snmpwalk.exe" + +# Zabbix Agent ZIP dosyasını çıkarın +if (Test-Path $zipFile) { + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $zabbixAgentDirectory) + Write-Host "Extraction completed." +} else { + Write-Host "Zip file not found: $zipFile" + exit +} + +# Gerekli bağımlılıkları kopyalayın +Copy-Item -Path "$scriptDirectory\vc_redist.x64.exe" -Destination $zabbixAgentDirectory -Force +Copy-Item -Path "$scriptDirectory\snmpwalk.exe" -Destination $zabbixAgentDirectory -Force + +# Zabbix Agent servisinin kaldırılması (varsa) +if (Get-Service -Name "Zabbix Agent" -ErrorAction SilentlyContinue) { + sc stop "Zabbix Agent" + sc delete "Zabbix Agent" + Start-Sleep -Seconds 10 # Kaldırma işleminin tamamlanması için bekleyin +} + +# Çıkarılan dosyaların doğru yerde olduğunu kontrol edin +if (-not (Test-Path "$zabbixAgentDirectory\conf\zabbix_agentd.conf") -or -not (Test-Path "$zabbixAgentDirectory\bin\zabbix_agentd.exe")) { + Write-Host "Required files are missing. Please check the ZIP file and extraction path." + exit +} + +# Visual C++ Redistributable'ın kurulumu +if (Test-Path "$zabbixAgentDirectory\vc_redist.x64.exe") { + Start-Process -FilePath "$zabbixAgentDirectory\vc_redist.x64.exe" -ArgumentList "/quiet", "/norestart" -Wait +} else { + Write-Host "vc_redist.x64.exe not found in $zabbixAgentDirectory" + exit +} + +# Konfigürasyon dosyasının düzenlenmesi +$configPath = "$zabbixAgentDirectory\conf\zabbix_agentd.conf" +if (Test-Path $configPath) { + (Get-Content $configPath) ` + -replace 'Server=127.0.0.1', "Server=$ZABBIX_SERVER_IP" ` + | Set-Content $configPath + + # Dosyanın doğru şekilde değiştirildiğini doğrulayın + $updatedContent = Get-Content -Path $configPath + Write-Host "Updated configuration file content:" + Write-Host $updatedContent +} else { + Write-Host "Configuration file not found: $configPath" + exit +} + +# Zabbix Agent'in kurulması ve başlatılması +& "$zabbixAgentDirectory\bin\zabbix_agentd.exe" --config "$zabbixAgentDirectory\conf\zabbix_agentd.conf" --install + +# Güvenlik duvarı kuralının eklenmesi +New-NetFirewallRule -DisplayName "Zabbix Agent Rule" -Direction Inbound -LocalPort 10050 -Protocol TCP -Action Allow + +# SNMPwalk aracının kontrol edilmesi ve PATH'e eklenmesi +$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine") +$snmpwalkDirectory = "$zabbixAgentDirectory" +$snmpwalkFilePath = "$zabbixAgentDirectory\snmpwalk.exe" + +if (-not (Test-Path -Path $snmpwalkFilePath)) { + Write-Host "snmpwalk.exe not found in $snmpwalkDirectory" + exit +} + +if ($currentPath -notlike "*$snmpwalkDirectory*") { + [Environment]::SetEnvironmentVariable("Path", "$currentPath;$snmpwalkDirectory", "Machine") + Write-Host "Directory added to PATH. You can now use 'snmpwalk' command." +} else { + Write-Host "Directory is already in PATH." +} + +# Zabbix Agent'in başlatılması +& "$zabbixAgentDirectory\bin\zabbix_agentd.exe" --start --config "$zabbixAgentDirectory\conf\zabbix_agentd.conf" diff --git a/zabbix-online-2.ps1 b/zabbix-online-2.ps1 new file mode 100644 index 0000000..e281c85 --- /dev/null +++ b/zabbix-online-2.ps1 @@ -0,0 +1,98 @@ +# Zabbix sunucu IP adresini belirleyin +$ZABBIX_SERVER_IP = "" + +# Dizin ve dosya yollarını belirleyin +$zabbixAgentDirectory = "C:\Program Files\zabbix-agent" +$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition +$zipFile = Join-Path -Path $scriptDirectory -ChildPath "zabbix-agent.zip" + +# Program Files içinde Zabbix Agent dizinini oluşturun +if (-not (Test-Path $zabbixAgentDirectory)) { + New-Item -ItemType Directory -Path $zabbixAgentDirectory -Force | Out-Null +} + +# Gerekli dosyaları indir +$zabbixAgentUrl = "https://cdn.zabbix.com/zabbix/binaries/stable/6.0/6.0.12/zabbix_agent2-6.0.12-windows-amd64-static.zip" +$vcRedistUrl = "https://aka.ms/vs/17/release/vc_redist.x64.exe" +$snmpwalkUrl = "https://github.com/limanmys/zabbix-agent-slient/releases/download/snmp/snmpwalk.exe" + +Invoke-WebRequest -Uri $zabbixAgentUrl -OutFile "$scriptDirectory\zabbix-agent.zip" +Invoke-WebRequest -Uri $vcRedistUrl -OutFile "$scriptDirectory\vc_redist.x64.exe" +Invoke-WebRequest -Uri $snmpwalkUrl -OutFile "$scriptDirectory\snmpwalk.exe" + +# Zabbix Agent ZIP dosyasını çıkarın +if (Test-Path $zipFile) { + Add-Type -AssemblyName System.IO.Compression.FileSystem + [System.IO.Compression.ZipFile]::ExtractToDirectory($zipFile, $zabbixAgentDirectory) + Write-Host "Extraction completed." +} else { + Write-Host "Zip file not found: $zipFile" + exit +} + +# Gerekli bağımlılıkları kopyalayın +Copy-Item -Path "$scriptDirectory\vc_redist.x64.exe" -Destination $zabbixAgentDirectory -Force +Copy-Item -Path "$scriptDirectory\snmpwalk.exe" -Destination $zabbixAgentDirectory -Force + +# Zabbix Agent servisinin kaldırılması (varsa) +if (Get-Service -Name "Zabbix Agent" -ErrorAction SilentlyContinue) { + sc stop "Zabbix Agent" + sc delete "Zabbix Agent" + Start-Sleep -Seconds 10 # Kaldırma işleminin tamamlanması için bekleyin +} + +# Çıkarılan dosyaların doğru yerde olduğunu kontrol edin +if (-not (Test-Path "$zabbixAgentDirectory\conf\zabbix_agentd.conf") -or -not (Test-Path "$zabbixAgentDirectory\bin\zabbix_agentd.exe")) { + Write-Host "Required files are missing. Please check the ZIP file and extraction path." + exit +} + +# Visual C++ Redistributable'ın kurulumu +if (Test-Path "$zabbixAgentDirectory\vc_redist.x64.exe") { + Start-Process -FilePath "$zabbixAgentDirectory\vc_redist.x64.exe" -ArgumentList "/quiet", "/norestart" -Wait +} else { + Write-Host "vc_redist.x64.exe not found in $zabbixAgentDirectory" + exit +} + +# Konfigürasyon dosyasının düzenlenmesi +$configPath = "$zabbixAgentDirectory\conf\zabbix_agentd.conf" +if (Test-Path $configPath) { + (Get-Content $configPath) ` + -replace 'Server=127.0.0.1', "Server=$ZABBIX_SERVER_IP" ` + | Set-Content $configPath + + # Dosyanın doğru şekilde değiştirildiğini doğrulayın + $updatedContent = Get-Content -Path $configPath + Write-Host "Updated configuration file content:" + Write-Host $updatedContent +} else { + Write-Host "Configuration file not found: $configPath" + exit +} + +# Zabbix Agent'in kurulması ve başlatılması +& "$zabbixAgentDirectory\bin\zabbix_agentd.exe" --config "$zabbixAgentDirectory\conf\zabbix_agentd.conf" --install + +# Güvenlik duvarı kuralının eklenmesi +New-NetFirewallRule -DisplayName "Zabbix Agent Rule" -Direction Inbound -LocalPort 10050 -Protocol TCP -Action Allow + +# SNMPwalk aracının kontrol edilmesi ve PATH'e eklenmesi +$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine") +$snmpwalkDirectory = "$zabbixAgentDirectory" +$snmpwalkFilePath = "$zabbixAgentDirectory\snmpwalk.exe" + +if (-not (Test-Path -Path $snmpwalkFilePath)) { + Write-Host "snmpwalk.exe not found in $snmpwalkDirectory" + exit +} + +if ($currentPath -notlike "*$snmpwalkDirectory*") { + [Environment]::SetEnvironmentVariable("Path", "$currentPath;$snmpwalkDirectory", "Machine") + Write-Host "Directory added to PATH. You can now use 'snmpwalk' command." +} else { + Write-Host "Directory is already in PATH." +} + +# Zabbix Agent'in başlatılması +& "$zabbixAgentDirectory\bin\zabbix_agentd.exe" --start --config "$zabbixAgentDirectory\conf\zabbix_agentd.conf" From 5265102d4352e7c18346cc22e349bd9362293623 Mon Sep 17 00:00:00 2001 From: Erenalp06 Date: Tue, 16 Jul 2024 09:56:28 +0300 Subject: [PATCH 2/2] fix: offline script bugs fixed --- zabbix-offline-3.ps1 => zabbix-offline.ps1 | 23 +++++++++++----------- 1 file changed, 11 insertions(+), 12 deletions(-) rename zabbix-offline-3.ps1 => zabbix-offline.ps1 (83%) diff --git a/zabbix-offline-3.ps1 b/zabbix-offline.ps1 similarity index 83% rename from zabbix-offline-3.ps1 rename to zabbix-offline.ps1 index d691a48..56b350f 100644 --- a/zabbix-offline-3.ps1 +++ b/zabbix-offline.ps1 @@ -1,4 +1,12 @@ -# Zabbix sunucu IP adresini belirleyin + +# Yönetici iznini kontrol et ve gerekirse talep et +If (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) +{ + Write-Host "This script needs to be run as an Administrator. Please restart PowerShell as an Administrator." + exit +} + +# Zabbix sunucu IP adreslerini ve hostname'i belirleyin $ZABBIX_SERVER_IP = "" # Dizin ve dosya yollarını belirleyin @@ -11,15 +19,6 @@ if (-not (Test-Path $zabbixAgentDirectory)) { New-Item -ItemType Directory -Path $zabbixAgentDirectory -Force | Out-Null } -# Gerekli dosyaları indir -$zabbixAgentUrl = "https://cdn.zabbix.com/zabbix/binaries/stable/6.0/6.0.12/zabbix_agent-6.0.12-windows-amd64.zip" -$vcRedistUrl = "https://aka.ms/vs/17/release/vc_redist.x64.exe" -$snmpwalkUrl = "https://github.com/limanmys/zabbix-agent-slient/releases/download/snmp/snmpwalk.exe" - -Invoke-WebRequest -Uri $zabbixAgentUrl -OutFile "$scriptDirectory\zabbix-agent.zip" -Invoke-WebRequest -Uri $vcRedistUrl -OutFile "$scriptDirectory\vc_redist.x64.exe" -Invoke-WebRequest -Uri $snmpwalkUrl -OutFile "$scriptDirectory\snmpwalk.exe" - # Zabbix Agent ZIP dosyasını çıkarın if (Test-Path $zipFile) { Add-Type -AssemblyName System.IO.Compression.FileSystem @@ -59,8 +58,8 @@ if (Test-Path "$zabbixAgentDirectory\vc_redist.x64.exe") { $configPath = "$zabbixAgentDirectory\conf\zabbix_agentd.conf" if (Test-Path $configPath) { (Get-Content $configPath) ` - -replace 'Server=127.0.0.1', "Server=$ZABBIX_SERVER_IP" ` - | Set-Content $configPath + -replace 'Server=127.0.0.1', "Server=$ZABBIX_SERVER_IP" ` + | Set-Content $configPath # Dosyanın doğru şekilde değiştirildiğini doğrulayın $updatedContent = Get-Content -Path $configPath