zoukankan      html  css  js  c++  java
  • 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 '{
    ' 
            printf '	"data":[
    ' 
        for((i=0;i<${#WEB_IP[@]};++i)) 
        { 
            num=$(echo $((${#WEB_IP[@]}-1))) 
            if [ "$i" != ${num} ]; 
                then 
                printf "		{ 
    " 
                printf "			"{#SITENAME}":"${WEB_IP[$i]}"},
    " 
            else 
                    printf  "		{ 
    " 
                    printf  "			"{#SITENAME}":"${WEB_IP[$num]}"}]}
    " 
            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
  • 相关阅读:
    边缘节点为什么不能直接通过 kubernetes service 直接访问云端 master 节点中的 API Server
    Leaflet中原生方式实现测距
    http网页是否能引用https资源/调用https接口?https网页是否能引用http资源/调用http接口?
    Vite2 Vue3 SSR
    SQL模糊查询的四种匹配模式
    vue3中ref、reactive、toRef、toRefs区别
    iis在访问vue服务时报错
    vue3中使用elform
    koa2cors实现过程以及应用
    chrome v8的垃圾回收机制和内存泄漏分析
  • 原文地址:https://www.cnblogs.com/reblue520/p/10764414.html
Copyright © 2011-2022 走看看