[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#832342: sitesummary: SiteSummary.pm fails to extract information w/ recent stretch linux-images



The following patch get rid fo the hardcoded eth0/eth1 entries in sitesummary.

I am unsure what ordering should be used to avoid using interfaces like virbr0
when deciding how to identify a machine.

diff --git a/SiteSummary.pm b/SiteSummary.pm
index e9f2a93..ad90031 100644
--- a/SiteSummary.pm
+++ b/SiteSummary.pm
@@ -207,19 +207,15 @@ sub get_primary_macaddress {
 #
 sub get_unique_ether_id {
     my $ifconfigoutput = shift;
-    my $eth0mac;
-    my $eth1mac;
-    my $eth2mac;
+    my %macs;
     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+)/);
+        $macs{$1} = $2 if (m/^(\w+)\s+Link encap:Ethernet  HWaddr (\S+)/);
     }
     close (IFCONFIG);
-    #print STDERR "MAC: $eth0mac\n";
-    my $mac = $eth0mac || $eth1mac || $eth2mac || "unknown";
+    my $if = (sort keys %macs)[0];
+    my $mac = $macs{$if};
     return lc("ether-$mac");
 }
 
diff --git a/sitesummary-nodes b/sitesummary-nodes
index a889fe7..cb9108e 100755
--- a/sitesummary-nodes
+++ b/sitesummary-nodes
@@ -145,7 +145,15 @@ 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} = $2 if (m/^(\w+)\s+Link encap:Ethernet  HWaddr (\S+)/);
+    }
+    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)) {


Reply to: