Commit 5447d0c6 by Rinat K. Nugaev

Added Try and Catch command for run agent and added chosing paltform

parent 1311e390
......@@ -8,6 +8,28 @@
#
# CHANGELOG
# Version 0.3:
<#
.NAME
Zabbix Agent Install.
.SYNOPSIS
Installs Zabbix Agent Service and starts it.
.Descripton
This script downloading zabbix agent zip archive unzip this archive to the ProgramFiles folder
Script installs Zabbix Agent Service
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.
Ensure that you have set the configuration file correctly for your Zabbix setup BEFORE deploying.
.Author: Rinat K. Nugaev
.Date: 06/08/2018
#>
#Checking that script run with admin privilegies
......@@ -37,7 +59,7 @@ Break
#Getting and defining some vars
$PathZabbix = ${env:ProgramFiles} + '\Zabbix'
#$osarch = wmic os get OSArchitecture /value
$osarch = wmic os get OSArchitecture /value
$ZabbixConf = $PathZabbix + '\conf\zabbix_agentd.conf'
#Getting monitoring server ip for Firewall Rule
$monserverip = (Test-Connection -ComputerName monitoring.nugaev.net -count 1).IPV4Address.ipaddressTOstring
......@@ -83,12 +105,48 @@ HostMetadataItem=system.uname
#Adding content to the config file
Add-Content -Value "$confcont" -Path $ZabbixConf
#Installing zabbix agent as a service
New-Service -Name "Zabbix Agent" -BinaryPathName '"C:\Program Files\Zabbix\bin\win64\zabbix_agentd.exe" --config "C:\Program Files\Zabbix\conf\zabbix_agentd.conf"' `
-DisplayName "Zabbix Agent" -Description "Provides system monitoring" -StartupType "Automatic" -ErrorAction SilentlyContinue
#Starting zabbix agent
Get-service -name "Zabbix Agent" | start-service
$osarch = wmic os get OSArchitecture /value
if ($osarch -eq "OSArchitecture=64-bit")
{
$osarch = 'win64'
}
else
{
$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`""
Try
{
New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand `
-DisplayName "Zabbix Agent" -Description "Provides system monitoring" -StartupType "Automatic"
}
Catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
write-host "Cannot Install Zabbix Service ((("
write-host $ErrorMessage
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
......
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