# 下载地址
wget https://tool-box.oss-cn-hangzhou.aliyuncs.com/shell/monitor_client.sh
#!/bin/bash
function omsa_install
{
# install omsa (DELL 硬件监控)
echo "#####开始安装OMSA####"
echo "根据网络情况,此过程需要话比较长的时间"
wget -q -O - http://linux.dell.com/repo/hardware/latest/bootstrap.cgi | bash
yum install -y srvadmin-base srvadmin-storageservices
if [ $? != 0 ];then
echo "####安装失败,重试一次####"
yum install -y srvadmin-base srvadmin-storageservices
fi
if [ $? == 0 ];then
echo "####启动OMSA 并加入开机启动####"
cp /opt/dell/srvadmin/sbin/omreport /usr/bin
/opt/dell/srvadmin/sbin/srvadmin-services.sh start
echo "/opt/dell/srvadmin/sbin/srvadmin-services.sh start" >> /etc/rc.local
echo "####OMSA 安装完成#####"
fi
}
function nagios_plugin_install
{
echo "####开始安装nagios插件####"
mkdir -p /fjyl/Tools
cd /fjyl/Tools
wget https://tool-box.oss-cn-hangzhou.aliyuncs.com/nagios-plugins-2.3.1.tar.gz
wget https://tool-box.oss-cn-hangzhou.aliyuncs.com/nrpe-2.12.tar.gz
tar zxvf nagios-plugins-2.3.1.tar.gz
cd nagios-plugins-2.3.1
./configure --prefix=/fjyl/local/nagios
make && make install
mkdir -p /fjyl/local/nagios/bin
mkdir -p /fjyl/local/nagios/etc
cd ..
groupadd nagios
useradd -s /sbin/nologin -M -g nagios nagios
cd /fjyl/Tools
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
yum -y install openssl-devel
./configure
make
cp -a src/nrpe /fjyl/local/nagios/bin/
cp -a src/check_nrpe /fjyl/local/nagios/libexec
cd /fjyl/local/nagios/etc
touch nrpe.cfg
cat >> nrpe.cfg <<EOF
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=1.1.1.1,2.2.2.2
dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/fjyl/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/fjyl/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/fjyl/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/fjyl/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/fjyl/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]= /fjyl/local/nagios/libexec/check_swap -w 20 -c 10
command[check_openmanage]=/fjyl/local/nagios/libexec/check_openmanage -b ctrl_fw=all/pdisk_cert=all/bat=all/dimm=3 -t 60
command[check_disk]=/fjyl/local/nagios/libexec/check_disk -w 20% -c 10%
command[check_mem]=/fjyl/local/nagios/libexec/check_mem -w 80 -c 90 -W 40 -C 60
EOF
}
function check_openmanage_install
{
echo "####开始安装check_openmanage####"
cd /fjyl/Tools
mkdir -p /fjyl/local/nagios/libexec/
wget https://tool-box.oss-cn-hangzhou.aliyuncs.com/check_openmanage-3.7.12.tar.gz
tar zxvf check_openmanage-3.7.12.tar.gz
cd check_openmanage-3.7.12
./install.sh << EOF
/fjyl/local/nagios/libexec/
EOF
echo 'export PATH=$PATH://opt/dell/srvadmin/bin' >> /root/.bashrc
}
function check_mem_install
{
echo "#### 开始安装check_mem####"
cd /fjyl/local/nagios/libexec/
wget http://tool-box.oss-cn-hangzhou.aliyuncs.com/check_mem
chmod +x check_mem
}
function snmpd_install
{
echo "####开始安装snmpd服务####"
yum -y install net-snmp net-snmp-utils net-snmp-libs
sed -i 's/com2sec notConfigUser default public/com2sec notConfigUser default ylwl..pw/g ' /etc/snmp/snmpd.conf
systemctl restart snmpd
systemctl enable snmpd
}
function main
{
# 判断是否为虚拟机
num=`dmidecode -s system-product-name|grep Virtual|wc -l`
if [ $num == 1 ];then # 虚拟机
nagios_plugin_install
check_mem_install
snmpd_install
else # 物理机
omsa_install
nagios_plugin_install
check_openmanage_install
check_mem_install
snmpd_install
fi
/fjyl/local/nagios/bin/nrpe -c /fjyl/local/nagios/etc/nrpe.cfg -d
echo "/fjyl/local/nagios/bin/nrpe -c /fjyl/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
}
main