summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-01-11 04:00:32 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-11 04:00:32 +0100
commit65acfdc8b408dad17779fc686b14b3532e55476c (patch)
treed94f5f3e64736ed3fafe502a1f58a5409fbc5da1
parentc59b49203834348ecfb256350d574f395d84606c (diff)
downloadnet_if-65acfdc8b408dad17779fc686b14b3532e55476c.tar.gz
net_if-65acfdc8b408dad17779fc686b14b3532e55476c.tar.bz2
net_if-65acfdc8b408dad17779fc686b14b3532e55476c.zip
capture all interfaces (not only up interfaces)
To support nagiosgrapher each time the performance data for all interfaces should be emited (even if they are down). So capture all existing interfaces that are specified on the command line or that are part of an interface group.
-rwxr-xr-xnet_if22
1 files changed, 9 insertions, 13 deletions
diff --git a/net_if b/net_if
index f2f1d31..265ad80 100755
--- a/net_if
+++ b/net_if
@@ -28,14 +28,14 @@ sub msg ($@) {
}
# Check the status of the given network interface and return
-# three lists the interfaces sorted by status (up, down, error).
-# This resolves interfaces groups, but only return the interfaces
-# that are up.
+# three lists of the interfaces sorted by status (all, down, error).
+# This does resolves interfaces groups automaticaly and returns
+# the member interfaces.
#
# parameter:
# list of interfaces
sub get_if_status (@) {
- my (@up, @down, @error);
+ my (@all, @down, @error);
while (@_) {
# untaint interface name
@@ -59,19 +59,15 @@ sub get_if_status (@) {
while (<IFCONFIG>) {
# parse ifconfig output:
if ($_ =~ m/^([-a-v0-9]+): flags=([0-9]+)</) {
- if ($2 & 1) {
- push(@up, $1);
- }
- else {
- push (@down, $if) if $1 eq $if;
- }
+ push(@all, $1);
+ push(@down, $1) unless ($2 & 1);
}
}
close(IFCONFIG) or push(@error, $if);
}
- return (\@up, \@down, \@error);
+ return (\@all, \@down, \@error);
}
# Get the byte conters for incomming and outgoing packages.
@@ -125,7 +121,7 @@ sub print_stats ($) {
}
-my ($up, $down, $error) = get_if_status(@ARGV);
+my ($interfaces, $down, $error) = get_if_status(@ARGV);
if (@$error) {
$error = join ", ", @$error;
@@ -138,7 +134,7 @@ if (@$down) {
}
my $stats = {};
-for my $if (@$up) {
+for my $if (@$interfaces) {
$stats->{$if} = get_if_stats($if);
}