From 36dbfa1b28bada1de4faef91a29b514be108b790 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sat, 13 Sep 2014 22:03:45 +0200 Subject: [PATCH 1/4] arp_ sh lint --- plugins/network/arp_ | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/network/arp_ b/plugins/network/arp_ index adbd86c3..471d17f3 100755 --- a/plugins/network/arp_ +++ b/plugins/network/arp_ @@ -15,7 +15,7 @@ #%# family=contrib #%# capabilities=autoconf suggest -INTERFACE=`basename $0 | sed 's/^arp_//g' | tr '_' '.'` +INTERFACE=$(basename $0 | sed 's/^arp_//g' | tr '_' '.') if [ "$1" = "autoconf" ]; then # Search for arp @@ -43,7 +43,7 @@ if [ "$1" = "config" ]; then echo 'graph_vlabel Entries' echo 'graph_category network' echo 'graph_scale no' - echo "graph_info This graph shows the number of ARP entries registered by the system for interface $INTERFACE." + echo "graph_info This graph shows the number of ARP entries registered by the system for interface ${INTERFACE}." echo 'entries.label ARP entries' echo 'entries.draw LINE2' echo 'entries.type GAUGE' @@ -51,5 +51,5 @@ if [ "$1" = "config" ]; then exit 0 fi -arp -an -i $INTERFACE | awk 'BEGIN { regex="";} { if (!match($4,regex)) { a[$4] }} END{for(i in a){n++};print "entries.value " n}' +arp -an -i "$INTERFACE" | awk 'BEGIN { regex="";} { if (!match($4,regex)) { a[$4] }} END{for(i in a){n++};print "entries.value " n}' From 2d0c82de8126a1602c8b30f107eb724be144dff4 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sat, 13 Sep 2014 22:10:22 +0200 Subject: [PATCH 2/4] arp_ wspace fix --- plugins/network/arp_ | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/network/arp_ b/plugins/network/arp_ index 471d17f3..79159e94 100755 --- a/plugins/network/arp_ +++ b/plugins/network/arp_ @@ -27,28 +27,28 @@ if [ "$1" = "autoconf" ]; then fi if [ "$1" = "suggest" ]; then - if [ -r /proc/net/dev ]; then - egrep '^ *(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?:' /proc/net/dev | cut -f1 -d: | sed 's/ //g' | tr '.' '_' - exit 0 - else - exit 1 - fi + if [ -r /proc/net/dev ]; then + egrep '^ *(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?:' /proc/net/dev | cut -f1 -d: | sed 's/ //g' | tr '.' '_' + exit 0 + else + exit 1 + fi fi if [ "$1" = "config" ]; then - echo "graph_title ARP entries for $INTERFACE" - echo 'graph_args --base 1000 -l 0' - echo 'graph_vlabel Entries' - echo 'graph_category network' - echo 'graph_scale no' - echo "graph_info This graph shows the number of ARP entries registered by the system for interface ${INTERFACE}." - echo 'entries.label ARP entries' - echo 'entries.draw LINE2' - echo 'entries.type GAUGE' - echo 'entries.info Number of ARP entries' - exit 0 + echo "graph_title ARP entries for $INTERFACE" + echo 'graph_args --base 1000 -l 0' + echo 'graph_vlabel Entries' + echo 'graph_category network' + echo 'graph_scale no' + echo "graph_info This graph shows the number of ARP entries registered by the system for interface ${INTERFACE}." + echo 'entries.label ARP entries' + echo 'entries.draw LINE2' + echo 'entries.type GAUGE' + echo 'entries.info Number of ARP entries' + exit 0 fi arp -an -i "$INTERFACE" | awk 'BEGIN { regex="";} { if (!match($4,regex)) { a[$4] }} END{for(i in a){n++};print "entries.value " n}' From 0d718aadc3db8aba0edef41ee934fcaf8629d450 Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Sat, 13 Sep 2014 22:26:10 +0200 Subject: [PATCH 3/4] arp_ less processes --- plugins/network/arp_ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/network/arp_ b/plugins/network/arp_ index 79159e94..35fd4b78 100755 --- a/plugins/network/arp_ +++ b/plugins/network/arp_ @@ -28,7 +28,7 @@ fi if [ "$1" = "suggest" ]; then if [ -r /proc/net/dev ]; then - egrep '^ *(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?:' /proc/net/dev | cut -f1 -d: | sed 's/ //g' | tr '.' '_' + awk '$1~ /^(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?/ { gsub(":", ""); gsub("\.", "_"); print $1 }' /proc/net/dev exit 0 else exit 1 From 3f0845af2b9abfb4521a2c0f3e6aaf0342cdffee Mon Sep 17 00:00:00 2001 From: Martin Ness Date: Wed, 24 Sep 2014 05:03:30 +0200 Subject: [PATCH 4/4] arp_ well-sorted --- plugins/network/arp_ | 84 +++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/plugins/network/arp_ b/plugins/network/arp_ index 35fd4b78..f85865b4 100755 --- a/plugins/network/arp_ +++ b/plugins/network/arp_ @@ -8,6 +8,7 @@ # autoconf (optional) # # Made by Sven Hartge (sven AT svenhartge DOT de) +# change to iproute by Martin89 (martin AT martin89 DOT de) # # @@ -15,41 +16,52 @@ #%# family=contrib #%# capabilities=autoconf suggest -INTERFACE=$(basename $0 | sed 's/^arp_//g' | tr '_' '.') +case "$1" in + autoconf) + # Search for ip + which ip >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "no (can't find ip binary)" + exit 1 + fi + # ...or success + echo 'yes' + exit 0 + ;; + suggest) + if [ ! -r /proc/net/dev ]; then + exit 1 + fi + awk '$1~ /^(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?/ { gsub(":", ""); gsub("\.", "_"); print $1 }' /proc/net/dev + exit 0 + ;; + config) + INTERFACE="$(basename $0 | sed 's/^arp_//g' | tr '_' '.')" + if [ -z "$INTERFACE" ]; then + exit 1 + fi + echo "graph_title ARP/NDP entries for $INTERFACE" + cat <<'EOM' +graph_args --base 1000 -l 0 +graph_vlabel Entries +graph_category network +graph_scale no +graph_info This graph shows the number of ARP and NDP entries for a interface. +entries4.label ARP entries +entries4.info Number of ARP entries +entries6global.label NDP global entries +entries6global.info Number of NDP entries for global IPv6 address +entries6local.label NDP local entries +entries6local.info Number of NDP entries for link-local IPv6 address (fe80::/64) +EOM + exit 0 + ;; +esac -if [ "$1" = "autoconf" ]; then - # Search for arp - which arp >/dev/null 2>/dev/null || (echo "no (can't find arp binary)" && exit 1) - - # ...or success - echo yes - exit 0 +INTERFACE="$(basename $0 | sed 's/^arp_//g' | tr '_' '.')" +if [ -z "$INTERFACE" ]; then + exit 1 fi - -if [ "$1" = "suggest" ]; then - if [ -r /proc/net/dev ]; then - awk '$1~ /^(eth|wlan|ath|ra)[0-9]+(\.[0-9]+)?/ { gsub(":", ""); gsub("\.", "_"); print $1 }' /proc/net/dev - exit 0 - else - exit 1 - fi -fi - - - -if [ "$1" = "config" ]; then - echo "graph_title ARP entries for $INTERFACE" - echo 'graph_args --base 1000 -l 0' - echo 'graph_vlabel Entries' - echo 'graph_category network' - echo 'graph_scale no' - echo "graph_info This graph shows the number of ARP entries registered by the system for interface ${INTERFACE}." - echo 'entries.label ARP entries' - echo 'entries.draw LINE2' - echo 'entries.type GAUGE' - echo 'entries.info Number of ARP entries' - exit 0 -fi - -arp -an -i "$INTERFACE" | awk 'BEGIN { regex="";} { if (!match($4,regex)) { a[$4] }} END{for(i in a){n++};print "entries.value " n}' - +ip neigh show dev "$INTERFACE" | awk 'BEGIN { a=0; b=0; c=0 } +/(REACHABLE|DELAY|STALE)/ { if ($1~ /^fe80:/){c++} else{if ($1~ /^[0-9]+\./) {a++} else{b++} } } +END { print "entries4.value", a "\nentries6global.value", b, "\nentries6local.value", c }'