Commit 384d427c by Rinat K. Nugaev

Added some comments

parent 5447d0c6
...@@ -21,11 +21,8 @@ ...@@ -21,11 +21,8 @@
This script install only 64 bit version This script install only 64 bit version
.Remarks .Remarks
This can then be deployed via GPO or other means. This can then be run manually on each server
This coupled with a discovery rule in the Zabbix app will set the host up.
Ensure that you have set the configuration file correctly for your Zabbix setup BEFORE deploying.
.Author: Rinat K. Nugaev .Author: Rinat K. Nugaev
.Date: 06/08/2018 .Date: 06/08/2018
...@@ -39,7 +36,8 @@ If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent ...@@ -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 Break
...@@ -52,41 +50,45 @@ Import-Module BitsTransfer -ErrorAction stop ...@@ -52,41 +50,45 @@ Import-Module BitsTransfer -ErrorAction stop
Catch Catch
{ {
$ErrorMessage = $_.Exception.Message $ErrorMessage = $_.Exception.Message
write-host "I cannot import the Bits module (((" write-host "Cannot import Bits module..."
write-host $ErrorMessage write-host $ErrorMessage
Break Break
} }
#Getting and defining some vars #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' $PathZabbix = ${env:ProgramFiles} + '\Zabbix'
#$ZabbixConf zabbix agent config
$osarch = wmic os get OSArchitecture /value
$ZabbixConf = $PathZabbix + '\conf\zabbix_agentd.conf' $ZabbixConf = $PathZabbix + '\conf\zabbix_agentd.conf'
#Your OS architechture
$OsArch = wmic os get OSArchitecture /value
#Getting monitoring server ip for Firewall Rule #Getting monitoring server ip for Firewall Rule
$monserverip = (Test-Connection -ComputerName monitoring.nugaev.net -count 1).IPV4Address.ipaddressTOstring $monserverip = (Test-Connection -ComputerName monitoring.nugaev.net -count 1).IPV4Address.ipaddressTOstring
#Downloading and unzip zabbix agent #Downloading and unzip zabbix agent
Try Try
{ {
$url = "https://support.nugaev.net/files/distrib/zabbix_agent.zip" Start-BitsTransfer -Source $urldistzabbix -Destination $temparchivedir -ErrorAction stop
$temparchive = $env:TEMP }
Start-BitsTransfer -Source $url -Destination $temparchive -ErrorAction stop
}
Catch Catch
{ {
$ErrorMessage = $_.Exception.Message $ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName $FailedItem = $_.Exception.ItemName
write-host "I cannot download the archive (((" write-host "I cannot download the archive ((("
write-host $ErrorMessage write-host $ErrorMessage
Break Break
} }
#unzip it #unzip it
Add-Type -AssemblyName System.IO.Compression.FileSystem Add-Type -AssemblyName System.IO.Compression.FileSystem
function Unzip function Unzip
{ {
param([string]$zipfile, [string]$outpath) param([string]$zipfile, [string]$outpath)
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
} }
Unzip $temparchive\zabbix_agent.zip $PathZabbix Unzip $temparchive\zabbix_agent.zip $PathZabbix
Remove-Item -Force $temparchive\zabbix_agent.zip Remove-Item -Force $temparchive\zabbix_agent.zip
#Getting computer hostname for config file #Getting computer hostname for config file
...@@ -105,25 +107,25 @@ HostMetadataItem=system.uname ...@@ -105,25 +107,25 @@ HostMetadataItem=system.uname
#Adding content to the config file #Adding content to the config file
Add-Content -Value "$confcont" -Path $ZabbixConf Add-Content -Value "$confcont" -Path $ZabbixConf
$osarch = wmic os get OSArchitecture /value #Defining $OsArch variable. It depend on system platform, 64 or 32 bits
if ($osarch -eq "OSArchitecture=64-bit") $OsArch = wmic os get OSArchitecture /value
if ($OsArch -eq "OSArchitecture=64-bit")
{ {
$osarch = 'win64' $OsArch = 'win64'
} }
else else
{ {
$osarch = 'win32' $OsArch = 'win32'
} }
#Defining zabbix install command. It depends on $osarch variable #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`"" $ZabbixInstallCommand = "`"C:\Program Files\Zabbix\bin\$OsArch\zabbix_agentd.exe`" --config `"C:\Program Files\Zabbix\conf\zabbix_agentd.conf`""
#Installing Zabbix Service
Try Try
{ {
New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand ` New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand -DisplayName "Zabbix Agent" -Description "Provides Monitoring" -StartupType "Automatic"
-DisplayName "Zabbix Agent" -Description "Provides system monitoring" -StartupType "Automatic"
} }
Catch Catch
{ {
...@@ -136,22 +138,35 @@ Break ...@@ -136,22 +138,35 @@ Break
#Starting zabbix agent #Starting zabbix agent
Try 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 Catch
{ {
$ErrorMessage = $_.Exception.Message $ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName $FailedItem = $_.Exception.ItemName
write-host "Cannot Start Zabbix Service (((" write-host "Cannot Add Firewall Rules..."
write-host $ErrorMessage write-host $ErrorMessage
Break Break
} }
#Dont remember why but entering to the temporary directory
cd ${ENV:temp} Write-host "Firewall rules for Zabbix Agent added..."
#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 "Installation completed!" 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