forked from berlin493/github4shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_nrpe.sh
105 lines (79 loc) · 2.45 KB
/
install_nrpe.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
#!/bin/bash
#SET ENV
YUM_SERVER='yum.server.local'
PACKAGE_URL="http://${YUM_SERVER}/tools"
#SET TEMP PATH
TEMP_PATH='/usr/local/src'
#SET TEMP DIR
INSTALL_DIR="install_$$"
INSTALL_PATH="${TEMP_PATH}/${INSTALL_DIR}"
#SET PACKAGE
YUM_PACKAGE='gcc glibc glibc-common make cmake gcc-c++ xinetd openssl-devel'
APT_PACKAGE='build-essential libssl-dev xinetd'
#SET EXIT STATUS AND COMMAND
trap "exit 1" HUP INT PIPE QUIT TERM
trap "rm -rf ${INSTALL_PATH}" EXIT
download_func () {
local func_shell='func4install.sh'
local func_url="http://${YUM_SERVER}/shell/${func_shell}"
local tmp_file="/tmp/${func_shell}"
wget -q ${func_url} -O ${tmp_file} && source ${tmp_file} ||\
eval "echo Can not access ${func_url}! 1>&2;exit 1"
rm -f ${tmp_file}
}
turn_off_syslog(){
local nrpe_config='/etc/xinetd.d/nrpe'
if [ -f "${nrpe_config}" ];then
sed -r -i 's/log_on_failure.*$/log_type = file \/dev\/null/' ${nrpe_config}
fi
}
config_xinetd () {
if [ -f /etc/services ];then
grep '5666' /etc/services >/dev/null 2>&1 || echo "nrpe 5666/tcp #NRPE" >> /etc/services
/etc/init.d/xinetd restart
sleep 1
${CONFIG_CMD} xinetd on
fi
}
backup_nrpe_config () {
local nrpe_config='/usr/local/nagios/etc/nrpe.cfg'
if [ -f "${nrpe_config}" ];then
mv ${nrpe_config} ${nrpe_config}.bak`date -d now +"%F_%H-%M-%S"`
fi
}
main () {
#DOWNLOAD FUNC FOR INSTALL
download_func
#CHECK SYSTEM AND CREATE TEMP DIR
check_system
set_install_cmd 'net'
platform=`check_platform`
#FOR debian7
[ "${platform}" = 'x64' -a "${SYSTEM}" = 'debian7' ] &&\
NRPE_PARA='--with-ssl-lib=/usr/lib/x86_64-linux-gnu' ||\
NRPE_PARA='--with-ssl-lib=/usr/lib/i386-linux-gnu'
[ "${SYSTEM}" == 'debian7' ] || NRPE_PARA=''
#Backup NRPE config
backup_nrpe_config
#Created user
create_user "nagios" "bash"
#Install nrpe-2.15.tar.gz
PACKAGE='nrpe-2.15.tar.gz'
create_tmp_dir
download_and_check
run_cmds "./configure ${NRPE_PARA}" 'make all' 'make install-plugin' 'make install-daemon' 'make install-daemon-config' 'make install-xinetd'
#ADD NRPE CMD
nrpe_conf='/usr/local/nagios/etc/nrpe.cfg'
if [ -f "${nrpe_conf}" ];then
grep 'check_swap' ${nrpe_conf} ||\
echo 'command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%' >> ${nrpe_conf}
grep 'check_disk_root' ${nrpe_conf} ||\
echo 'command[check_disk_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /' >> ${nrpe_conf}
fi
#CONFIG NRPE
turn_off_syslog
config_xinetd
#EXIT AND CLEAR TEMP DIR
exit_and_clear
}
main