Created
July 30, 2014 06:43
-
-
Save alice-xu/5c165636cec899e29bf5 to your computer and use it in GitHub Desktop.
TCP listen port discovery for Zabbix LLD
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
#!/usr/bin/env bash | |
PROCNAME="$1" | |
PORT_LIST=$(ss -nap|grep LISTEN|grep \"${PROCNAME}\" \ | |
|awk '{ print $4 }'|sed -e 's/.*://g'|sort|uniq) | |
[ -z "${PORT_LIST}" ] && echo ZBX_NOTSUPPORTED && exit 1 | |
{ | |
echo "{" | |
echo " \"data\":[" | |
for PORT in ${PORT_LIST}; do | |
echo " {" | |
echo " \"{#LISTEN_PORT}\":\"${PORT}\"" | |
echo " }," | |
done | sed -e '$d' | |
echo " }" | |
echo " ]" | |
echo "}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment