From 80462688936ae4bb726c7065fbfb6ac289a361e9 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sat, 22 Aug 2020 20:26:27 +0200 Subject: [PATCH] if_: handle "Unknown" emitted by ethtool Previously error messages were emitted due to this non-numeric value. Closes: #3 --- plugins/if_ | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/if_ b/plugins/if_ index dc6b379..d2b5460 100644 --- a/plugins/if_ +++ b/plugins/if_ @@ -16,10 +16,12 @@ config_if() { echo "up.min 0" echo "up.negative down" echo "up.cdef up,8,*" - if [ -n "$(which ethtool)" ] && [ -x "$(which ethtool)" ] && ethtool "$INTERFACE" 2>/dev/null | grep -q Speed; then - 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 "down.max $MAX" + if [ -n "$(which ethtool)" ] && [ -x "$(which ethtool)" ]; then + MAX_MBPS=$(ethtool "$INTERFACE" 2>/dev/null | grep "Speed: [0-9]\+Mb/s$" | sed 's/[^0-9]//g') + if [ -n "$MAX_MBPS" ]; then + echo "up.max $((MAX_MBPS * 1024 * 1024))" + echo "down.max $((MAX_MBPS * 1024 * 1024))" + fi fi } fetch_if() {