zabbix3.2自动发现批量监控redis端口状态

使用nmap提示被防火墙阻挡,实际没有启用防火墙

[root@eus_chinasoft_haproxy:/usr/local/aegis]# nmap 172.20.103.202 -p 7000

Starting Nmap 6.40 ( http://nmap.org ) at 2019-04-24 02:24 PDT
Nmap scan report for redis01 (172.20.103.202)
Host is up (0.000044s latency).
PORT STATE SERVICE
7000/tcp filtered afs3-fileserver
MAC Address: EE:FF:FF:FF:FF:FF (Unknown)

Nmap done: 1 IP address (1 host up) scanned in 0.29 seconds

 

[root@eus_chinasoft_haproxy:/usr/local/zabbix_agents_3.2.0/scripts]# cat /usr/local/zabbix_agents_3.2.0/scripts/redis_server_status.sh
#!/bin/bash 
# function:monitor redis port status from zabbix 
 

web_ip_discovery () { 
    WEB_IP=($(cat  /usr/local/zabbix_agents_3.2.0/scripts/redis_servers.txt|grep -v "^#")) 
        printf '{\n' 
        printf '\t"data":[\n' 
    for((i=0;i<${#WEB_IP[@]};++i)) 
    { 
        num=$(echo $((${#WEB_IP[@]}-1))) 
        if [ "$i" != ${num} ]; 
            then 
            printf "\t\t{ \n" 
            printf "\t\t\t\"{#SITENAME}\":\"${WEB_IP[$i]}\"},\n" 
        else 
                printf  "\t\t{ \n" 
                printf  "\t\t\t\"{#SITENAME}\":\"${WEB_IP[$num]}\"}]}\n" 
        fi 
    } 
} 
 
web_site_code () {
    ip=`echo $1|awk -F ':' '{print $1}'`
    port=`echo $1|awk -F ':' '{print $2}'`
    #echo $ip
    /usr/bin/nc -w 1 ${ip} ${port} </dev/null && echo 200
} 
 
case "$1" in
web_ip_discovery) 
web_ip_discovery
;;
web_site_code) 
web_site_code $2
;; 
*) 
 
echo "Usage:$0 {web_ip_discovery|web_site_code [URL]}" 
;; 
esac

# redis服务器列表
[root@eus_chinasoft_haproxy:/usr/local/zabbix_agents_3.2.0/scripts]# cat redis_servers.txt 
172.20.103.202:7000:eus_chinasoft_redis01
172.20.103.202:7001:eus_chinasoft_redis01
172.20.103.203:7000:eus_chinasoft_redis02
172.20.103.203:7000:eus_chinasoft_redis02
172.20.73.210:7000:eus_chinasoft_redis04
172.20.73.210:7001:eus_chinasoft_redis04
172.20.73.211:7000:eus_chinasoft_redis03
172.20.73.211:7001:eus_chinasoft_redis03
172.20.103.202:7002:eus_chinasoft_redis01
172.20.103.202:7003:eus_chinasoft_redis01
172.20.103.203:7002:eus_chinasoft_redis02
172.20.103.203:7003:eus_chinasoft_redis02
172.20.73.210:7002:eus_chinasoft_redis04
172.20.73.210:7003:eus_chinasoft_redis04
172.20.73.211:7002:eus_chinasoft_redis03
172.20.73.211:7003:eus_chinasoft_redis03

# 配置文件
UserParameter=web.ip.discovery,/usr/local/zabbix_agents_3.2.0/scripts/redis_server_status.sh web_ip_discovery
UserParameter=web.ip.code[*],/usr/local/zabbix_agents_3.2.0/scripts/redis_server_status.sh web_site_code $1


# 测试
[root@eus_chinasoft_haproxy:/usr/local/zabbix_agents_3.2.0/scripts]# /usr/local/zabbix_agents_3.2.0/scripts/redis_server_status.sh web_ip_discovery
{
    "data":[
        { 
            "{#SITENAME}":"172.20.103.202:7000:eus_chinasoft_redis01"},
        { 
            "{#SITENAME}":"172.20.103.202:7001:eus_chinasoft_redis01"},
        { 
            "{#SITENAME}":"172.20.103.203:7000:eus_chinasoft_redis02"},
        { 
            "{#SITENAME}":"172.20.103.203:7000:eus_chinasoft_redis02"},
        { 
            "{#SITENAME}":"172.20.73.210:7000:eus_chinasoft_redis04"},
        { 
            "{#SITENAME}":"172.20.73.210:7001:eus_chinasoft_redis04"},
        { 
            "{#SITENAME}":"172.20.73.211:7000:eus_chinasoft_redis03"},
        { 
            "{#SITENAME}":"172.20.73.211:7001:eus_chinasoft_redis03"},
        { 
            "{#SITENAME}":"172.20.103.202:7002:eus_chinasoft_redis01"},
        { 
            "{#SITENAME}":"172.20.103.202:7003:eus_chinasoft_redis01"},
        { 
            "{#SITENAME}":"172.20.103.203:7002:eus_chinasoft_redis02"},
        { 
            "{#SITENAME}":"172.20.103.203:7003:eus_chinasoft_redis02"},
        { 
            "{#SITENAME}":"172.20.73.210:7002:eus_chinasoft_redis04"},
        { 
            "{#SITENAME}":"172.20.73.210:7003:eus_chinasoft_redis04"},
        { 
            "{#SITENAME}":"172.20.73.211:7002:eus_chinasoft_redis03"},
        { 
            "{#SITENAME}":"172.20.73.211:7003:eus_chinasoft_redis03"}]}

[root@eus_chinasoft_haproxy:/usr/local/zabbix_agents_3.2.0/scripts]# /usr/local/zabbix_agents_3.2.0/scripts/redis_server_status.sh web_site_code 172.20.73.210:7002:eus_chinasoft_redis04
200

 

posted @ 2019-04-24 19:16  reblue520  阅读(593)  评论(0编辑  收藏  举报