* [gentoo-commits] gentoo-x86 commit in net-analyzer/munin/files: munin-1.4.6-if_-hardened-v2.patch
@ 2012-04-09 23:15 Diego Petteno (flameeyes)
0 siblings, 0 replies; only message in thread
From: Diego Petteno (flameeyes) @ 2012-04-09 23:15 UTC (permalink / raw
To: gentoo-commits
flameeyes 12/04/09 23:15:27
Added: munin-1.4.6-if_-hardened-v2.patch
Log:
Fix bug #403961, thanks to Tom Hendrikx.
(Portage version: 2.2.0_alpha100/cvs/Linux x86_64)
Revision Changes Path
1.1 net-analyzer/munin/files/munin-1.4.6-if_-hardened-v2.patch
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-analyzer/munin/files/munin-1.4.6-if_-hardened-v2.patch?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-analyzer/munin/files/munin-1.4.6-if_-hardened-v2.patch?rev=1.1&content-type=text/plain
Index: munin-1.4.6-if_-hardened-v2.patch
===================================================================
diff --git a/plugins/node.d.linux/if_.in b/plugins/node.d.linux/if_.in
index da0fc31..63a5dfd 100755
--- a/plugins/node.d.linux/if_.in
+++ b/plugins/node.d.linux/if_.in
@@ -43,7 +43,9 @@ monitored with this plugin.
=head1 AUTHOR
-Unknown author
+Original author unknown
+
+Copyright (C) 2011 Diego Elio Petteno' <flameeyes@flameeyes.eu>
=head1 LICENSE
@@ -64,86 +66,71 @@ Unknown license
INTERFACE=${0##*if_}
-findspeed () {
-
- # Who whould have thought it's so much work to determine the
- # maximum speed of a network interface. Buckle up!
-
- IWLIST="$(type -p iwlist)"
-
- WIRELESS=0
+# Who whould have thought it's so much work to determine the
+# maximum speed of a network interface. Buckle up!
+findspeed_mbps() {
# Do not use interface name to guess technology. Many many
# wifi drivers use "eth*" names.
- case $IWLIST in
-
- '')
- # Used to use iwconfig to look for "no wireless
- # extentions" message - but this seemed un-needed. If we
- # don't have iwlist we can't find out if # the interface
- # is wireless
- :;;
- *) IWO="$($IWLIST $INTERFACE rate 2>&1)"
- case $IWO in
- *no*) :;;
- *) WIRELESS=1;;
- esac
- ;;
- esac
-
- SPEED=U
- # Find speed in Mbps. - or not
- case $WIRELESS:$IWLIST in
- 0:*)
- ETHTOOL="$(type -p ethtool)"
- if [ -x "$ETHTOOL" ]; then
- SPEED="$($ETHTOOL $INTERFACE 2>&1 |
- awk '/Speed:/ { gsub(/[^0-9]*/,"",$2); print $2; }')"
- case $SPEED in
- [0-9]*) :;; # OK
- *) SPEED=U;; # Could be "unknown"
- esac
- else
- INSTALL="ethtool"
+ IWLIST="$(type -p iwlist)"
+ if [ -x "$IWLIST" ]; then
+ SPEED=$($IWLIST $INTERFACE rate 2>&1 |
+ awk 'BEGIN { RATE=U }
+ { if ($2 == "Mb/s") RATE=$1; }
+ END { print RATE; }')
+
+ if [ "$SPEED" != "U" ]; then
+ echo $SPEED
+ return
+ fi
+ fi
+
+ # sysfs can report the speed if the driver supports it (but it
+ # doesn't work as well for wireless cards, thus why we check for
+ # iwlist first)
+ if [ -r /sys/class/net/$INTERFACE/speed ]; then
+ SPEED="$(cat /sys/class/net/$INTERFACE/speed 2>/dev/null)"
+ if [ -n "$SPEED" ]; then
+ echo $SPEED
+ return
fi
- ;;
- 1:/*)
- # Current bit rate is not very interesting, it varies too often
- SPEED=$(echo "$IWO" |
- awk 'BEGIN { RATE=U }
- { if ($2 == "Mb/s") RATE=$1; }
- END { print RATE; }')
-
- ;;
- *)
- # Wireless interface, cannot find iwlist
- INSTALL="wireless-tools"
- ;;
- esac
+ fi
+
+ ETHTOOL="$(type -p ethtool)"
+ if [ -x "$ETHTOOL" ]; then
+ SPEED="$($ETHTOOL $INTERFACE 2>&1 |
+ awk '/Speed:/ { gsub(/[^0-9]*/,"",$2); print $2; }')"
+
+ if [ $SPEED = [0-9]* ]; then
+ echo $SPEED
+ return
+ fi
+ fi
MIITOOL="$(type -p mii-tool)"
- case $SPEED:$MIITOOL in
- U:/*)
- SPEED="$($MIITOOL $INTERFACE 2>&1)"
- case $SPEED in
- *1000base*) SPEED=1000;; # as if...
- *100base*) SPEED=100;;
- *10base*) SPEED=10;;
- *) SPEED=U;;
- esac
- ;;
- esac
-
- # sysfs can report the speed if the driver supports it
- SYSFS="$(cat /sys/class/net/$INTERFACE/speed 2>/dev/null)"
- # If it can't, it fails on I/O, so we check cat's return value
- if [ $? -eq 0 -a "$SPEED" = "U" -a -n "$SYSFS" ]; then
- SPEED="$SYSFS"
+ if [ -x $MIITOOL ]; then
+ case $($MIITOOL $INTERFACE 2>&1) in
+ *1000base*) echo 1000; return ;;
+ *100base*) echo 100; return ;;
+ *10base*) echo 10; return ;;
+ esac
fi
- case $SPEED in
- U) echo "up.info Traffic of the $INTERFACE interface. Unable to determine interface speed. Please install ethtool, wireless-tools (or mii-tool), whatever is appropriate for the interface."
- return;;
- esac
+ echo U
+}
+
+findspeed() {
+ SPEED=$(findspeed_mbps)
+
+ if [ -z $SPEED -o $SPEED = "U" ]; then
+ printf "up.info Traffic of the %s interface. Unable to determine interface speed." $INTERFACE
+ if [ $EUID -ne 0 ]; then
+ echo " Please run the plugin as root."
+ else
+ echo " Please install ethtool, wireless-tools, mii-tool or whatever is appropriate for the interface."
+ fi
+
+ return
+ fi
BPS=$(( $SPEED * 1000 * 1000 ))
@@ -207,11 +194,15 @@ case $1 in
esac
# Escape dots in the interface name (eg. vlans) before using it as a regex
-awk -v interface="$INTERFACE" \
- 'BEGIN { gsub(/\./, "\\.", interface) } \
- $1 ~ "^" interface ":" {
- split($0, a, /: */); $0 = a[2]; \
- print "down.value " $1 "\nup.value " $9 \
- }' \
- /proc/net/dev
-
+if [ -r /sys/class/net/$INTERFACE/statistics/rx_bytes ]; then
+ echo "down.value $(cat /sys/class/net/$INTERFACE/statistics/rx_bytes)"
+ echo "up.value $(cat /sys/class/net/$INTERFACE/statistics/tx_bytes)"
+else
+ awk -v interface="$INTERFACE" \
+ 'BEGIN { gsub(/\./, "\\.", interface) } \
+ $1 ~ "^" interface ":" {
+ split($0, a, /: */); $0 = a[2]; \
+ print "down.value " $1 "\nup.value " $9 \
+ }' \
+ /proc/net/dev
+fi
diff --git a/plugins/node.d.linux/if_err_.in b/plugins/node.d.linux/if_err_.in
index 331866d..2e35909 100755
--- a/plugins/node.d.linux/if_err_.in
+++ b/plugins/node.d.linux/if_err_.in
@@ -93,10 +93,15 @@ if [ "$1" = "config" ]; then
fi;
# Escape dots in the interface name (eg. vlans) before using it as a regex
-awk -v interface="$INTERFACE" \
- 'BEGIN { gsub(/\./, "\\.", interface) } \
- $1 ~ "^" interface ":" {
- split($0, a, /: */); $0 = a[2]; \
- print "rcvd.value " $3 "\ntrans.value " $11 \
- }' \
- /proc/net/dev
+if [ -r /sys/class/net/$INTERFACE/statistics/rx_bytes ]; then
+ echo "rcvd.value $(cat /sys/class/net/$INTERFACE/statistics/rx_errors)"
+ echo "trans.value $(cat /sys/class/net/$INTERFACE/statistics/tx_errors)"
+else
+ awk -v interface="$INTERFACE" \
+ 'BEGIN { gsub(/\./, "\\.", interface) } \
+ $1 ~ "^" interface ":" {
+ split($0, a, /: */); $0 = a[2]; \
+ print "rcvd.value " $3 "\ntrans.value " $11 \
+ }' \
+ /proc/net/dev
+fi
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-04-09 23:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-09 23:15 [gentoo-commits] gentoo-x86 commit in net-analyzer/munin/files: munin-1.4.6-if_-hardened-v2.patch Diego Petteno (flameeyes)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox