-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy_zabbix.sh
executable file
·90 lines (81 loc) · 2.56 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
#!/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 " -u Configuration key LIBVIRT_URI."
echo ""
echo "Please send any bug reports to https://github.com/sergiotocalini/virbix/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}" =~ .*virbix ]]; then
SCRIPT_DIR="${SCRIPT_DIR}/virbix"
fi
;;
Z)
ZABBIX_INC="${OPTARG}"
;;
u)
LIBVIRT_URI="${OPTARG}"
;;
\?)
exit 1
;;
esac
done
[ -n "${SCRIPT_DIR}" ] || SCRIPT_DIR="${ZABBIX_DIR}/scripts/agentd/virbix"
[ -n "${ZABBIX_INC}" ] || ZABBIX_INC="${ZABBIX_DIR}/zabbix_agentd.d"
[ -n "${LIBVIRT_URI}" ] || LIBVIRT_URI="qemu:///system"
# Creating necessary directories
mkdir -p "${SCRIPT_DIR}" "${ZABBIX_INC}" 2>/dev/null
# Copying the main script and dependencies
cp -rpv "${SOURCE_DIR}/virbix/virbix.sh" "${SCRIPT_DIR}/virbix.sh"
cp -rpv "${SOURCE_DIR}/virbix/scripts" "${SCRIPT_DIR}/"
# Provisioning script configuration
SCRIPT_CFG="${SCRIPT_DIR}/virbix.conf"
cp -rpv "${SOURCE_DIR}/virbix/virbix.conf.example" "${SCRIPT_CFG}.new"
# Adding script configuration values
regex_cfg[0]="s|LIBVIRT_DEFAULT_URI=.*|LIBVIRT_DEFAULT_URI=\"${LIBVIRT_URI}\"|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}/virbix.conf"
cp -rpv "${SOURCE_DIR}/virbix/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