标签:zabbix
一、配置脚本,将脚本分发到各个minion端1.1.脚本内容
vim discover_port.sh #!/bin/bash portarray=(`sudo netstat -tnlp|egrep -i "$1"|awk {'print $4'}|awk -F':' '{if ($NF~/^[0-9]*$/) print $NF}'|sort|uniq`) length=${#portarray[@]} printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$length;i++)) do printf '\n\t\t{' printf "\"{#TCP_PORT}\":\"${portarray[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n"
1.2.本地测试脚本
# /bin/bash /usr/local/zabbix-agent/script/discover_port.sh { "data":[ {"{#TCP_PORT}":"10050"}, {"{#TCP_PORT}":"22"}, {"{#TCP_PORT}":"25"}, {"{#TCP_PORT}":"443"}, {"{#TCP_PORT}":"80"}, {"{#TCP_PORT}":"9008"}, {"{#TCP_PORT}":"9012"}, {"{#TCP_PORT}":"9083"}, {"{#TCP_PORT}":"9085"}, {"{#TCP_PORT}":"9088"}, {"{#TCP_PORT}":"9089"} ] }
二、修改zabbix客户端配置文件,增加参数
2.1.修改配置文件,增加参数
# vim /usr/local/zabbix-agent/etc/zabbix_agentd.conf #增加如下 UserParameter=tcpportlisten,/bin/bash /usr/local/zabbix-agent/script/discover_port.sh "$1"
2.2.重启zabbix客户端
# /etc/init.d/zabbix_agentd restart Shutting down zabbix_agentd: [ OK ] Starting zabbix_agentd: [ OK ]
三、服务端测试连通
3.1.测试通信
# /usr/local/zabbix/bin/zabbix_get -s 10.27.182.76 -k tcpportlisten { "data":[ {"{#TCP_PORT}":"10050"}, {"{#TCP_PORT}":"22"}, {"{#TCP_PORT}":"25"}, {"{#TCP_PORT}":"443"}, {"{#TCP_PORT}":"80"}, {"{#TCP_PORT}":"9008"}, {"{#TCP_PORT}":"9012"}, {"{#TCP_PORT}":"9083"}, {"{#TCP_PORT}":"9085"}, {"{#TCP_PORT}":"9088"}, {"{#TCP_PORT}":"9089"} ] }
四、添加自动发现规则
4.1.创建发现规则
4.2.配置发现规则名称
4.3.配置检测规则
4.4.配置触发器
五、错误处理
5.1.服务器测试与客户端通信时:
zabbix sudo: no tty present and no askpass program specified
解决:
zabbix客户端修改zabbix_agentd.conf:
AllowRoot=1
重启客户端:
# /etc/init.d/zabbix_agentd restart
脚本添加权限及修改属主:
# chown zabbix. discover_port.sh # chmod +x discover_port.sh
5.2.测试通信报错2:
zabbix sudo: sorry, you must have a tty to run sudo
解决:
vi /etc/sudoers (最好用visudo命令) 注释掉 Default requiretty 一行 #Default requiretty
标签:zabbix
原文地址:http://blog.51cto.com/ckl893/2104864