-
-
Save djhuahao/a75a14235759d0985b215a099b0eb661 to your computer and use it in GitHub Desktop.
Replace netstat with ss to implement the low level discovery for zabbix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
lines=$(sudo ss -lp | grep $1 | awk '{print $3}' | cut -d: -f2 | sort | wc -l) | |
if [ "$1" == "mongod" ] | |
then | |
portarray=(`sudo ss -lp | grep $1 | awk '{print $3}' | cut -d: -f2 | sort | head -n $(($lines/2)) 2>/dev/null`) | |
else | |
portarray=(`sudo ss -lp | grep $1 | awk '{print $3}' | cut -d: -f2 | sort 2>/dev/null`) | |
fi | |
length=${#portarray[@]} | |
printf "{\n" | |
printf '\t'"\"data\":[" | |
for ((i=0;i<$length;i++)) | |
do | |
printf '\n\t\t{ ' | |
printf "\"{#TCP_PORT}\":\"${portarray[$i]}\" }" | |
if [ $i -lt $[$length-1] ];then | |
printf ',' | |
fi | |
done | |
printf "\n\t]\n" | |
printf "}\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment