diff options
-rw-r--r-- | SiteSummary.pm | 90 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rwxr-xr-x | sitesummary-nodes | 12 |
3 files changed, 68 insertions, 41 deletions
diff --git a/SiteSummary.pm b/SiteSummary.pm index e9f2a93..3d13334 100644 --- a/SiteSummary.pm +++ b/SiteSummary.pm @@ -123,12 +123,13 @@ sub get_hostclass { sub get_primary_ip_address { my $hostid = shift; my $path = get_filepath_current($hostid, "/system/ifconfig-a"); - # XXX Not properly implemented, just pick the first IP + # XXX Not properly implemented, just pick the first non-local IP my $ip; if (open (FILE, $path)) { while(<FILE>) { chomp; - if (m/inet addr:(\S+)\s+/) { + if ((m/inet addr:(\S+)\s+/ || m/\s*inet\s+(\S+)\s+/) + && "127.0.0.1" ne $1) { $ip = $1; last; } @@ -142,22 +143,47 @@ sub get_primary_ip_address { # # Return all MAC addresses -sub get_macaddresses { - my $hostid = shift; - my $path = get_filepath_current($hostid, "/system/ifconfig-a"); - if (open (FILE, $path)) { - my @macs; - while(<FILE>) { - chomp; - if (m/Link encap:Ethernet\s+HWaddr (\S+)\s+/) { - push(@macs, $1); +sub get_macaddresses_from_ifconfig { + my $ifconfigoutput = shift; + my %macs; + open(IFCONFIG, $ifconfigoutput) || return (); + my $line = ""; + while (<IFCONFIG>) { + chomp; + if (m/^(\w+)\s+Link encap:Ethernet HWaddr (\S+)/) { + # Old ifconfig format + $macs{$1} = $2; + while (<IFCONFIG>) { + chomp; + last if (/^\s*$/); + } + } elsif (m/flags=/) { + # New ifconfig format + my $line = $_; + while (<IFCONFIG>) { + chomp; + $line .= $_; + last if (/^\s*$/); + } + if ($line =~ m/^(\S+): .+\sether\s+(\S+)\s/) { + $macs{$1} = $2; } } - close(FILE); - return @macs; - } else { - return undef; } + close (IFCONFIG); + my $if = (sort keys %macs)[0]; + my $mac = $macs{$if}; + return lc("$mac"); + + return undef; +} + +# +# Return all MAC addresses +sub get_macaddresses { + my $hostid = shift; + my $path = get_filepath_current($hostid, "/system/ifconfig-a"); + return get_macaddresses_from_ifconfig($path); } # Return current default route used on host @@ -177,22 +203,13 @@ sub get_default_route { } # -# Return the IP address on the primary network interface +# Return the MAC address on the primary network interface # sub get_primary_macaddress { my $hostid = shift; my $path = get_filepath_current($hostid, "/system/ifconfig-a"); - # XXX Not properly implemented, just pick the first MAC after - # sorting alphabetically. - if (open (FILE, $path)) { - my @macs; - while(<FILE>) { - chomp; - if (m/Link encap:Ethernet\s+HWaddr (\S+)\s+/) { - push(@macs, $1); - } - } - close(FILE); + my @macs = get_macaddresses_from_ifconfig($path); + if (@macs) { return (sort @macs)[0]; } else { return undef; @@ -207,20 +224,13 @@ sub get_primary_macaddress { # sub get_unique_ether_id { my $ifconfigoutput = shift; - my $eth0mac; - my $eth1mac; - my $eth2mac; - open(IFCONFIG, $ifconfigoutput) || return undef; - while (<IFCONFIG>) { - chomp; - $eth0mac = $1 if (m/^eth0\s+Link encap:Ethernet HWaddr (\S+)/); - $eth1mac = $1 if (m/^eth1\s+Link encap:Ethernet HWaddr (\S+)/); - $eth2mac = $1 if (m/^eth2\s+Link encap:Ethernet HWaddr (\S+)/); + my @macs = get_macaddresses_from_ifconfig($ifconfigoutput); + if (@macs) { + my $mac = (sort @macs)[0]; + return lc("ether-$mac"); + } else { + return undef; } - close (IFCONFIG); - #print STDERR "MAC: $eth0mac\n"; - my $mac = $eth0mac || $eth1mac || $eth2mac || "unknown"; - return lc("ether-$mac"); } # diff --git a/debian/changelog b/debian/changelog index 4b5b4c3..3943ed9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +sitesummary (0.1.25+nmu1) UNRELEASED; urgency=medium + + * Adjust parser for collected information to handle the new ifconfig + output format (Closes: #832342). + + -- Petter Reinholdtsen <pere@debian.org> Sat, 26 Nov 2016 17:31:59 +0100 + sitesummary (0.1.25) unstable; urgency=medium [ Wolfgang Schweer ] diff --git a/sitesummary-nodes b/sitesummary-nodes index a889fe7..a554fa9 100755 --- a/sitesummary-nodes +++ b/sitesummary-nodes @@ -145,7 +145,17 @@ sub is_remote_nagios_client { sub get_switch_info { my $hostid = shift; my %switch = (); - for my $if (qw(eth0 eth1)) { + my $ifconfigoutput = get_filepath_current($hostid, "/system/ifconfig-a"); + my %ifs; + open(IFCONFIG, $ifconfigoutput) || return (); + while (<IFCONFIG>) { + chomp; + $ifs{$1} = 1 + if (m/^(\w+)\s+Link encap:Ethernet HWaddr (\S+)/ + || m/^(\w+): flags=\S+<UP,BROADCAST/); + } + close (IFCONFIG); + for my $if (sort keys %ifs) { my $path = get_filepath_current($hostid, "/system/cdpr.$if"); my ($id, $addr); if (open(my $fh, $path)) { |