#!/bin/bash
if [ "`grep '192.168.10.2 zabbixproxy.xxxx.com' /etc/hosts`" = "" ];then
echo "192.168.10.2 zabbixproxy.xxxx.com" >> /etc/hosts
fi
#IP=`ip a show dev eth0 scope global |grep "inet" |sed -e 's#.*inet##g' -e 's#/.*##g'`
IP=`ip a |grep 192.168.10. |sed -e 's#.*inet##g' -e 's#/.*##g'`
zabbix_agent_conf(){
cp /etc/zabbix/zabbix_agentd.conf{,.bk}
cat > /etc/zabbix/zabbix_agentd.conf << EOF
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=1
EnableRemoteCommands=1
Server=zabbixproxy.xxxx.com
ServerActive=zabbixproxy.xxxx.com
Hostname=$IP
BufferSize=200
Include=/etc/zabbix/zabbix_agentd.d/*.conf
centos7_zabbix_agent(){
ps -ef|grep zabbix |awk '{print $2}' |xargs kill -9
rpm -ivh /tmp/zabbix-agent-4.0.2-1.el7.x86_64.rpm
zabbix_agent_conf
systemctl enable zabbix-agent && systemctl start zabbix-agent
centos6_zabbix_agent(){
ps -ef|grep zabbix |awk '{print $2}' |xargs kill -9
rpm -ivh /tmp/zabbix-agent-4.0.2-1.el6.x86_64.rpm
zabbix_agent_conf
service zabbix-agent start && chkconfig zabbix-agent on
}
if [ `cat /etc/redhat-release |sed -r 's/.* ([0-9]+)\..*/\1/'` -eq 7 ];then
echo "centos 7"
centos7_zabbix_agent
else
echo "centos6"
centos6_zabbix_agent
fi