-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvx_zbxproxy.sh
303 lines (237 loc) · 7.8 KB
/
vx_zbxproxy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#! /bin/bash
#set -x
# ****************************************************************************
# *
# * Creation: (c) 2004-2022 Cybionet - Ugly Codes Division
# *
# * File: vx_zbxproxy.sh
# * Version: 0.1.1d
# *
# * Comment: Zabbix Proxy LTS installation script under Ubuntu LTS Server.
# *
# * Creation: October 03, 2014
# * Change: January 30, 2022
# *
# ****************************************************************************
#############################################################################################
# ## CUSTOM VARIABLES
# ## Force configuration of the script.
# ## Value: enabled (true), disabled (false).
isConfigured='false'
# ## Do you want to install the distribution Zabbix Proxy [0=Zabbix Repo (recommended), 1=Distribution Repo].
installDefault=0
# ## Zabbix Proxy version.
# ## 3.x: 3.0, 3.4 (Obsolete)
# ## 4.x: 4.0, 4.5
# ## 5.x: 5.0, 5.5
# ## 3.0, 4.0 and 5.0 are LTS version.
zbxVers='5.0'
# ## (Without the trailing slash).
scriptLocation='/opt/zabbix'
#############################################################################################
# ## VARIABLES
declare -r isConfigured
declare -ir installDefault
declare -r zbxVers
declare -r scriptLocation
# ## Distribution: ubuntu, debian, raspbian.
osDist=$(lsb_release -i | awk '{print $3}')
declare -r osDist
# ## Supported version.
# ## Ubuntu: focal, bionic, trusty.
# ## Debian: bulleye, buster, jessie, stretch.
# ## Raspbian: buster, stretch.
osVers=$(lsb_release -c | awk '{print $2}')
declare -r osVers
#############################################################################################
# ## VERIFICATION
# ## Check if the script is configured.
if [ "${isConfigured}" == 'false' ] ; then
echo -n -e '\e[38;5;208mWARNING: Customize the settings to match your environment. Then set the "isConfigured" variable to "true".\n\e[0m'
exit 0
fi
# ## Check if the script are running under root user.
if [ "${EUID}" -ne 0 ]; then
echo -n -e "\n\n\n\e[38;5;208mWARNING:This script must be run with sudo or as root.\e[0m"
exit 0
fi
# ## Last chance - Ask before execution.
echo -n -e "\n\e[38;5;208mWARNING:\e[0m You are preparing to install the Zabbix Proxy service. Press 'y' to continue, or any other key to exit: "
read -r ANSWER
if [[ "${ANSWER}" != 'y' && "${ANSWER}" != 'Y' ]]; then
echo 'Have a nice day!'
exit 0
fi
# ## Don't uses distribution repo message.
if [ ${installDefault} -eq 1 ]; then
echo -e "Do you realy want to install the distribution Zabbix Proxy (Y/N) [default=N]?"
echo -e "If not, change \"installDefault\" parameter to '0' in this script."
read -r INSTALL
if [[ "${INSTALL}" != 'n' && "${INSTALL}" != 'N' ]]; then
echo 'Good choice!'
exit 0
fi
fi
#############################################################################################
# ## FUNCTIONS
# ##############
# ## DEPENDANCIES
# ## Installation basic packages required for internal scripts in Zabbix.
function zxScripts {
# ## Script: Ping
apt-get -y install fping
# ## Script: Traceroute
apt-get -y install traceroute
# ## Script: Detect operating system
apt-get -y install nmap
echo "zabbix ALL=(ALL) NOPASSWD:/usr/bin/nmap" >> /etc/sudoers.d/zabbix
}
# ## Added Zabbix repository.
function zxRepo {
if [ ! -f '/etc/apt/sources.list.d/zabbix.list' ]; then
echo -e "# ## Zabbix ${zbxVers} Repository" > /etc/apt/sources.list.d/zabbix.list
echo -e "deb https://repo.zabbix.com/zabbix/${zbxVers}/${osDist,,}/ ${osVers} main contrib non-free" >> /etc/apt/sources.list.d/zabbix.list
echo -e "deb-src https://repo.zabbix.com/zabbix/${zbxVers}/${osDist,,}/ ${osVers} main contrib non-free" >> /etc/apt/sources.list.d/zabbix.list
apt-key adv --keyserver hkps://keyserver.ubuntu.com --recv-keys 082AB56BA14FE591
apt-get update
else
echo -e 'INFO: Source file already exist!'
fi
}
# ##############
# ## SUPPORTED AGENT
# ## SSH support for SSH Agent (--with-ssh2).
function sshAgentSupport {
apt-get -y install openssh-server
apt-get -y install libssh2-1-dev
apt-get -y install libcurl4-openssl-dev
}
# ## SNMP support for SNMP Agent (--with-net-snmp).
function snmpAgentSupport {
apt-get -y install libsnmp-base libsnmp35
apt-get -y install snmp-mibs-downloader # ## Not supported on Debian system.
}
# ## SNMP Trap support for SNMP Trap Agent (--with-net-snmp).
function snmpTrapAgentSupport {
apt-get -y install snmptt
}
# ## Openipmi support for IPMI Agent (--with-openipmi).
function openipmiAgentSupport {
apt-get -y install libopenipmi0
}
# ## Java support for JMX Agent (--with-java).
function jmxAgentSupport {
#apt-get -y install default-jdk # ## By default openjdk-11-jdk
apt-get -y install openjdk-17-jdk # ## openjdk-8-jdk on Debian.
}
# ## ODBC support for Database Agent (--with--unixodbc).
function odbcAgentSupport {
apt-get -y install unixodbc unixodbc-dev
apt-get -y install libmyodbc
apt-get -y install odbc-postgresql
apt-get -y install tdsodbc
apt-get -y install unixodbc-bin
}
# ##############
# ## PROXY
# ## Installing the Zabbix Proxy with SQLite3 support.
function zxProxy {
apt-get -y install zabbix-proxy-sqlite3
systemctl enable zabbix-proxy.service
}
function zxDatabase {
# ## Paclkage supposed to be already installed.
apt-get -y install sqlite3
if [ -f '/usr/share/doc/zabbix-proxy-sqlite3/schema.sql.gz' ]; then
zcat /usr/share/doc/zabbix-proxy-sqlite3/schema.sql.gz | sqlite3 /etc/zabbix/zabbix.db
else
echo -e "\n\e[31mERROR: The source file to generate the database was not found.\e[0m\n"
fi
}
# ## Download optimal Zabbix Proxy configuration.
function zxProxyConfig {
if [ -f '/etc/zabbix/zabbix_proxy.conf' ]; then
mv /etc/zabbix/zabbix_proxy.conf /etc/zabbix/zabbix_proxy.conf.ori
fi
if [ "${installDefault}" -eq 0 ]; then
cp configs/zabbix_proxy.conf /etc/zabbix/
else
cp configs/zabbix_proxy_notls.conf /etc/zabbix/zabbix_proxy.conf
fi
}
# ## Generate the shared key (64-byte PSK).
function zxProxyTls {
if [ "${installDefault}" -eq 0 ]; then
echo -e 'Generation Zabbix Proxy 64 bit Pre-Shared Key (PSK).'
openssl rand -hex 64 > /etc/zabbix/zabbix_proxy.psk
else
echo -e 'Zabbix Proxy from Ubuntu repository do not support TLS.'
fi
}
# ## Creation of additional directories required.
function zxDir {
if [ ! -d "${scriptLocation}" ]; then
mkdir -p "${scriptLocation}"/{externalscripts,alertscripts}
chown -R zabbix:zabbix "${scriptLocation}"/
fi
if [ ! -d '/var/run/zabbix/' ]; then
mkdir -p /var/run/zabbix/
chown -R zabbix:zabbix /var/run/zabbix/
fi
if [ ! -d '/var/log/zabbix-proxy/' ]; then
mkdir -p /var/log/zabbix/
chown -R zabbix:zabbix /var/log/zabbix/
fi
}
# ##############
# ## EXTRA
# ## Installing the Zabbix Agent.
function zxAgent {
apt-get install -y zabbix-agent
}
# ## Installing Zabbix tools.
function zxTools {
apt-get install -y zabbix-get
apt-get install -y zabbix-sender
}
# ## Installation of the Java gateway.
function zxJavaGw {
apt-get install -y zabbix-java-gateway
}
#############################################################################################
# ## EXECUTION
# ## Installation basic packages required for internal scripts in Zabbix.
zxScripts
# ## Set Zabbix repository for installation.
if [ "${installDefault}" -eq 0 ]; then
# ## Added Zabbix repository as per setting.
zxRepo
zxProxy
else
# ## Installing Zabbix Proxy.
zxProxy
fi
# ## Generate the shared key (64 byte PSK).
zxProxyTls
# ## Copy of the ready-to-use simplified configuration file.
zxProxyConfig
# ## Creation of the necessary directories for Zabbix.
zxDir
# ## Installing of all Agent services for the Proxy.
sshAgentSupport
snmpAgentSupport
snmpTrapAgentSupport
openipmiAgentSupport
odbcAgentSupport
jmxAgentSupport
# ## Populate the database.
zxDatabase
# ## Installing Zabbix Agent.
#zxAgent
# ## Installing Java Gateway.
#zxJavaGw
# ## Installing Zabbix tools.
#zxTools
# ## Exit.
exit 0
# ## END