--- /usr/src/redhat/BUILD/ocsinventory-fermi-0.9.9/ocsinventory-client.pl 2016-02-15 10:52:37.726625000 -0600 +++ ocsinventory-client.pl 2016-02-15 11:07:00.000000000 -0600 @@ -168,6 +168,7 @@ #Setting binaries locations my $dmidecode_path = &_get_path('dmidecode'); my $ifconfig_path = &_get_path('ifconfig'); +my $ip_path = &_get_path('ip'); #my $ipdiscover_path = &_get_path('ipdiscover'); my $ipdiscover_path = 'ipdiscover'; my $route_path = &_get_path('route'); @@ -183,6 +184,7 @@ #Get the binaries output #ifconfig my @ifconfig = `env LANGUAGE=us $ifconfig_path`; +my @ip_addr = `env LANGUAGE=us $ip_path addr`; #dmidecode my @dmidecode = `env LANGUAGE=us $dmidecode_path`; # Remove spaces at the beginning of lines @@ -337,12 +339,16 @@ $PhysicalMemory=$1 if /^memtotal\s*:\s*(\S+)/i; $SwapFileSize=$1 if /^swaptotal\s*:\s*(\S+)/i; } - - # Looking for ip addresses with ifconfig, except loopback - for(@ifconfig){ - if(/^\s*inet add?r\s*:\s*(\S+)/){ - ($1=~/127.+/)?next:push @ip, $1 - }; + for(@ip_addr){ + if(/^\s*inet \s*(\S+)/){ + if (/127.+/){ + next + } + else{ + $1 =~ /^(.*)\// ; + push @ip, $1 ; + } + } } $ip=join "/", @ip; @@ -503,70 +509,82 @@ } # Retrieving network settings - for $line (@ifconfig){ + my $e ; + $flag = 0 ; + #Switching from ifconfig to ip because more consistent between releases + for $line (@ip_addr){ + #print "line: " . $line . "\n" ; + #Search for next entry , formated as d: + #Entry num is $n , reset flag + if ($line =~ /^(\d+):/ ) { + $e = $1 ; + # print "eeeee: " . $e . "\n" ; + $flag = 0 ; + } + #Only care about some interfaces indicated by $flag #if($line =~ /^([eai](m|b|th)\S+)/i){ #Added np2s for minnowboard if($line =~ /([eai](m|b|th|np2s)(\d+)):/i){ defined($n)?($n++):($n = 0); $request{'CONTENT'}{'NETWORKS'}[$n]{'DESCRIPTION'} = [ $1 ]; push @values, $1; + # print "interface: " . $1 . "\n"; + #Care about this interface $flag = 1; - # Looking for dhcp server IP in a lease declaration (using /var/lib/dhcp/dhclient.leases) - if(-e "/var/lib/dhcp/dhclient-" . $1 . ".leases" ){ - open DHCP, "/var/lib/dhcp/dhclient-" . $1 . ".leases"; - while(<DHCP>){ - $lease = 1 if(/lease\s*{/i); - $lease = 0 if(/^\s*}\s*$/); - #Interface name - if(/interface\s+"(.+?)"\s*/ and $lease){ - ($1=~ /@{$request{'CONTENT'}{'NETWORKS'}[$n]{'DESCRIPTION'}}/i)?($dhcp = 1):($dhcp = 0); - } - #Server IP - if(/option\s+dhcp-server-identifier\s+(\d{1,3}(?:\.\d{1,3}){3})\s*;/ and $dhcp and $lease){ - $request{'CONTENT'}{'NETWORKS'}[$n]{'IPDHCP'} = [ $1 ]; - push @values, $1; - } - } - close(DHCP); - } + if($line =~ /\s*,UP,/i ){ + $request{'CONTENT'}{'NETWORKS'}[$n]{'STATUS'}= [ 'Up' ]; + } } - if($line =~ /^lo/){$flag = 0; next;} - if (!$request{'CONTENT'}{'NETWORKS'}[$n]{IPGATEWAY} and $flag){ - $request{'CONTENT'}{'NETWORKS'}[$n]{IPGATEWAY} = [ $gateway ]; - push @values, $gateway; + if( ! $flag ) { + #We can skip lines until we hit the next "entry" head line + next ; + } + #print "flag: " . $flag . "\n" ; + if (!$request{'CONTENT'}{'NETWORKS'}[$n]{IPGATEWAY} ){ + $request{'CONTENT'}{'NETWORKS'}[$n]{IPGATEWAY} = [ $gateway ]; + # print "gateway: " . $gateway . "\n"; + push @values, $gateway; }; - if($line =~ /(link|lien) encap:(\S+)/i && $flag){ - $request{'CONTENT'}{'NETWORKS'}[$n]{'TYPE'}= [ $2 ]; - push @values, $2; + if($line =~ /link\/(ether) (\S+)/i ){ + $request{'CONTENT'}{'NETWORKS'}[$n]{'TYPE'}= [ 'Ethernet']; + push @values, [ 'Ethernet']; + # print "type: " . "Ethernet" . "\n"; + + $request{'CONTENT'}{'NETWORKS'}[$n]{'MACADDR'}= [ $2 ]; + push @values, $2; + # print "mac: " . $2 . "\n"; }; - if($line =~ /hwadd?r\s+(\S+)/i && $flag){ - $request{'CONTENT'}{'NETWORKS'}[$n]{'MACADDR'}= [ $1 ]; - push @values, $1; + if($line =~ /inet6 (\S+)/i ){ + my $ipv6 = $1 ; + if($line =~ /scope global/ ){ + #we are borrowing IPDHCP as not using for DHCP + $request{'CONTENT'}{'NETWORKS'}[$n]{'IPDHCP'} = [ $ipv6]; + + push @values, $ipv6; + # print "ipv6: " . $ipv6 . "\n"; + } }; - if($line =~ /inet add?r:(\S+)/i && $flag){ + if($line =~ /inet (\S+)/i ){ + #ip addr does not show netmask so convert cidr + my($network, $netbit) = split m'/', $1; + # print "netbit: " . $netbit . "\n"; + + # Decimal representation of mask + my $mask = (2 ** $netbit - 1) << (32 - $netbit); + # convert decimal representation to our familiar form + my $netmask = join( '.', unpack( "C4", pack( "N", $mask ))); + $request{'CONTENT'}{'NETWORKS'}[$n]{'IPMASK'}= [ $netmask ]; + push @values, $netmask; + # print "ipmask: " . $netmask . "\n"; + + #ip addr returns ipaddress/netmask so have to remove /net + $1 =~ /^(.*)\// ; $request{'CONTENT'}{'NETWORKS'}[$n]{'IPADDRESS'}= [ $1 ]; push @values, $1; + # print "inet: " . $1 . "\n"; }; - if($line =~ /\S*mas(?:k|que):(\S+)/i && $flag){ - $request{'CONTENT'}{'NETWORKS'}[$n]{'IPMASK'}= [ $1 ]; - push @values, $1; - }; - if($line =~ /^\s*UP/i && $flag){ - $request{'CONTENT'}{'NETWORKS'}[$n]{'STATUS'}= [ 'Up' ]; - } - # Retrieving ip of the subnet for each interface - if($request{'CONTENT'}{'NETWORKS'}[$n]{'IPMASK'}[0] - and $request{'CONTENT'}{'NETWORKS'}[$n]{'IPADDRESS'}[0] - and !$request{'CONTENT'}{'NETWORKS'}[$n]{'IPSUBNET'}[0]){ - # To retrieve the subnet for this iface -#CJS my $binip = &ip_iptobin ($request{'CONTENT'}{'NETWORKS'}[$n]{'IPADDRESS'}[0] ,4); -#CJS my $binmask = &ip_iptobin ($request{'CONTENT'}{'NETWORKS'}[$n]{'IPMASK'}[0] ,4); -#CJS my $subnet = $binip & $binmask; -#CJS $request{'CONTENT'}{'NETWORKS'}[$n]{'IPSUBNET'} = [ ip_bintoip($subnet,4) ] or warn(Error()); - push @values, $request{'CONTENT'}{'NETWORKS'}[$n]{'IPSUBNET'}[0]; - } } #Checksum &_has_changed('networks', md5_base64(@values)); @@ -905,8 +923,8 @@ my @liclines ; my $comm = '' ; my $lic = '' ; - my @dir_search_matlab = ('/usr/local/matlab/','/usr/local/MATLAB/','/usr/local/Matlab','/usr/Matlab/') ; - my $dir = ''; + my @dir_search_matlab = ('/usr/local/matlab/','/usr/local/MATLAB/','/usr/local/Matlab','/usr/Matlab/') ; + my $dir = ''; my @dir_found ; my @foundfiles; #Find matlab dirs