Commit 384d427c by Rinat K. Nugaev

Added some comments

parent 5447d0c6
......@@ -21,11 +21,8 @@
This script install only 64 bit version
.Remarks
This can then be deployed via GPO or other means.
This coupled with a discovery rule in the Zabbix app will set the host up.
This can then be run manually on each server
Ensure that you have set the configuration file correctly for your Zabbix setup BEFORE deploying.
.Author: Rinat K. Nugaev
.Date: 06/08/2018
......@@ -39,7 +36,8 @@ If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent
{
Write-Warning "You do not have Admin rights to run this script!`nPlease re-run this script with Admin rights!"
Write-Warning "You do not have Admin rights to run this script!`nPlease`
re-run this script with Admin rights!"
Break
......@@ -52,41 +50,45 @@ Import-Module BitsTransfer -ErrorAction stop
Catch
{
$ErrorMessage = $_.Exception.Message
write-host "I cannot import the Bits module ((("
write-host "Cannot import Bits module..."
write-host $ErrorMessage
Break
}
#Getting and defining some vars
#$urldistzabbix where your zabbix_agent archive
$urldistzabbix = "https://support.nugaev.net/files/distrib/zabbix_agent.zip"
#$temparchivedir where you'll download zabbix_agent archive
$temparchivedir = $env:TEMP
#$PathZabbix folder where you'll install zabbix agent
$PathZabbix = ${env:ProgramFiles} + '\Zabbix'
$osarch = wmic os get OSArchitecture /value
#$ZabbixConf zabbix agent config
$ZabbixConf = $PathZabbix + '\conf\zabbix_agentd.conf'
#Your OS architechture
$OsArch = wmic os get OSArchitecture /value
#Getting monitoring server ip for Firewall Rule
$monserverip = (Test-Connection -ComputerName monitoring.nugaev.net -count 1).IPV4Address.ipaddressTOstring
#Downloading and unzip zabbix agent
Try
{
$url = "https://support.nugaev.net/files/distrib/zabbix_agent.zip"
$temparchive = $env:TEMP
Start-BitsTransfer -Source $url -Destination $temparchive -ErrorAction stop
}
{
Start-BitsTransfer -Source $urldistzabbix -Destination $temparchivedir -ErrorAction stop
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
write-host "I cannot download the archive ((("
write-host $ErrorMessage
Break
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
write-host "I cannot download the archive ((("
write-host $ErrorMessage
Break
}
#unzip it
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip
{
{
param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}
}
Unzip $temparchive\zabbix_agent.zip $PathZabbix
Remove-Item -Force $temparchive\zabbix_agent.zip
#Getting computer hostname for config file
......@@ -105,25 +107,25 @@ HostMetadataItem=system.uname
#Adding content to the config file
Add-Content -Value "$confcont" -Path $ZabbixConf
$osarch = wmic os get OSArchitecture /value
if ($osarch -eq "OSArchitecture=64-bit")
#Defining $OsArch variable. It depend on system platform, 64 or 32 bits
$OsArch = wmic os get OSArchitecture /value
if ($OsArch -eq "OSArchitecture=64-bit")
{
$osarch = 'win64'
$OsArch = 'win64'
}
else
{
$osarch = 'win32'
$OsArch = 'win32'
}
#Defining zabbix install command. It depends on $osarch variable
$ZabbixInstallCommand = "`"C:\Program Files\Zabbix\bin\$osarch\zabbix_agentd.exe`" --config `"C:\Program Files\Zabbix\conf\zabbix_agentd.conf`""
#Defining zabbix install command. It depends on $OsArch variable
$ZabbixInstallCommand = "`"C:\Program Files\Zabbix\bin\$OsArch\zabbix_agentd.exe`" --config `"C:\Program Files\Zabbix\conf\zabbix_agentd.conf`""
#Installing Zabbix Service
Try
{
New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand `
-DisplayName "Zabbix Agent" -Description "Provides system monitoring" -StartupType "Automatic"
New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand -DisplayName "Zabbix Agent" -Description "Provides Monitoring" -StartupType "Automatic"
}
Catch
{
......@@ -136,22 +138,35 @@ Break
#Starting zabbix agent
Try
{
start-service -name "Zabbix Agent" -ErrorAction Stop
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
write-host "Cannot Start Zabbix Service ((("
write-host $ErrorMessage
Break
}
#Dont remember why but entering to the temporary directory
cd ${ENV:temp}
#Adding firewall rules for zabbix agent inbound for zabbix server and outbound for agent
Try
{
start-service -name "Zabbix Agent" -ErrorAction Stop
New-NetFirewallRule -DisplayName "Zabbix Agent IN" -RemoteAddress $monserverip `
-Profile Any -Action Allow -Direction Inbound -Protocol TCP -LocalPort 10050 | out-null
New-NetFirewallRule -DisplayName "Zabbix Agent OUT" -RemoteAddress $monserverip `
-Profile Any -Action Allow -Direction OutBound -Protocol TCP -LocalPort 10051 | out-null
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
write-host "Cannot Start Zabbix Service ((("
write-host "Cannot Add Firewall Rules..."
write-host $ErrorMessage
Break
}
#Dont remember why but entering to the temporary directory
cd ${ENV:temp}
#Adding firewall rules for zabbix agent inbound for zabbix server and outbound for agent
New-NetFirewallRule -DisplayName "Zabbix" -RemoteAddress $monserverip -Profile Any -Action Allow -Direction Inbound -Protocol TCP -LocalPort 10050
New-NetFirewallRule -DisplayName "ZabbixOUT" -RemoteAddress $monserverip -Profile Any -Action Allow -Direction OutBound -Protocol TCP -LocalPort 10050
New-NetFirewallRule -DisplayName "ZabbixOUT" -RemoteAddress $monserverip -Profile Any -Action Allow -Direction OutBound -Protocol TCP -LocalPort 10051
Write-host "Firewall rule for Monitoring Server added..."
Write-host "Firewall rules for Zabbix Agent added..."
Write-host "Installation completed!"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment