zabbix_agent 设置脚本使用

Posted quemengqio

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix_agent 设置脚本使用相关的知识,希望对你有一定的参考价值。

zabbix_agent.conf

SourceIP=zabbix_agentIP
Hostname=zabbix_agentIP
Server=127.0.0.1
ServerActive=127.0.0.1
EnableRemoteCommands=1
LogRemoteCommands=1
HostMetadataItem=system.uname
Timeout=30
AllowRoot=0
User=bestpay
Include=/tools/zabbix_agent/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1

disk_sh

#!/bin/bash

diskarray=(`cat /proc/diskstats |grep -E "sd[a-z][0-9]*|xvd[a-z][0-9]*|vd[a-z][0-9]*"|awk ‘{print $3}‘|sort|uniq 2>/dev/null`)
length=${#diskarray[@]}
printf "{ "
printf ‘ ‘""data":["
for ((i=0;i<$length;i++))
do
printf ‘ {‘
printf ""{#DISK_NAME}":"${diskarray[$i]}"}"
if [ $i -lt $[$length-1] ];then
printf ‘,‘
fi
done
printf " ] "
printf "} "

 

zabbix_agent 修改

#/bin/bash
for line in $(cat ip_list)
do
function ssh_command() {
expect -c "
set timeout 2
spawn ssh root@$line
expect {
"yes/no)? " { send "yes "; exp_continue }
"word: " { send "$PASS " }
}
expect "# "
send "$1 "
expect "$# "
send "exit "
expect eof
"
}
ssh -tt $line<<EOF
sed -i -e ‘s/Server=127.0.0.1/Server=zabbix_serverIP/g‘ /tools/zabbix_agent/etc/zabbix_agentd.conf >>/dev/null
sed -i -e ‘s/ServerActive=127.0.0.1/ServerActive=zabbix_serverIP/g‘ /tools/zabbix_agent/etc/zabbix_agentd.conf >> /dev/null
sed -i ‘s/SourceIP=/&$line/g‘ /tools/zabbix_agent/etc/zabbix_agentd.conf >> /dev/null
sed -i ‘s/Hostname=/&$line/g‘ /tools/zabbix_agent/etc/zabbix_agentd.conf >> /dev/null
bash /etc/init.d/zabbix-agent start >> /dev/null
bash chkconfig --add zabbix-agent /dev/null
bash chkconfig zabbix-agent on >> /dev/null
echo "success $line "
exit
EOF

echo $line
done

以上是关于zabbix_agent 设置脚本使用的主要内容,如果未能解决你的问题,请参考以下文章

使用zabbix_agent监控第一台linux服务器

zabbix_agent自动发现服务端口

《zabbix_agent客户端的添加》

zabbix_agent自动发现服务端口

打rpm包步骤

Zabbix邮件告警