#!/bin/bash

# Define Variables
PING_DISCOVERY_URL="http://down.vqiu.cn/scripts/project/wy_zabbix/ping_discovery.sh"
HTTP_DISCOVERY_URL="http://down.vqiu.cn/scripts/project/wy_zabbix/http_discovery.sh"

SCRIPT_DIR="/usr/local/etc/scripts"
AGENTD_CONF_DIR="/usr/local/etc/zabbix_agentd.conf.d"

cd ${SCRIPT_DIR}
[[ -f ./ping_discovery.sh ]] && \rm -rf ping_discovery.sh
[[ -f ./http_discovery.sh ]] && \rm -rf http_discovery.sh
wget -c ${PING_DISCOVERY_URL}
wget -c ${HTTP_DISCOVERY_URL}
chmod +x ./ -R

cd ${AGENTD_DIR}
cat > ${AGENTD_CONF_DIR}/http_discovery.conf<<EOF
UserParameter=http.discovery[*],${SCRIPT_DIR}/http_discovery.sh "\$1"
EOF

cat > ${AGENTD_CONF_DIR}/ping_discovery.conf<<EOF
UserParameter=ping.discovery[*],${SCRIPT_DIR}/ping_discovery.sh "\$1"
EOF

systemctl restart zabbix-agent
