#! /bin/bash
# zabbix server address
zabbix='10.10.238.110'
# repo address
REPO='10.10.238.114:4507'
if [ -f /etc/yum.repos.d/sdata.repo ];then
echo 'no operation'
else
# check os version
osmaster=`cat /etc/redhat-release |awk -F '.' '{print $1}' |awk '{print $NF}'`
if [ $osmaster -eq 5 ];then
# get repo config
curl http://$REPO/repo/sdata5.repo -o /etc/yum.repos.d/sdata.repo
# sudo file config
echo '#includedir /etc/sudoers.d' >> /etc/sudoers
else
# get repo config
curl http://$REPO/repo/sdata.repo -o /etc/yum.repos.d/sdata.repo
fi
# install zabbix agent
yum --disablerepo=* --enablerepo=sdata -y install zabbix-agent
# check install status
pkg=`rpm -qa zabbix-agent| wc -l`
if [ $pkg -ge 1 ];then
echo get zabbix config
curl http://$REPO/repo/zabbix_config.tar.gz -o /tmp/zabbix_config.tar.gz
# config
tar xf /tmp/zabbix_config.tar.gz -C /
#
sed -i 's/HOSTNAME/'`hostname`'/g' /etc/sdata/zabbix/zabbix_agentd.conf
sed -i 's/SERVER/'$zabbix'/g' /etc/sdata/zabbix/zabbix_agentd.conf
chown sdata: -R /etc/sdata
if [ $osmaster -eq 7 ];then
systemctl enable zabbix-agent
systemctl start zabbix-agent
else
service zabbix-agent start
chkconfig --add zabbix-agent
chkconfig zabbix-agent on
fi
rm -f /tmp/zabbix_config.tar.gz
rm -f /tmp/install.sh
else
echo 'zabbix-agent install failed'
fi
fi