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
384d427c
Commit
384d427c
authored
Jun 11, 2018
by
Rinat K. Nugaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some comments
parent
5447d0c6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
39 deletions
+55
-39
zabbix_install.ps1
+55
-39
No files found.
zabbix_install.ps1
View file @
384d427c
...
...
@@ -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!
`n
Please re-run this script with Admin rights!"
Write-Warning
"You do not have Admin rights to run this script!
`n
Please
`
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"
)
{
$
osa
rch
=
'win64'
$
OsA
rch
=
'win64'
}
else
{
$
osa
rch
=
'win32'
$
OsA
rch
=
'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
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