Plugin if_ and if_err_: use explicit variable for interface name

This commit is contained in:
Lars Kruse 2020-02-08 05:28:40 +01:00
parent 60b16f4121
commit b5d8f7931b
2 changed files with 11 additions and 7 deletions

View file

@ -1,6 +1,7 @@
config_if() { config_if() {
INTERFACE=$1
echo "graph_order down up" echo "graph_order down up"
echo "graph_title $1 traffic" echo "graph_title $INTERFACE traffic"
echo "graph_args --base 1000" echo "graph_args --base 1000"
echo "graph_vlabel bits in (-) / out (+) per \${graph_period}" echo "graph_vlabel bits in (-) / out (+) per \${graph_period}"
echo "graph_category network" echo "graph_category network"
@ -17,8 +18,8 @@ config_if() {
echo "up.cdef up,8,*" echo "up.cdef up,8,*"
if [ -n "$(which ethtool)" ]; then if [ -n "$(which ethtool)" ]; then
if [ -x "$(which ethtool)" ]; then if [ -x "$(which ethtool)" ]; then
if ethtool "$1" | grep -q Speed; then if ethtool "$INTERFACE" | grep -q Speed; then
MAX=$(($(ethtool "$1" | grep Speed | sed -e 's/[[:space:]]\{1,\}/ /g' -e 's/^ //' -e 's/M.*//' | cut -d " " -f 2) * 1000000)) MAX=$(($(ethtool "$INTERFACE" | grep Speed | sed -e 's/[[:space:]]\{1,\}/ /g' -e 's/^ //' -e 's/M.*//' | cut -d " " -f 2) * 1000000))
echo "up.max $MAX" echo "up.max $MAX"
echo "down.max $MAX" echo "down.max $MAX"
fi fi
@ -26,7 +27,8 @@ config_if() {
fi fi
} }
fetch_if() { fetch_if() {
IINFO=$(grep "^ *$1:" /proc/net/dev | cut -d ":" -f 2 | sed -e 's/ */ /g' -e 's/^[ \t]*//') INTERFACE=$1
IINFO=$(grep "^ *$INTERFACE:" /proc/net/dev | cut -d ":" -f 2 | sed -e 's/ */ /g' -e 's/^[ \t]*//')
echo "down.value" "$(echo "$IINFO" | cut -d " " -f 1)" echo "down.value" "$(echo "$IINFO" | cut -d " " -f 1)"
echo "up.value" "$(echo "$IINFO" | cut -d " " -f 9)" echo "up.value" "$(echo "$IINFO" | cut -d " " -f 9)"
} }

View file

@ -1,10 +1,11 @@
config_if_err() { config_if_err() {
INTERFACE=$1
echo "graph_order rcvd trans" echo "graph_order rcvd trans"
echo "graph_title $1 errors" echo "graph_title $INTERFACE errors"
echo "graph_args --base 1000" echo "graph_args --base 1000"
echo "graph_vlabel packets in (-) / out (+) per \${graph_period}" echo "graph_vlabel packets in (-) / out (+) per \${graph_period}"
echo "graph_category network" echo "graph_category network"
echo "graph_info This graph shows the amount of errors on the $1 network interface." echo "graph_info This graph shows the amount of errors on the $INTERFACE network interface."
echo "rcvd.label packets" echo "rcvd.label packets"
echo "rcvd.type COUNTER" echo "rcvd.type COUNTER"
echo "rcvd.graph no" echo "rcvd.graph no"
@ -15,7 +16,8 @@ config_if_err() {
echo "trans.warning 1" echo "trans.warning 1"
} }
fetch_if_err() { fetch_if_err() {
IINFO=$(grep "^ *$1:" /proc/net/dev | cut -d ":" -f 2 | sed -e 's/ */ /g' -e 's/^[ \t]*//') INTERFACE=$1
IINFO=$(grep "^ *$INTERFACE:" /proc/net/dev | cut -d ":" -f 2 | sed -e 's/ */ /g' -e 's/^[ \t]*//')
echo "rcvd.value" "$(echo "$IINFO" | cut -d " " -f 3)" echo "rcvd.value" "$(echo "$IINFO" | cut -d " " -f 3)"
echo "trans.value" "$(echo "$IINFO" | cut -d " " -f 11)" echo "trans.value" "$(echo "$IINFO" | cut -d " " -f 11)"
} }