Subversion Repositories camp_sysinfo_client_3

Rev

Rev 26 | Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl
use warnings;
use strict;  

our $VERSION = '1.1';

# Linux network module for sysinfo client
# Author: R. W. Rodolico
# Date:   2016-04-08

# module to get network interface information for Linux systems
# assumes ifconfig is on the system and executable by the user
# NOTE: this takes the ifconfig output and parses it, so changes to 
#       this output invalidates this module

BEGIN {
   push @INC, shift;
}

use library;

my $command = &validCommandOnSystem('/sbin/ifconfig');

exit 1 unless $command;

my $CATEGORY = 'network';
# eth1      Link encap:Ethernet  HWaddr 00:16:3E:1F:EF:4F
my $regexHWADDR = 'hwaddr[^0-9a-f:]+([0-9a-f:]+)[^0-9a-f:]';
# inet addr:10.110.110.2  Bcast:10.110.110.255  Mask:255.255.255.0
my $regexINET = 'inet addr:\s*([0-9.]+)[^0-9].*mask:([0-9.]+)';
# inet6 addr: fe80::216:3eff:fe1f:ef4f/64 Scope:Link
my $regexINET6 = 'inet6 addr: ([0-9a-f:]+)\/([0-9]+)[^0-9]';
# UP LOOPBACK RUNNING  MTU:16436  Metric:1
my $regexMTU = 'mtu:([0-9]+)[^0-9]';
my $temp = qx/$command/;
my @temp = split( "\n", $temp );
my $currentIF;
while ( @temp ) {
   my $line = shift @temp;
   next unless $line;
   if ( $line =~ m/^([^ ]+) /) { # if the first character is not a space, starting new entry
      $currentIF = $1;
      if ( $line =~ m/$regexHWADDR/i ) {
         print "$CATEGORY\t$currentIF\tmac\t$1\n";
      } else {
         print "$CATEGORY\t$currentIF\tmac\tunknown\n";
      }
   } elsif ( $line =~ m/$regexINET/i ) {
      print "$CATEGORY\t$currentIF\taddress\t$1\n";
      print "$CATEGORY\t$currentIF\tnetmask\t$2\n";
   } elsif ( $line =~ m/$regexINET6/i )  {
      print "$CATEGORY\t$currentIF\tip6address\t$1\n";
      print "$CATEGORY\t$currentIF\tip6networkbits\t$2\n";
   } elsif ( $line =~ m/$regexMTU/i )  {
      print "$CATEGORY\t$currentIF\tmtu\t$1\n";
   }
}