diff options
-rwxr-xr-x | net_if | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -17,7 +17,8 @@ my %nagios = ( # Print nagios compatible status message and terminat script # with apropiate return code. # -# parameter: type of message +# parameter: +# type of message sub msg ($@) { my $type = shift; my ($msg, $exit) = @{$nagios{$type}}; @@ -31,25 +32,32 @@ sub msg ($@) { # This resolves interfaces groups, but only return the interfaces # that are up. # -# parameter: list of interfaces +# parameter: +# list of interfaces sub get_if_status (@) { my (@up, @down, @error); while (@_) { + # untaint interface name my $if = shift @_; next unless ($if =~ m/^([-\w]+)$/); $if = $1; + # We are doing an two step process. First we do a fork and + # after that we exec the ifconfig child process. This is + # necessary to pipe stderr of the child process away, while + # using the list syntax for open and exec. my $pid = open(IFCONFIG, "-|"); msg('crit', "fork: $!") unless defined $pid; if ($pid == 0) { - # child + # redirect stderr open(STDERR, ">", "/dev/null"); exec("ifconfig", $if) } while (<IFCONFIG>) { + # parse ifconfig output: if ($_ =~ m/^([-a-v0-9]+): flags=([0-9]+)</) { if ($2 & 1) { push(@up, $1); @@ -68,7 +76,8 @@ sub get_if_status (@) { # Get the byte conters for incomming and outgoing packages. # -# parameter: interface name +# parameter: +# interface name sub get_if_stats ($) { my $if = shift; my $stats = {}; @@ -95,6 +104,11 @@ sub get_if_stats ($) { # Print nagios compatible message containing the number of interfaces # and performance data containing the byte counter for the interfaces. +# +# parameter: +# nagios status code +# additional message +# interface statistics sub print_stats ($) { my $stats = shift; my ($count, $perfdata); |