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

View file

@ -32,7 +32,7 @@ config_netstat() {
}
fetch_netstat() {
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 "failed.value" "$(echo "$NINFO" | grep "failed connection" | cut -d " " -f 2)"
echo "resets.value" "$(echo "$NINFO" | grep "connection resets" | cut -d " " -f 2)"