• zabbix使用自动发现功能批量监控服务器端口的可用性


    使用自动发现脚本批量监控服务器端口的可用性
    
    1.编写自动发现脚本
    # cat /usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh 
    #!/bin/bash
    
    UrlFile="/usr/local/zabbix_agents_3.2.0/scripts/WEB.txt"
    IFS=$'
    '
    
    web_site_discovery () {
        WEB_SITE=($(cat $UrlFile|grep -v "^#"))
        printf '{
    '
        printf '	"data":[
    '
        num=${#WEB_SITE[@]}
        for site in ${WEB_SITE[@]}
        do
            num=$(( $num - 1 ))
            url=$(echo $site|awk '{print $1}')
            ip=$(echo $site|awk '{print $2}')
            if [ $num -ne 0 ] ; then
                printf "		{"{#SITENAME}":""%s"","{#PROXYIP}":""${ip}""},
    " ${url}
            else
                printf "		{"{#SITENAME}":""%s"","{#PROXYIP}":""${ip}""}
    " ${url}
                printf '	]
    '
                printf '}
    '
            fi
        done
    }
    
    web_site_code () {
    /usr/bin/nmap $1 -p 873 2>/dev/null | grep -c open
    }
    
    case "$1" in
        web_site_discovery)
            web_site_discovery
            ;;
        web_site_code)
            web_site_code $2
            ;;
        *)
            echo "Usage:$0 {web_site_discovery|web_site_code [URL]}"
            ;;
    esac
    
    
    2.需要监控的服务器列表
    [root@cbs_logs_master:/usr/local/zabbix_agents_3.2.0/scripts]# cat WEB.txt 
    ws_cbs_frontend_web01 1.1.1.1
    ws_cbs_frontend_web02 1.1.1.2
    
    # 监控选项
    [root@cbs_logs_master:/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd]# more web_site_discovery.conf 
    UserParameter=web.site.discovery,/usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh web_site_discovery
    UserParameter=web.site.code[*],/usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh web_site_code $1
    
    # 本机测试
    [root@cbs_logs_master:/usr/local/zabbix_agents_3.2.0/conf/zabbix_agentd]# /usr/local/zabbix_agents_3.2.0/scripts/web_site_code_status.sh web_site_code 1.1.1.1
    1
    
    # zabbix服务端测试
    # zabbix_get -s 192.168.11.42 -k 'web.site.code[1.1.1.1]'
    1

    监控模板

    <?xml version="1.0" encoding="UTF-8"?>
    <zabbix_export>
        <version>3.4</version>
        <date>2019-11-08T12:33:05Z</date>
        <groups>
            <group>
                <name>Templates</name>
            </group>
        </groups>
        <templates>
            <template>
                <template>urls_monitor_port</template>
                <name>urls_monitor_port</name>
                <description/>
                <groups>
                    <group>
                        <name>Templates</name>
                    </group>
                </groups>
                <applications/>
                <items/>
                <discovery_rules>
                    <discovery_rule>
                        <name>web.site.discovery</name>
                        <type>0</type>
                        <snmp_community/>
                        <snmp_oid/>
                        <key>web.site.discovery</key>
                        <delay>180;180/1-7,00:00-24:00</delay>
                        <status>0</status>
                        <allowed_hosts/>
                        <snmpv3_contextname/>
                        <snmpv3_securityname/>
                        <snmpv3_securitylevel>0</snmpv3_securitylevel>
                        <snmpv3_authprotocol>0</snmpv3_authprotocol>
                        <snmpv3_authpassphrase/>
                        <snmpv3_privprotocol>0</snmpv3_privprotocol>
                        <snmpv3_privpassphrase/>
                        <params/>
                        <ipmi_sensor/>
                        <authtype>0</authtype>
                        <username/>
                        <password/>
                        <publickey/>
                        <privatekey/>
                        <port/>
                        <filter>
                            <evaltype>0</evaltype>
                            <formula/>
                            <conditions/>
                        </filter>
                        <lifetime>30d</lifetime>
                        <description/>
                        <item_prototypes>
                            <item_prototype>
                                <name>web.site.discovery</name>
                                <type>0</type>
                                <snmp_community/>
                                <snmp_oid/>
                                <key>web.site.code[{#PROXYIP},]</key>
                                <delay>30</delay>
                                <history>90d</history>
                                <trends>365d</trends>
                                <status>0</status>
                                <value_type>3</value_type>
                                <allowed_hosts/>
                                <units/>
                                <snmpv3_contextname/>
                                <snmpv3_securityname/>
                                <snmpv3_securitylevel>0</snmpv3_securitylevel>
                                <snmpv3_authprotocol>0</snmpv3_authprotocol>
                                <snmpv3_authpassphrase/>
                                <snmpv3_privprotocol>0</snmpv3_privprotocol>
                                <snmpv3_privpassphrase/>
                                <params/>
                                <ipmi_sensor/>
                                <authtype>0</authtype>
                                <username/>
                                <password/>
                                <publickey/>
                                <privatekey/>
                                <port/>
                                <description/>
                                <inventory_link>0</inventory_link>
                                <applications/>
                                <valuemap/>
                                <logtimefmt/>
                                <preprocessing/>
                                <jmx_endpoint/>
                                <application_prototypes/>
                                <master_item_prototype/>
                            </item_prototype>
                        </item_prototypes>
                        <trigger_prototypes>
                            <trigger_prototype>
                                <expression>{urls_monitor_port:web.site.code[{#PROXYIP},].last(0)}&lt;&gt;1 and {urls_monitor_port:web.site.code[{#PROXYIP},].last(1)}&lt;&gt;1</expression>
                                <recovery_mode>0</recovery_mode>
                                <recovery_expression/>
                                <name>web.site.code {#SITENAME} port 873 is not open</name>
                                <correlation_mode>0</correlation_mode>
                                <correlation_tag/>
                                <url/>
                                <status>0</status>
                                <priority>0</priority>
                                <description/>
                                <type>0</type>
                                <manual_close>0</manual_close>
                                <dependencies/>
                                <tags/>
                            </trigger_prototype>
                        </trigger_prototypes>
                        <graph_prototypes/>
                        <host_prototypes/>
                        <jmx_endpoint/>
                    </discovery_rule>
                </discovery_rules>
                <httptests/>
                <macros/>
                <templates/>
                <screens/>
            </template>
        </templates>
    </zabbix_export>
  • 相关阅读:
    2015年秋季个人阅读计划
    MFC Cstring转化为string
    虚拟机无法共享文件夹解决
    YCM编译安装
    windows 下mysql loadfile 返回NULL的解决
    读“单例写出花来”瞎想
    Spark Scheduler内部原理剖析
    go 获取函数被调用的文件即行数
    spark 获取applicationID
    spark job, stage ,task介绍。
  • 原文地址:https://www.cnblogs.com/reblue520/p/11823138.html
Copyright © 2020-2023  润新知