Plugin netstat: adjust filter to newer netstat version

Newer versions of netstat use "active connection openings" instead of
"active connections".
This commit is contained in:
Lars Kruse 2020-02-08 04:58:35 +01:00
parent e439fd79a1
commit 60b16f4121
2 changed files with 34 additions and 39 deletions

View file

@ -68,45 +68,40 @@ do_quit() {
# ===== Runtime config ===== # ===== Runtime config =====
RES="" RES=""
for PLUG in $PLUGINS for PLUG in $PLUGINS; do
do case "$PLUG" in
if [ "$PLUG" = "if_" ]; then if_|if_err_)
for INTER in $(grep -E '^ *(ppp|eth|wlan|ath|ra|ipsec|tap|br-)[^:]{1,}:' /proc/net/dev | cut -f1 -d: | sed 's/ //g'); interface_names=$(grep -E '^ *(ppp|eth|wlan|ath|ra|ipsec|tap|br-)[^:]{1,}:' /proc/net/dev | sed 's/^ *//; s/:.*$//')
do for INTER in $interface_names; do
INTERRES=$(echo "$INTER" | sed -e 's/\./VLAN/' -e 's/\-/_/') INTERRES=$(echo "$INTER" | sed -e 's/\./VLAN/' -e 's/\-/_/')
RES="$RES if_$INTERRES" RES="$RES ${PLUG}${INTERRES}"
eval 'fetch_if_'"$INTERRES"'() { fetch_if "'"$INTER"'" "$@"; };' eval "fetch_${PLUG}${INTERRES}() { 'fetch_${PLUG%_}' '$INTER'; }"
eval 'config_if_'"$INTERRES"'() { config_if "'"$INTER"'" "$@"; };' eval "config_${PLUG}${INTERRES}() { 'config_${PLUG%_}' '$INTER'; }"
done done
elif [ "$PLUG" = "if_err_" ]; then ;;
for INTER in $(grep -E '^ *(ppp|eth|wlan|ath|ra|ipsec|tap|br-)[^:]{1,}:' /proc/net/dev | cut -f1 -d: | sed 's/ //g'); netstat)
do
INTERRES=$(echo "$INTER" | sed -e 's/\./VLAN/' -e 's/\-/_/')
RES="$RES if_err_$INTERRES"
eval 'fetch_if_err_'"$INTERRES"'() { fetch_if_err "'"$INTER"'" "$@"; };'
eval 'config_if_err_'"$INTERRES"'() { config_if_err "'"$INTER"'" "$@"; };'
done
elif [ "$PLUG" = "netstat" ]; then
if netstat -s >/dev/null 2>&1; then if netstat -s >/dev/null 2>&1; then
RES="$RES netstat" RES="$RES netstat"
fi fi
elif [ "$PLUG" = "plugindir_" ]; then ;;
for MYPLUGIN in $(if [ -d "$PLUGIN_DIRECTORY" ]; then find -L "$PLUGIN_DIRECTORY" -type f -name "$PLUGINPATTERN"; fi); plugindir_)
do for MYPLUGIN in $(if [ -d "$PLUGIN_DIRECTORY" ]; then find -L "$PLUGIN_DIRECTORY" -type f -name "$PLUGINPATTERN"; fi); do
if [ -f "$MYPLUGIN" ] && [ -x "$MYPLUGIN" ]; then if [ -f "$MYPLUGIN" ] && [ -x "$MYPLUGIN" ]; then
MYPLUGINNAME=$(basename "$MYPLUGIN") MYPLUGINNAME=$(basename "$MYPLUGIN")
#ensure we don't have name collision # detect and avoid name collision
if echo "$RES" | grep -qwF "$MYPLUGINNAME"; then if echo "$RES" | grep -qwF "$MYPLUGINNAME"; then
MYPLUGINNAME="plugindir_$MYPLUGINNAME" MYPLUGINNAME="plugindir_$MYPLUGINNAME"
fi fi
RES="$RES $MYPLUGINNAME" RES="$RES $MYPLUGINNAME"
eval "fetch_${MYPLUGINNAME}() { '$MYPLUGIN'; };" eval "fetch_${MYPLUGINNAME}() { '$MYPLUGIN'; }"
eval "config_${MYPLUGINNAME}() { '$MYPLUGIN' config; };" eval "config_${MYPLUGINNAME}() { '$MYPLUGIN' config; }"
fi fi
done done
else ;;
*)
RES="$RES $PLUG" RES="$RES $PLUG"
fi ;;
esac
done done
# sort plugin names and remove surrounding whitespace # sort plugin names and remove surrounding whitespace
PLUGINS=$(echo "$RES" | xargs -r -n 1 echo | sort | xargs echo) PLUGINS=$(echo "$RES" | xargs -r -n 1 echo | sort | xargs echo)

View file

@ -32,7 +32,7 @@ config_netstat() {
} }
fetch_netstat() { fetch_netstat() {
NINFO=$(netstat -s | sed 's/ \{1,\}/ /g') NINFO=$(netstat -s | sed 's/ \{1,\}/ /g')
echo "active.value" "$(echo "$NINFO" | grep "active connections" | cut -d " " -f 2)" echo "active.value" "$(echo "$NINFO" | grep "active connection" | cut -d " " -f 2)"
echo "passive.value" "$(echo "$NINFO" | grep "passive connection" | cut -d " " -f 2)" echo "passive.value" "$(echo "$NINFO" | grep "passive connection" | cut -d " " -f 2)"
echo "failed.value" "$(echo "$NINFO" | grep "failed connection" | cut -d " " -f 2)" echo "failed.value" "$(echo "$NINFO" | grep "failed connection" | cut -d " " -f 2)"
echo "resets.value" "$(echo "$NINFO" | grep "connection resets" | cut -d " " -f 2)" echo "resets.value" "$(echo "$NINFO" | grep "connection resets" | cut -d " " -f 2)"