summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-01-11 03:49:26 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-11 03:49:26 +0100
commitc59b49203834348ecfb256350d574f395d84606c (patch)
tree6f69c60904d3e7a4489ac278b91fd4e2a9cc07bd
parent1f498c055227d04a87dd7d79cbbc6392a463ea3c (diff)
downloadnet_if-c59b49203834348ecfb256350d574f395d84606c.tar.gz
net_if-c59b49203834348ecfb256350d574f395d84606c.tar.bz2
net_if-c59b49203834348ecfb256350d574f395d84606c.zip
add some more comments
-rwxr-xr-xnet_if22
1 files changed, 18 insertions, 4 deletions
diff --git a/net_if b/net_if
index dead89f..f2f1d31 100755
--- a/net_if
+++ b/net_if
@@ -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);