Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
install_zabbix_agent_win
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Rinat K. Nugaev
install_zabbix_agent_win
Commits
c81b68e9
Commit
c81b68e9
authored
Jun 13, 2018
by
Rinat K. Nugaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final version of zabbix_install script
parent
2ef8b007
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
94 deletions
+91
-94
zabbix_install.ps1
+91
-94
No files found.
zabbix_install.ps1
View file @
c81b68e9
# AUTHOR : Rinat K. Nugaev - http://www.nugaev.net - code@nugaev.net
# DATE : 06.06.2018
# EDIT :
08
.06.2018
# EDIT :
11
.06.2018
# COMMENT :
#
#
# VERSION : 0.2
#
# CHANGELOG
# Version 0.3:
# Version 0.3:
Added some improvements
<#
.NAME
Zabbix Agent Install.
...
...
@@ -43,135 +43,133 @@ If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdent
}
#Importing module BitsTransfer for downloading zip archive with zabbix agent
Try
{
Import-Module BitsTransfer -ErrorAction stop
}
Catch
{
$ErrorMessage
=
$_
.Exception.Message
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"
#$urldistzabbix = "https://www.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.win.zip"
#$temparchivedir where you'll download zabbix_agent archive
$temparchive
=
"
$env
:TEMP\zabbix_agent.zip"
#$PathZabbix folder where you'll install zabbix agent
###VARIABLES
# $UrlDistZabbix where your zabbix_agent archive
$UrlDistZabbix
=
"https://www.zabbix.com/downloads/3.4.6/zabbix_agents_3.4.6.win.zip"
#$UrlDistZabbix = "https://support.nugaev.net/files/distrib/zabbix_agent.zip"
# $MonitoringServer DNS Name of your Monitoring server
$MonitoringServer
=
"monitoring.nugaev.net"
# $temparchivedir where you'll download zabbix_agent archive
$TempArchive
=
"
$env
:TEMP\zabbix_agent.zip"
# $PathZabbix folder where you'll install zabbix agent
$PathZabbix
=
${
env
:ProgramFiles
}
+
'\Zabbix'
#$ZabbixConf zabbix agent config
#
$ZabbixConf zabbix agent config
$ZabbixConf
=
$PathZabbix
+
'\conf\zabbix_agentd.win.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
#$MonServerIp = [System.Net.Dns]::GetHostAddresses("$MonitoringServer").ipaddressTOstring
$MonServerIp
=
(
Resolve-DNSName
monitoring.nugaev.net
)
.IP4Address
#Getting computer hostname for config file
$CompHostName
=
"
$env
:computername.
$env
:userdnsdomain"
#Removing dot from end of the hostname (dot appears when computer is not a domain member)
$CompHostName
=
$CompHostName
-replace
"\.(?<=\z)"
,
""
###Creating config file
#Preparing content for config file
$ConfContent
=
"
LogFile=
$PathZabbix
\log\zabbix_agentd.log
Server=
$MonitoringServer
ServerActive=
$MonitoringServer
Hostname=
$CompHostName
HostMetadataItem=system.uname
"
#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'
}
else
{
$OsArch
=
'win32'
}
#Downloading and unzip Zabbix Agent
Try
{
Start-BitsTransfer
-Source
$
urldistzabbix
-Destination
$tempa
rchive
-ErrorAction stop
Start-BitsTransfer
-Source
$
UrlDistZabbix
-Destination
$TempA
rchive
-ErrorAction stop
}
Catch
{
$ErrorMessage
=
$_
.Exception.Message
$FailedItem
=
$_
.Exception.ItemName
write-host
"
I cannot download the archive (((
"
write-host
"
Cannot download Zabbix Agent archive from link
$UrlDistZabbix
"
write-host
$ErrorMessage
Break
}
}
#
unzip it
#
Unzip Zabbix Agent archive
Add-Type
-AssemblyName System.IO.Compression.FileSystem
function
Un
z
ip
function
Un
Z
ip
{
param
([
string
]
$zipfile
,
[
string
]
$outpath
)
[
System.IO.Compression.ZipFile]::ExtractToDirectory
(
$zipfile
,
$outpath
)
}
Unzip
$temparchive
$PathZabbix
Remove-Item
-Force
$temparchive
#Creating zabbix agent log folder
New-Item
-ItemType directory -Path
$PathZabbix
\log
#Getting computer hostname for config file
$HostnameFull
=
"
$env
:computername.
$env
:userdnsdomain"
#Removing dot from end of the hostname (this behavior possible if computer is not domain joined)
$HostnameFull
=
$HostnameFull
-replace
"\.(?<=\z)"
,
""
#Creating config
#Preparing content for config gile
$confcont
=
"
LogFile=
$PathZabbix
\log\zabbix_agentd.log
Server=monitoring.nugaev.net
ServerActive=monitoring.nugaev.net
Hostname=
$HostnameFull
HostMetadataItem=system.uname
"
#Adding content to the config file
Set-Content
-Value
"
$confcont
"
-Path
$ZabbixConf
#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'
}
else
{
$OsArch
=
'win32'
}
UnZip
$TempArchive
$PathZabbix
Remove-Item
-Force
$TempArchive
#Creating Zabbix Agent log folder
New-Item
-ItemType directory -Path
$PathZabbix
\log -ErrorAction Stop | out-null
#Setting up the content to the config file
Set-Content
-Value
"
$ConfContent
"
-Path
$ZabbixConf
#Defining zabbix install command. It depends on $OsArch variable
$ZabbixInstallCommand
=
"
`"
$PathZabbix
\bin\
$OsArch
\zabbix_agentd.exe
`"
--config
`"
$ZabbixConf
`"
"
#Installing Zabbix Service
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"
| out-null
}
Catch
{
$ErrorMessage
=
$_
.Exception.Message
$FailedItem
=
$_
.Exception.ItemName
write-host
"Cannot Install Zabbix Service (((
"
write-host
$ErrorMessage
Break
}
{
$ErrorMessage
=
$_
.Exception.Message
$FailedItem
=
$_
.Exception.ItemName
write-host
"Cannot Install Zabbix Service!!!
"
write-host
$ErrorMessage
Break
}
#
Starting zabbix agent
#
Adding firewall rules for Zabbix Agent and Zabbix Server
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 a
gent
#
Starting Zabbix A
gent
Try
{
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
}
{
Start-Service
-name
"Zabbix Agent"
-ErrorAction Stop
}
Catch
{
$ErrorMessage
=
$_
.Exception.Message
$FailedItem
=
$_
.Exception.ItemName
write-host
"Cannot Add Firewall Rules..."
write-host
$ErrorMessage
Break
{
$ErrorMessage
=
$_
.Exception.Message
$FailedItem
=
$_
.Exception.ItemName
write-host
"Cannot Start Zabbix Service. See
$PathZabbix
\log\zabbix_agentd.log
`
for details"
write-host
$ErrorMessage
Break
}
For
(
$i
=
5;
$i
-gt 1;
$i
-
)
{
Write-Progress
-Activity
"
`n
Installation completed! Waiting Zabbix Agent starts..."
`
-SecondsRemaining
$i
Start-Sleep
1
}
Write-host
"Firewall rules for Zabbix Agent added..."
Write-host
"Installation completed!"
\ No newline at end of file
Get-content
$PathZabbix
\log\zabbix_agentd.log
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment