Commit 9f847963 by Rinat K. Nugaev

Added creating log dir and download from any url

parent 384d427c
...@@ -56,9 +56,11 @@ Break ...@@ -56,9 +56,11 @@ Break
} }
#Getting and defining some vars #Getting and defining some vars
#$urldistzabbix where your zabbix_agent archive #$urldistzabbix where your zabbix_agent archive
$urldistzabbix = "https://support.nugaev.net/files/distrib/zabbix_agent.zip" #$urldistzabbix = "https://support.nugaev.net/files/distrib/zabbix_agent.zip"
$urldistzabbix = "https://www.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.win.zip"
#$temparchivedir where you'll download zabbix_agent archive #$temparchivedir where you'll download zabbix_agent archive
$temparchivedir = $env:TEMP $temparchive = "$env:TEMP\zabbix_agent.zip"
#$PathZabbix folder where you'll install zabbix agent #$PathZabbix folder where you'll install zabbix agent
$PathZabbix = ${env:ProgramFiles} + '\Zabbix' $PathZabbix = ${env:ProgramFiles} + '\Zabbix'
#$ZabbixConf zabbix agent config #$ZabbixConf zabbix agent config
...@@ -70,7 +72,7 @@ $monserverip = (Test-Connection -ComputerName monitoring.nugaev.net -count 1).IP ...@@ -70,7 +72,7 @@ $monserverip = (Test-Connection -ComputerName monitoring.nugaev.net -count 1).IP
#Downloading and unzip zabbix agent #Downloading and unzip zabbix agent
Try Try
{ {
Start-BitsTransfer -Source $urldistzabbix -Destination $temparchivedir -ErrorAction stop Start-BitsTransfer -Source $urldistzabbix -Destination $temparchive -ErrorAction stop
} }
Catch Catch
{ {
...@@ -89,8 +91,10 @@ function Unzip ...@@ -89,8 +91,10 @@ function Unzip
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath) [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
} }
Unzip $temparchive\zabbix_agent.zip $PathZabbix Unzip $temparchive $PathZabbix
Remove-Item -Force $temparchive\zabbix_agent.zip Remove-Item -Force $temparchive
#Creating zabbix agent log folder
New-Item -ItemType directory -Path $PathZabbix\log
#Getting computer hostname for config file #Getting computer hostname for config file
$HostnameFull ="$env:computername.$env:userdnsdomain" $HostnameFull ="$env:computername.$env:userdnsdomain"
#Removing dot from end of the hostname (this behavior possible if computer is not domain joined) #Removing dot from end of the hostname (this behavior possible if computer is not domain joined)
...@@ -120,12 +124,14 @@ else ...@@ -120,12 +124,14 @@ else
#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 #Installing Zabbix Service
Try Try
{ {
New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand -DisplayName "Zabbix Agent" -Description "Provides Monitoring" -StartupType "Automatic" New-Service -Name "Zabbix Agent" -BinaryPathName $ZabbixInstallCommand `
-DisplayName "Zabbix Agent" -Description "Provides Monitoring" -StartupType "Automatic"
} }
Catch Catch
{ {
......
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