-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
deploy_zabbix.sh
executable file
·97 lines (92 loc) · 2.92 KB
/
deploy_zabbix.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
#!/usr/bin/env ksh
SOURCE_DIR=$(dirname $0)
ZABBIX_DIR=/etc/zabbix
usage() {
echo "Usage: ${APP_NAME%.*} [Options]"
echo ""
echo "Options:"
echo " -F Force configuration overwrite."
echo " -H Displays this help message."
echo " -P Installation prefix (SCRIPT_DIR)."
echo " -Z Zabbix agent include files directory (ZABBIX_INC)."
echo " -o Configuration key ORACLE_OSID."
echo " -p Configuration key ORACLE_PASS."
echo " -u Configuration key ORACLE_USER."
echo ""
echo "Please send any bug reports to https://github.com/sergiotocalini/zabora/issues"
exit 1
}
while getopts ":o:p:u:P:Z:FH" OPTION; do
case ${OPTION} in
F)
FORCE=true
;;
H)
usage
;;
P)
SCRIPT_DIR="${OPTARG}"
if [[ ! "${SCRIPT_DIR}" =~ .*zabora ]]; then
SCRIPT_DIR="${SCRIPT_DIR}/zabora"
fi
;;
Z)
ZABBIX_INC="${OPTARG}"
;;
o)
ORACLE_OSID="${OPTARG}"
;;
p)
ORACLE_PASS="${OPTARG}"
;;
u)
ORACLE_USER="${OPTARG}"
;;
\?)
exit 1
;;
esac
done
[ -n "${SCRIPT_DIR}" ] || SCRIPT_DIR="${ZABBIX_DIR}/scripts/agentd/zabora"
[ -n "${ZABBIX_INC}" ] || ZABBIX_INC="${ZABBIX_DIR}/zabbix_agentd.d"
[ -n "${ORACLE_USER}" ] || ORACLE_USER="monitor"
[ -n "${ORACLE_PASS}" ] || ORACLE_PASS="xxxxxxx"
[ -n "${ORACLE_OSID}" ] || ORACLE_OSID="oracle"
# Creating necessary directories
mkdir -p "${SCRIPT_DIR}" "${ZABBIX_INC}" 2>/dev/null
# Copying the main script and dependencies
cp -rpv "${SOURCE_DIR}/zabora/zabora.sh" "${SCRIPT_DIR}/zabora.sh"
cp -rpv "${SOURCE_DIR}/zabora/sql" "${SCRIPT_DIR}/"
# Provisioning script configuration
SCRIPT_CFG="${SCRIPT_DIR}/zabora.conf"
cp -rpv "${SOURCE_DIR}/zabora/zabora.conf.example" "${SCRIPT_CFG}.new"
# Adding script configuration values
regex_cfg[0]="s|ORACLE_USER=.*|ORACLE_USER=\"${ORACLE_USER}\"|g"
regex_cfg[1]="s|ORACLE_PASS=.*|ORACLE_PASS=\"${ORACLE_PASS}\"|g"
for index in ${!regex_cfg[*]}; do
sed -i'' -e "${regex_cfg[${index}]}" "${SCRIPT_CFG}.new"
done
# Checking if the new configuration exist
if [[ -f "${SCRIPT_CFG}" && ${FORCE:-false} == false ]]; then
state=$(cmp --silent "${SCRIPT_CFG}" "${SCRIPT_CFG}.new")
if [[ ${?} == 0 ]]; then
rm "${SCRIPT_CFG}.new" 2>/dev/null
fi
else
mv "${SCRIPT_CFG}.new" "${SCRIPT_CFG}" 2>/dev/null
fi
# Provisioning zabbix_agent configuration
SCRIPT_ZBX="${ZABBIX_INC}/zabora.conf"
cp -rpv "${SOURCE_DIR}/zabora/zabbix_agentd.conf" "${SCRIPT_ZBX}.new"
regex_inc[0]="s|{PREFIX}|${SCRIPT_DIR}|g"
for index in ${!regex_inc[*]}; do
sed -i'' -e "${regex_inc[${index}]}" "${SCRIPT_ZBX}.new"
done
if [[ -f "${SCRIPT_ZBX}" ]]; then
state=$(cmp --silent "${SCRIPT_ZBX}" "${SCRIPT_ZBX}.new")
if [[ ${?} == 0 ]]; then
rm "${SCRIPT_ZBX}.new" 2>/dev/null
fi
else
mv "${SCRIPT_ZBX}.new" "${SCRIPT_ZBX}" 2>/dev/null
fi