2016-08-03 10:09:49 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-10-03 16:08:57 +02:00
|
|
|
set -o pipefail
|
2018-02-18 21:42:44 +01:00
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
set +e
|
2016-08-04 07:09:11 +02:00
|
|
|
|
2016-08-11 12:55:45 +02:00
|
|
|
# Script trace mode
|
2021-04-12 03:43:41 +02:00
|
|
|
if [ "${DEBUG_MODE,,}" == "true" ]; then
|
2016-08-04 07:09:11 +02:00
|
|
|
set -o xtrace
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
# Default Zabbix server host
|
2019-10-03 16:08:57 +02:00
|
|
|
: ${ZBX_SERVER_HOST:="zabbix-server"}
|
2019-04-12 12:22:41 +02:00
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
# Default directories
|
2016-08-11 12:55:45 +02:00
|
|
|
# User 'zabbix' home directory
|
2016-08-03 10:09:49 +02:00
|
|
|
ZABBIX_USER_HOME_DIR="/var/lib/zabbix"
|
2016-08-11 12:55:45 +02:00
|
|
|
# Configuration files directory
|
2016-08-03 10:09:49 +02:00
|
|
|
ZABBIX_ETC_DIR="/etc/zabbix"
|
|
|
|
|
2018-02-23 22:43:00 +01:00
|
|
|
escape_spec_char() {
|
|
|
|
local var_value=$1
|
|
|
|
|
|
|
|
var_value="${var_value//\\/\\\\}"
|
|
|
|
var_value="${var_value//[$'\n']/}"
|
|
|
|
var_value="${var_value//\//\\/}"
|
|
|
|
var_value="${var_value//./\\.}"
|
|
|
|
var_value="${var_value//\*/\\*}"
|
|
|
|
var_value="${var_value//^/\\^}"
|
|
|
|
var_value="${var_value//\$/\\\$}"
|
|
|
|
var_value="${var_value//\&/\\\&}"
|
|
|
|
var_value="${var_value//\[/\\[}"
|
2018-06-01 05:06:05 +02:00
|
|
|
var_value="${var_value//\]/\\]}"
|
2018-02-23 22:43:00 +01:00
|
|
|
|
2019-07-13 23:50:22 +02:00
|
|
|
echo "$var_value"
|
2018-02-23 22:43:00 +01:00
|
|
|
}
|
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var() {
|
|
|
|
local config_path=$1
|
|
|
|
local var_name=$2
|
|
|
|
local var_value=$3
|
|
|
|
local is_multiple=$4
|
|
|
|
|
2020-06-23 14:42:13 +02:00
|
|
|
local masklist=("TLSPSKIdentity")
|
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
if [ ! -f "$config_path" ]; then
|
|
|
|
echo "**** Configuration file '$config_path' does not exist"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2020-06-23 15:24:22 +02:00
|
|
|
if [[ " ${masklist[@]} " =~ " $var_name " ]] && [ ! -z "$var_value" ]; then
|
2020-06-23 14:42:13 +02:00
|
|
|
echo -n "** Updating '$config_path' parameter \"$var_name\": '****'. Enable DEBUG_MODE to view value ..."
|
|
|
|
else
|
|
|
|
echo -n "** Updating '$config_path' parameter \"$var_name\": '$var_value'..."
|
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
# Remove configuration parameter definition in case of unset parameter value
|
|
|
|
if [ -z "$var_value" ]; then
|
2018-02-20 17:23:18 +01:00
|
|
|
sed -i -e "/^$var_name=/d" "$config_path"
|
2016-08-03 10:09:49 +02:00
|
|
|
echo "removed"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Remove value from configuration parameter in case of double quoted parameter value
|
|
|
|
if [ "$var_value" == '""' ]; then
|
|
|
|
sed -i -e "/^$var_name=/s/=.*/=/" "$config_path"
|
|
|
|
echo "undefined"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Use full path to a file for TLS related configuration parameters
|
2021-11-22 14:32:57 +01:00
|
|
|
if [[ $var_name =~ ^TLS.*File$ ]] && [[ ! $var_value =~ ^/.+$ ]]; then
|
2016-08-03 10:09:49 +02:00
|
|
|
var_value=$ZABBIX_USER_HOME_DIR/enc/$var_value
|
|
|
|
fi
|
|
|
|
|
2020-04-27 22:19:42 +02:00
|
|
|
# Escaping characters in parameter value and name
|
2018-02-23 22:43:00 +01:00
|
|
|
var_value=$(escape_spec_char "$var_value")
|
2020-04-27 22:19:42 +02:00
|
|
|
var_name=$(escape_spec_char "$var_name")
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
if [ "$(grep -E "^$var_name=" $config_path)" ] && [ "$is_multiple" != "true" ]; then
|
|
|
|
sed -i -e "/^$var_name=/s/=.*/=$var_value/" "$config_path"
|
|
|
|
echo "updated"
|
|
|
|
elif [ "$(grep -Ec "^# $var_name=" $config_path)" -gt 1 ]; then
|
|
|
|
sed -i -e "/^[#;] $var_name=$/i\\$var_name=$var_value" "$config_path"
|
|
|
|
echo "added first occurrence"
|
|
|
|
else
|
|
|
|
sed -i -e "/^[#;] $var_name=/s/.*/&\n$var_name=$var_value/" "$config_path"
|
|
|
|
echo "added"
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
update_config_multiple_var() {
|
|
|
|
local config_path=$1
|
|
|
|
local var_name=$2
|
|
|
|
local var_value=$3
|
|
|
|
|
|
|
|
var_value="${var_value%\"}"
|
|
|
|
var_value="${var_value#\"}"
|
|
|
|
|
|
|
|
local IFS=,
|
|
|
|
local OPT_LIST=($var_value)
|
|
|
|
|
|
|
|
for value in "${OPT_LIST[@]}"; do
|
|
|
|
update_config_var $config_path $var_name $value true
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
update_zbx_config() {
|
2019-09-05 19:04:42 +02:00
|
|
|
echo "** Preparing Zabbix proxy configuration file"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-09-05 19:04:42 +02:00
|
|
|
ZBX_CONFIG=$ZABBIX_ETC_DIR/zabbix_proxy.conf
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "ProxyMode" "${ZBX_PROXYMODE}"
|
|
|
|
update_config_var $ZBX_CONFIG "Server" "${ZBX_SERVER_HOST}"
|
|
|
|
if [ -z "${ZBX_HOSTNAME}" ] && [ -n "${ZBX_HOSTNAMEITEM}" ]; then
|
|
|
|
update_config_var $ZBX_CONFIG "Hostname" ""
|
|
|
|
update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}"
|
2016-08-03 10:09:49 +02:00
|
|
|
else
|
2019-10-31 21:10:08 +01:00
|
|
|
update_config_var $ZBX_CONFIG "Hostname" "${ZBX_HOSTNAME:-"zabbix-proxy-sqlite3"}"
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "HostnameItem" "${ZBX_HOSTNAMEITEM}"
|
2016-08-03 10:09:49 +02:00
|
|
|
fi
|
2019-04-11 16:02:48 +02:00
|
|
|
|
2021-02-18 14:22:15 +01:00
|
|
|
update_config_var $ZBX_CONFIG "ListenIP" "${ZBX_LISTENIP}"
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "ListenPort" "${ZBX_LISTENPORT}"
|
2021-11-17 00:43:47 +01:00
|
|
|
update_config_var $ZBX_CONFIG "ListenBacklog" "${ZBX_LISTENBACKLOG}"
|
2019-09-05 19:04:42 +02:00
|
|
|
|
2017-05-11 12:37:37 +02:00
|
|
|
update_config_var $ZBX_CONFIG "SourceIP" "${ZBX_SOURCEIP}"
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "LogType" "console"
|
|
|
|
update_config_var $ZBX_CONFIG "LogFile"
|
|
|
|
update_config_var $ZBX_CONFIG "LogFileSize"
|
|
|
|
update_config_var $ZBX_CONFIG "PidFile"
|
|
|
|
|
2016-08-04 11:18:32 +02:00
|
|
|
update_config_var $ZBX_CONFIG "DebugLevel" "${ZBX_DEBUGLEVEL}"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-10-31 22:29:17 +01:00
|
|
|
update_config_var $ZBX_CONFIG "EnableRemoteCommands" "${ZBX_ENABLEREMOTECOMMANDS}"
|
|
|
|
update_config_var $ZBX_CONFIG "LogRemoteCommands" "${ZBX_LOGREMOTECOMMANDS}"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "DBHost"
|
2021-08-04 17:40:37 +02:00
|
|
|
update_config_var $ZBX_CONFIG "DBName" "/var/lib/zabbix/db_data/${ZBX_HOSTNAME:-"zabbix-proxy-sqlite3"}.sqlite"
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "DBUser"
|
|
|
|
update_config_var $ZBX_CONFIG "DBPort"
|
|
|
|
update_config_var $ZBX_CONFIG "DBPassword"
|
2018-02-18 11:11:27 +01:00
|
|
|
|
2021-11-04 14:42:05 +01:00
|
|
|
if [ -n "${VAULT_TOKEN}" ] && [ -n "${ZBX_VAULTURL}" ]; then
|
2020-10-08 11:05:12 +02:00
|
|
|
update_config_var $ZBX_CONFIG "VaultDBPath" "${ZBX_VAULTDBPATH}"
|
|
|
|
update_config_var $ZBX_CONFIG "VaultURL" "${ZBX_VAULTURL}"
|
|
|
|
else
|
|
|
|
update_config_var $ZBX_CONFIG "VaultDBPath"
|
|
|
|
update_config_var $ZBX_CONFIG "VaultURL"
|
|
|
|
fi
|
|
|
|
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "ProxyLocalBuffer" "${ZBX_PROXYLOCALBUFFER}"
|
|
|
|
update_config_var $ZBX_CONFIG "ProxyOfflineBuffer" "${ZBX_PROXYOFFLINEBUFFER}"
|
|
|
|
update_config_var $ZBX_CONFIG "HeartbeatFrequency" "${ZBX_PROXYHEARTBEATFREQUENCY}"
|
|
|
|
update_config_var $ZBX_CONFIG "ConfigFrequency" "${ZBX_CONFIGFREQUENCY}"
|
|
|
|
update_config_var $ZBX_CONFIG "DataSenderFrequency" "${ZBX_DATASENDERFREQUENCY}"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-04-16 00:11:30 +02:00
|
|
|
update_config_var $ZBX_CONFIG "StatsAllowedIP" "${ZBX_STATSALLOWEDIP}"
|
2019-11-22 06:53:14 +01:00
|
|
|
update_config_var $ZBX_CONFIG "StartPreprocessors" "${ZBX_STARTPREPROCESSORS}"
|
2019-04-16 00:11:30 +02:00
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "StartPollers" "${ZBX_STARTPOLLERS}"
|
|
|
|
update_config_var $ZBX_CONFIG "StartIPMIPollers" "${ZBX_IPMIPOLLERS}"
|
|
|
|
update_config_var $ZBX_CONFIG "StartPollersUnreachable" "${ZBX_STARTPOLLERSUNREACHABLE}"
|
|
|
|
update_config_var $ZBX_CONFIG "StartTrappers" "${ZBX_STARTTRAPPERS}"
|
|
|
|
update_config_var $ZBX_CONFIG "StartPingers" "${ZBX_STARTPINGERS}"
|
|
|
|
update_config_var $ZBX_CONFIG "StartDiscoverers" "${ZBX_STARTDISCOVERERS}"
|
2021-04-27 23:48:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "StartHistoryPollers" "${ZBX_STARTHISTORYPOLLERS}"
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "StartHTTPPollers" "${ZBX_STARTHTTPPOLLERS}"
|
2022-04-15 15:51:26 +02:00
|
|
|
update_config_var $ZBX_CONFIG "StartODBCPollers" "${ZBX_STARTODBCPOLLERS}"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-10-03 16:08:57 +02:00
|
|
|
: ${ZBX_JAVAGATEWAY_ENABLE:="false"}
|
2021-04-12 03:43:41 +02:00
|
|
|
if [ "${ZBX_JAVAGATEWAY_ENABLE,,}" == "true" ]; then
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "JavaGateway" "${ZBX_JAVAGATEWAY:-"zabbix-java-gateway"}"
|
|
|
|
update_config_var $ZBX_CONFIG "JavaGatewayPort" "${ZBX_JAVAGATEWAYPORT}"
|
|
|
|
update_config_var $ZBX_CONFIG "StartJavaPollers" "${ZBX_STARTJAVAPOLLERS:-"5"}"
|
|
|
|
else
|
|
|
|
update_config_var $ZBX_CONFIG "JavaGateway"
|
|
|
|
update_config_var $ZBX_CONFIG "JavaGatewayPort"
|
|
|
|
update_config_var $ZBX_CONFIG "StartJavaPollers"
|
|
|
|
fi
|
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "StartVMwareCollectors" "${ZBX_STARTVMWARECOLLECTORS}"
|
|
|
|
update_config_var $ZBX_CONFIG "VMwareFrequency" "${ZBX_VMWAREFREQUENCY}"
|
|
|
|
update_config_var $ZBX_CONFIG "VMwarePerfFrequency" "${ZBX_VMWAREPERFFREQUENCY}"
|
|
|
|
update_config_var $ZBX_CONFIG "VMwareCacheSize" "${ZBX_VMWARECACHESIZE}"
|
|
|
|
update_config_var $ZBX_CONFIG "VMwareTimeout" "${ZBX_VMWARETIMEOUT}"
|
|
|
|
|
2019-10-03 16:08:57 +02:00
|
|
|
: ${ZBX_ENABLE_SNMP_TRAPS:="false"}
|
2021-04-12 03:43:41 +02:00
|
|
|
if [ "${ZBX_ENABLE_SNMP_TRAPS,,}" == "true" ]; then
|
2016-08-03 14:23:39 +02:00
|
|
|
update_config_var $ZBX_CONFIG "SNMPTrapperFile" "${ZABBIX_USER_HOME_DIR}/snmptraps/snmptraps.log"
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "StartSNMPTrapper" "1"
|
|
|
|
else
|
|
|
|
update_config_var $ZBX_CONFIG "SNMPTrapperFile"
|
|
|
|
update_config_var $ZBX_CONFIG "StartSNMPTrapper"
|
|
|
|
fi
|
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "HousekeepingFrequency" "${ZBX_HOUSEKEEPINGFREQUENCY}"
|
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "CacheSize" "${ZBX_CACHESIZE}"
|
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "StartDBSyncers" "${ZBX_STARTDBSYNCERS}"
|
|
|
|
update_config_var $ZBX_CONFIG "HistoryCacheSize" "${ZBX_HISTORYCACHESIZE}"
|
|
|
|
update_config_var $ZBX_CONFIG "HistoryIndexCacheSize" "${ZBX_HISTORYINDEXCACHESIZE}"
|
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "Timeout" "${ZBX_TIMEOUT}"
|
2021-08-04 13:37:59 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TrapperTimeout" "${ZBX_TRAPPERTIMEOUT}"
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "UnreachablePeriod" "${ZBX_UNREACHABLEPERIOD}"
|
|
|
|
update_config_var $ZBX_CONFIG "UnavailableDelay" "${ZBX_UNAVAILABLEDELAY}"
|
|
|
|
update_config_var $ZBX_CONFIG "UnreachableDelay" "${ZBX_UNREACHABLEDELAY}"
|
2016-10-24 13:41:00 +02:00
|
|
|
|
2016-10-24 15:11:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "AlertScriptsPath" "/usr/lib/zabbix/alertscripts"
|
|
|
|
update_config_var $ZBX_CONFIG "ExternalScripts" "/usr/lib/zabbix/externalscripts"
|
|
|
|
|
2019-11-22 05:14:01 +01:00
|
|
|
update_config_var $ZBX_CONFIG "FpingLocation" "/usr/sbin/fping"
|
|
|
|
update_config_var $ZBX_CONFIG "Fping6Location"
|
2016-10-24 13:41:00 +02:00
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "SSHKeyLocation" "$ZABBIX_USER_HOME_DIR/ssh_keys"
|
|
|
|
update_config_var $ZBX_CONFIG "LogSlowQueries" "${ZBX_LOGSLOWQUERIES}"
|
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "SSLCertLocation" "$ZABBIX_USER_HOME_DIR/ssl/certs/"
|
|
|
|
update_config_var $ZBX_CONFIG "SSLKeyLocation" "$ZABBIX_USER_HOME_DIR/ssl/keys/"
|
|
|
|
update_config_var $ZBX_CONFIG "SSLCALocation" "$ZABBIX_USER_HOME_DIR/ssl/ssl_ca/"
|
|
|
|
update_config_var $ZBX_CONFIG "LoadModulePath" "$ZABBIX_USER_HOME_DIR/modules/"
|
|
|
|
update_config_multiple_var $ZBX_CONFIG "LoadModule" "${ZBX_LOADMODULE}"
|
|
|
|
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TLSConnect" "${ZBX_TLSCONNECT}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSAccept" "${ZBX_TLSACCEPT}"
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TLSCAFile" "${ZBX_TLSCAFILE}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCRLFile" "${ZBX_TLSCRLFILE}"
|
2019-09-05 19:04:42 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TLSServerCertIssuer" "${ZBX_TLSSERVERCERTISSUER}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSServerCertSubject" "${ZBX_TLSSERVERCERTSUBJECT}"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCertFile" "${ZBX_TLSCERTFILE}"
|
2020-08-05 22:58:07 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TLSCipherAll" "${ZBX_TLSCIPHERALL}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCipherAll13" "${ZBX_TLSCIPHERALL13}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCipherCert" "${ZBX_TLSCIPHERCERT}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCipherCert13" "${ZBX_TLSCIPHERCERT13}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCipherPSK" "${ZBX_TLSCIPHERPSK}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSCipherPSK13" "${ZBX_TLSCIPHERPSK13}"
|
2016-08-03 10:09:49 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TLSKeyFile" "${ZBX_TLSKEYFILE}"
|
|
|
|
|
2020-05-12 23:41:26 +02:00
|
|
|
update_config_var $ZBX_CONFIG "TLSPSKIdentity" "${ZBX_TLSPSKIDENTITY}"
|
|
|
|
update_config_var $ZBX_CONFIG "TLSPSKFile" "${ZBX_TLSPSKFILE}"
|
|
|
|
|
2019-10-03 19:52:14 +02:00
|
|
|
if [ "$(id -u)" != '0' ]; then
|
|
|
|
update_config_var $ZBX_CONFIG "User" "$(whoami)"
|
2016-08-03 10:09:49 +02:00
|
|
|
else
|
2019-10-03 19:52:14 +02:00
|
|
|
update_config_var $ZBX_CONFIG "AllowRoot" "1"
|
2016-08-03 10:09:49 +02:00
|
|
|
fi
|
|
|
|
}
|
2016-08-11 12:55:45 +02:00
|
|
|
|
2016-08-03 10:09:49 +02:00
|
|
|
prepare_proxy() {
|
|
|
|
echo "Preparing Zabbix proxy"
|
|
|
|
|
2019-09-05 19:04:42 +02:00
|
|
|
update_zbx_config
|
2016-08-03 10:09:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
|
2019-10-03 17:16:08 +02:00
|
|
|
if [ "${1#-}" != "$1" ]; then
|
|
|
|
set -- /usr/sbin/zabbix_proxy "$@"
|
2016-08-03 10:09:49 +02:00
|
|
|
fi
|
|
|
|
|
2019-10-03 17:16:08 +02:00
|
|
|
if [ "$1" == '/usr/sbin/zabbix_proxy' ]; then
|
|
|
|
prepare_proxy
|
2018-02-22 21:07:15 +01:00
|
|
|
fi
|
2016-08-03 10:09:49 +02:00
|
|
|
|
2019-10-03 16:08:57 +02:00
|
|
|
exec "$@"
|
2016-08-03 10:09:49 +02:00
|
|
|
|
|
|
|
#################################################
|