Skip to content

Instantly share code, notes, and snippets.

@alice-xu
Created July 30, 2014 06:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alice-xu/5c165636cec899e29bf5 to your computer and use it in GitHub Desktop.
Save alice-xu/5c165636cec899e29bf5 to your computer and use it in GitHub Desktop.
TCP listen port discovery for Zabbix LLD
#!/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