您好,登錄后才能下訂單哦!
在我們進行自動發現的時候,總會有一個腳本來獲取端口等信息,并返回json格式,那以redis為例,下邊是redis進行進行自動發現的腳本
redisport=(`ps aux|grep -w redis-server|grep -v "grep" |awk -F':' '{print $NF}'`) portnum=${#redisport[@]} count=`hostname | grep "\-SQ" | wc -l` if [ $count -eq 1 ];then address=` /usr/sbin/ip address | grep -w "inet" | awk -F " " '{print $2}' | egrep "^10."| awk -F"/" '{print $1}'` else address=` /usr/sbin/ip address | grep "192.168" | awk '{print $2}' | awk -F "/" '{print $1}'` fi printf "{\n" printf '\t'"\"data\":[" for ((i=0;i<$portnum;i++)) do printf '\n\t\t{\n' printf '\t\t\t' printf "\"{#REDIS_PORT}\":\"${redisport[$i]}\"", printf '\n\t\t\t' printf "\"{#REDIS_ADDRESS}\":\"${address}"\", printf '\n\t\t\t' printf "\"{#REDIS_NAME}\":\"Redis ${address}:${redisport[$i]}\"" printf '\n\t\t}' if [ $i -lt $[$portnum-1] ];then printf ',' fi done printf "\n\t]\n" printf "}\n"
返回結果如下
{ "data":[ { "{#REDIS_PORT}":"6386", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6386" }, { "{#REDIS_PORT}":"6387", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6387" }, { "{#REDIS_PORT}":"6388", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6388" }, { "{#REDIS_PORT}":"6379", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6379" }, { "{#REDIS_PORT}":"6384", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6384" }, { "{#REDIS_PORT}":"6385", "{#REDIS_ADDRESS}":"192.168.43.66", "{#REDIS_NAME}":"Redis 192.168.43.66:6385" } ] }
總結
以上所述是小編給大家介紹的zabbix redis自動發現端口的腳本返回json格式,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對億速云網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。