[Fusioninventory-commit] [fusinv/fusioninventory-agent-task-snmpquery] 3108cf: version bump

Guillaume Rousse guillomovitch at gmail.com
Wed May 2 21:40:27 UTC 2012


  Branch: refs/heads/master
  Home:   https://github.com/fusinv/fusioninventory-agent-task-snmpquery
  Commit: 3108cf43474fca732262b2ed4e2751fc5ef8a5d0
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/3108cf43474fca732262b2ed4e2751fc5ef8a5d0
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-04-25 (Wed, 25 Apr 2012)

  Changed paths:
    M lib/FusionInventory/Agent/Task/NetInventory.pm

  Log Message:
  -----------
  version bump


diff --git a/lib/FusionInventory/Agent/Task/NetInventory.pm b/lib/FusionInventory/Agent/Task/NetInventory.pm
index 51be473..49a617f 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory.pm
@@ -19,7 +19,7 @@ use FusionInventory::Agent::XML::Query;
 use FusionInventory::Agent::Tools;
 use FusionInventory::Agent::Tools::Network;
 
-our $VERSION = '2.1';
+our $VERSION = '2.2.0';
 
 # list of devices properties, indexed by XML element name
 # the link to a specific OID is made by the model


================================================================
  Commit: 81b3467da576864ec0821bc9347718492aa30e36
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/81b3467da576864ec0821bc9347718492aa30e36
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-04-25 (Wed, 25 Apr 2012)

  Changed paths:
    M Changes

  Log Message:
  -----------
  replace tabs with spaces


diff --git a/Changes b/Changes
index 9b6a914..8e414d8 100644
--- a/Changes
+++ b/Changes
@@ -7,10 +7,10 @@ Revision history for FusionInventory::Agent::Task::NetInventory
         * Avoid various warnings
 
 2.0     Mon, 09 Apr 2012 13:49:34 +0200
-	* adaptation to FusionInventory 2.2
-	* large code cleanup
-	* simplify and harmonize parallelism handling
-	* rename to NetInventory
+        * adaptation to FusionInventory 2.2
+        * large code cleanup
+        * simplify and harmonize parallelism handling
+        * rename to NetInventory
 
 1.3
        * Drop the --local mode


================================================================
  Commit: 2d9cc02e2699eaaf256abefe4763d64fc067e503
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/2d9cc02e2699eaaf256abefe4763d64fc067e503
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-04-26 (Thu, 26 Apr 2012)

  Changed paths:
    M Changes

  Log Message:
  -----------
  prepare for 2.2.0 release


diff --git a/Changes b/Changes
index 8e414d8..f250d76 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,13 @@
 Revision history for FusionInventory::Agent::Task::NetInventory
 
+2.2.0   Thu, 26 Apr
+        * standalone binary for inventory without server
+        * send results to the server on the fly, not after all devices have
+          been processes
+        * fix connected devices mac address retrieval for non-cisco hardware
+        * fix output format for multiple connected devices mac address
+        * fix broken 3Com module
+
 2.1     Thu, 12 Apr 2012 21:02:51 +0200
         * Fix cartridges level inventory
         * Fix printer ports inventory


================================================================
  Commit: d3d0531ce356bdbe5bf506dafcd1d78f5422cdfa
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/d3d0531ce356bdbe5bf506dafcd1d78f5422cdfa
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-04-26 (Thu, 26 Apr 2012)

  Changed paths:
    M README

  Log Message:
  -----------
  fix Gonéri address


diff --git a/README b/README
index 7901844..33071b5 100644
--- a/README
+++ b/README
@@ -29,7 +29,7 @@ Additional mandatory perl modules:
 Authors 
 -------
 * David Durieux <d.durieux at siprossii.com>
-* Gonéri Le Bouder <goneri at rulezlan.org>>
+* Gonéri Le Bouder <goneri at rulezlan.org>
 * Guillaume Rousse <guillomovitch at gmail.com>
 
 Copyright 2009-2012 FusionInventory Team


================================================================
  Commit: 0232c0217a4e1056bead58281f9b7769d5325d7a
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/0232c0217a4e1056bead58281f9b7769d5325d7a
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-04-26 (Thu, 26 Apr 2012)

  Changed paths:
    A t/05var.t
    R t/05var.t
    A t/output.t
    R t/output.t

  Log Message:
  -----------
  fix perms


diff --git a/t/05var.t b/t/05var.t
old mode 100644
new mode 100755
diff --git a/t/output.t b/t/output.t
old mode 100644
new mode 100755


================================================================
  Commit: 2dac5917f3ec2f183a7aa1745b7bc86991d57422
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/2dac5917f3ec2f183a7aa1745b7bc86991d57422
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-05-02 (Wed, 02 May 2012)

  Changed paths:
    M lib/FusionInventory/Agent/Task/NetInventory.pm
    M lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Cisco.pm
    A lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
    M lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm

  Log Message:
  -----------
  Merge remote-tracking branch 'forge/master'


diff --git a/lib/FusionInventory/Agent/Task/NetInventory.pm b/lib/FusionInventory/Agent/Task/NetInventory.pm
index 49a617f..c14f59b 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory.pm
@@ -115,13 +115,17 @@ my @ports_dispatch_table = (
     {
         match   => qr/ProCurve/,
         trunk   => __PACKAGE__ . '::Manufacturer::Cisco',
-        devices => __PACKAGE__ . '::Manufacturer::ProCurve',
+        devices => __PACKAGE__ . '::Manufacturer::Procurve',
     },
     {
         match   => qr/Nortel/,
         trunk   => __PACKAGE__ . '::Manufacturer::Nortel',
         devices => __PACKAGE__ . '::Manufacturer::Nortel',
     },
+    {
+        match   => qr/Juniper/,
+        devices => __PACKAGE__ . '::Manufacturer::Juniper',
+    }
 );
 
 my @mac_dispatch_table = (
@@ -137,7 +141,7 @@ my @mac_dispatch_table = (
     },
     {
         match    => qr/ProCurve/,
-        module   => __PACKAGE__ . '::Manufacturer::ProCurve',
+        module   => __PACKAGE__ . '::Manufacturer::Procurve',
         function => 'setConnectedDevicesMacAddress'
     },
     {
@@ -149,6 +153,11 @@ my @mac_dispatch_table = (
         match    => qr/Allied Telesis/,
         module   => __PACKAGE__ . '::Manufacturer::AlliedTelesis',
         function => 'setConnectedDevicesMacAddress'
+    },
+    {
+        match    => qr/Juniper/,
+        module   => __PACKAGE__ . '::Manufacturer::Juniper',
+        function => 'setConnectedDevicesMacAddress'
     }
 );
 
@@ -643,12 +652,14 @@ sub _setNetworkingProperties {
         foreach my $entry (@ports_dispatch_table) {
             next unless $comments =~ $entry->{match};
 
-            runFunction(
-                module   => $entry->{trunk},
-                function => 'setTrunkPorts',
-                params   => { results => $results, ports => $ports },
-                load     => 1
-            );
+            if (defined $entry->{trunk}) {
+                runFunction(
+                    module   => $entry->{trunk},
+                    function => 'setTrunkPorts',
+                    params   => { results => $results, ports => $ports },
+                    load     => 1
+                );
+            }
 
             runFunction(
                 module   => $entry->{devices},
diff --git a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Cisco.pm b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Cisco.pm
index 4bd383a..5753105 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Cisco.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Cisco.pm
@@ -39,6 +39,9 @@ sub setConnectedDevicesMacAddress {
         # this device has already been processed through CDP/LLDP
         next if $port->{CONNECTIONS}->{CDP};
 
+        # This mac is empty
+        next unless $mac;
+
         $mac = alt2canonical($mac);
 
         # this is port own mac address
diff --git a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
new file mode 100644
index 0000000..c5b3c69
--- /dev/null
+++ b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
@@ -0,0 +1,156 @@
+package FusionInventory::Agent::Task::NetInventory::Manufacturer::Juniper;
+
+use strict;
+use warnings;
+
+use FusionInventory::Agent::Tools::Network;
+use FusionInventory::Agent::SNMP qw(getElement getLastElement getNextToLastElement);
+    
+sub setConnectedDevicesMacAddress {
+    my (%params) = @_;
+
+    my $results = $params{results};
+    my $ports   = $params{ports};
+    my $walks   = $params{walks};
+
+    while (my ($oid, $suffix) = each %{$results->{dot1dTpFdbAddress}}) {
+
+        my $mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", getElement($oid, -6), 
+                          getElement($oid, -5),  
+                          getElement($oid, -4), 
+                          getElement($oid, -3), 
+                          getElement($oid, -2), 
+                          getElement($oid, -1)); 
+
+        my $dot1dTpFdbPort = $walks->{dot1dTpFdbPort}->{OID};
+
+        my $portKey = $dot1dTpFdbPort . '.' . $suffix;
+        my $ifKey_part = $results->{dot1dTpFdbPort}->{$portKey};
+        next unless defined $ifKey_part;
+
+        my $ifIndex =
+            $results->{dot1dBasePortIfIndex}->{
+                $walks->{dot1dBasePortIfIndex}->{OID} . '.' .  $ifKey_part
+            };
+        next unless defined $ifIndex;
+
+        my $port = $ports->{$ifIndex};
+
+        # this device has already been processed through CDP/LLDP
+        next if $port->{CONNECTIONS}->{CDP};
+
+        # This mac is empty
+        next unless $mac;
+
+        # this is port own mac address
+        next if $port->{MAC} eq $mac;
+
+        # create a new connection with this mac address
+        push
+            @{$port->{CONNECTIONS}->{CONNECTION}->{MAC}},
+            $mac;
+    }
+}
+
+sub setConnectedDevices {
+    my (%params) = @_;
+
+    my $results = $params{results};
+    my $ports   = $params{ports};
+    my $walks   = $params{walks};
+
+    if (ref $results->{cdpCacheAddress} eq 'HASH') {
+        while (my ($oid, $ip_hex) = each %{$results->{cdpCacheAddress}}) {
+            my $ip = hex2canonical($ip_hex);
+            next if $ip eq '0.0.0.0';
+
+            my $port_number =
+                getNextToLastElement($oid) . "." . getLastElement($oid, -1);
+                
+            $ports->{getNextToLastElement($oid)}->{CONNECTIONS} = {
+                CDP        => 1,
+                CONNECTION => {
+                    IP      => $ip,
+                    IFDESCR => $results->{cdpCacheDevicePort}->{
+                        $walks->{cdpCacheDevicePort}->{OID} . "." .$port_number
+                    },
+                    SYSDESCR => $results->{cdpCacheVersion}->{
+                        $walks->{cdpCacheVersion}->{OID} . "." .$port_number
+                    },
+                    SYSNAME  => $results->{cdpCacheDeviceId}->{
+                        $walks->{cdpCacheDeviceId}->{OID} . "." .$port_number
+                    },
+                    MODEL => $results->{cdpCachePlatform}->{
+                        $walks->{cdpCachePlatform}->{OID} . "." .$port_number
+                    }
+                }
+            };
+        }
+    } elsif (ref $results->{lldpRemChassisId} eq 'HASH') {
+        while (my ($oid, $sysmac) = each %{$results->{lldpRemChassisId}}) {
+
+            my $port_number =
+                getElement($oid, -3) . "." . getNextToLastElement($oid) . "." . getLastElement($oid, -1);
+
+            $ports->{getNextToLastElement($oid)}->{CONNECTIONS} = {
+                CDP        => 1,
+                CONNECTION => {
+                    SYSMAC => alt2canonical($sysmac),
+                    IFDESCR => $results->{lldpRemPortDesc}->{
+                        $walks->{lldpRemPortDesc}->{OID} . "." . $port_number
+                    },
+                    SYSDESCR => $results->{lldpRemSysDesc}->{
+                        $walks->{lldpRemSysDesc}->{OID} . "." .$port_number
+                    },
+                    SYSNAME  => $results->{lldpRemSysName}->{
+                        $walks->{lldpRemSysName}->{OID} . "." .$port_number
+                    },
+                    IFNUMBER => $results->{lldpRemPortId}->{
+                        $walks->{lldpRemPortId}->{OID} . "." .$port_number
+                    }
+                }
+            };
+        }
+    }
+}
+
+1;
+__END__
+
+=head1 NAME
+
+FusionInventory::Agent::Task::NetInventory::Manufacturer::Procurve - Procurve-specific functions
+
+=head1 DESCRIPTION
+
+This is a class defining some functions specific to Procurve hardware.
+
+=head1 FUNCTIONS
+
+=head2 setConnectedDevicesMacAddress(%params)
+
+Set mac addresses of connected devices.
+
+=over
+
+=item results raw values collected through SNMP
+
+=item ports device ports list
+
+=item walks model walk branch
+
+=back
+
+=head2 setConnectedDevices(%params)
+
+Set connected devices, through CDP or LLDP.
+
+=over
+
+=item results raw values collected through SNMP
+
+=item ports device ports list
+
+=item walks model walk branch
+
+=back
diff --git a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm
index 862fb5c..d51d1a7 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use FusionInventory::Agent::Tools::Network;
-use FusionInventory::Agent::SNMP qw(getLastElement getNextToLastElement);
+use FusionInventory::Agent::SNMP qw(getElement getLastElement getNextToLastElement);
     
 sub setConnectedDevicesMacAddress {
     my (%params) = @_;
@@ -35,6 +35,9 @@ sub setConnectedDevicesMacAddress {
         # this device has already been processed through CDP/LLDP
         next if $port->{CONNECTIONS}->{CDP};
 
+        # This mac is empty
+        next unless $mac;
+
         $mac = alt2canonical($mac);
 
         # this is port own mac address
@@ -59,35 +62,49 @@ sub setConnectedDevices {
             my $ip = hex2canonical($ip_hex);
             next if $ip eq '0.0.0.0';
 
-            my $port_number = getNextToLastElement($oid);
-
-            $ports->{$port_number}->{CONNECTIONS} = {
+            my $port_number =
+                getNextToLastElement($oid) . "." . getLastElement($oid, -1);
+                
+            $ports->{getNextToLastElement($oid)}->{CONNECTIONS} = {
                 CDP        => 1,
                 CONNECTION => {
                     IP      => $ip,
                     IFDESCR => $results->{cdpCacheDevicePort}->{
-                        $walks->{cdpCacheDevicePort}->{OID} . $port_number
+                        $walks->{cdpCacheDevicePort}->{OID} . "." .$port_number
+                    },
+                    SYSDESCR => $results->{cdpCacheVersion}->{
+                        $walks->{cdpCacheVersion}->{OID} . "." .$port_number
+                    },
+                    SYSNAME  => $results->{cdpCacheDeviceId}->{
+                        $walks->{cdpCacheDeviceId}->{OID} . "." .$port_number
+                    },
+                    MODEL => $results->{cdpCachePlatform}->{
+                        $walks->{cdpCachePlatform}->{OID} . "." .$port_number
                     }
                 }
             };
         }
-    }
-
-    if (ref $results->{lldpCacheAddress} eq 'HASH') {
-        while (my ($oid, $chassisname) = each %{$results->{lldpCacheAddress}}) {
+    } elsif (ref $results->{lldpRemChassisId} eq 'HASH') {
+        while (my ($oid, $sysmac) = each %{$results->{lldpRemChassisId}}) {
 
             my $port_number =
-                getNextToLastElement($oid) . "." . getLastElement($oid, -1);
-
-            # already done through CDP 
-            next if $ports->{getNextToLastElement($oid)}->{CONNECTIONS};
+                getElement($oid, -3) . "." . getNextToLastElement($oid) . "." . getLastElement($oid, -1);
 
             $ports->{getNextToLastElement($oid)}->{CONNECTIONS} = {
                 CDP        => 1,
                 CONNECTION => {
-                    SYSNAME => $chassisname,
-                    IFDESCR => $results->{lldpCacheDevicePort}->{
-                        $walks->{lldpCacheDevicePort}->{OID} . "." . $port_number
+                    SYSMAC => alt2canonical($sysmac),
+                    IFDESCR => $results->{lldpRemPortDesc}->{
+                        $walks->{lldpRemPortDesc}->{OID} . "." . $port_number
+                    },
+                    SYSDESCR => $results->{lldpRemSysDesc}->{
+                        $walks->{lldpRemSysDesc}->{OID} . "." .$port_number
+                    },
+                    SYSNAME  => $results->{lldpRemSysName}->{
+                        $walks->{lldpRemSysName}->{OID} . "." .$port_number
+                    },
+                    IFNUMBER => $results->{lldpRemPortId}->{
+                        $walks->{lldpRemPortId}->{OID} . "." .$port_number
                     }
                 }
             };


================================================================
  Commit: 3933b3c560a1d6b890f9f7b1557149e3ab020c86
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/3933b3c560a1d6b890f9f7b1557149e3ab020c86
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-05-02 (Wed, 02 May 2012)

  Changed paths:
    M lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
    M lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm

  Log Message:
  -----------
  cosmetics: spacing


diff --git a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
index c5b3c69..9801267 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Juniper.pm
@@ -5,7 +5,7 @@ use warnings;
 
 use FusionInventory::Agent::Tools::Network;
 use FusionInventory::Agent::SNMP qw(getElement getLastElement getNextToLastElement);
-    
+
 sub setConnectedDevicesMacAddress {
     my (%params) = @_;
 
@@ -15,12 +15,12 @@ sub setConnectedDevicesMacAddress {
 
     while (my ($oid, $suffix) = each %{$results->{dot1dTpFdbAddress}}) {
 
-        my $mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", getElement($oid, -6), 
-                          getElement($oid, -5),  
-                          getElement($oid, -4), 
-                          getElement($oid, -3), 
-                          getElement($oid, -2), 
-                          getElement($oid, -1)); 
+        my $mac = sprintf("%02x:%02x:%02x:%02x:%02x:%02x", getElement($oid, -6),
+                          getElement($oid, -5),
+                          getElement($oid, -4),
+                          getElement($oid, -3),
+                          getElement($oid, -2),
+                          getElement($oid, -1));
 
         my $dot1dTpFdbPort = $walks->{dot1dTpFdbPort}->{OID};
 
@@ -30,7 +30,7 @@ sub setConnectedDevicesMacAddress {
 
         my $ifIndex =
             $results->{dot1dBasePortIfIndex}->{
-                $walks->{dot1dBasePortIfIndex}->{OID} . '.' .  $ifKey_part
+                $walks->{dot1dBasePortIfIndex}->{OID} . '.' . $ifKey_part
             };
         next unless defined $ifIndex;
 
@@ -66,22 +66,22 @@ sub setConnectedDevices {
 
             my $port_number =
                 getNextToLastElement($oid) . "." . getLastElement($oid, -1);
-                
+
             $ports->{getNextToLastElement($oid)}->{CONNECTIONS} = {
                 CDP        => 1,
                 CONNECTION => {
                     IP      => $ip,
                     IFDESCR => $results->{cdpCacheDevicePort}->{
-                        $walks->{cdpCacheDevicePort}->{OID} . "." .$port_number
+                        $walks->{cdpCacheDevicePort}->{OID} . "." . $port_number
                     },
                     SYSDESCR => $results->{cdpCacheVersion}->{
-                        $walks->{cdpCacheVersion}->{OID} . "." .$port_number
+                        $walks->{cdpCacheVersion}->{OID} . "." . $port_number
                     },
                     SYSNAME  => $results->{cdpCacheDeviceId}->{
-                        $walks->{cdpCacheDeviceId}->{OID} . "." .$port_number
+                        $walks->{cdpCacheDeviceId}->{OID} . "." . $port_number
                     },
                     MODEL => $results->{cdpCachePlatform}->{
-                        $walks->{cdpCachePlatform}->{OID} . "." .$port_number
+                        $walks->{cdpCachePlatform}->{OID} . "." . $port_number
                     }
                 }
             };
@@ -100,13 +100,13 @@ sub setConnectedDevices {
                         $walks->{lldpRemPortDesc}->{OID} . "." . $port_number
                     },
                     SYSDESCR => $results->{lldpRemSysDesc}->{
-                        $walks->{lldpRemSysDesc}->{OID} . "." .$port_number
+                        $walks->{lldpRemSysDesc}->{OID} . "." . $port_number
                     },
                     SYSNAME  => $results->{lldpRemSysName}->{
-                        $walks->{lldpRemSysName}->{OID} . "." .$port_number
+                        $walks->{lldpRemSysName}->{OID} . "." . $port_number
                     },
                     IFNUMBER => $results->{lldpRemPortId}->{
-                        $walks->{lldpRemPortId}->{OID} . "." .$port_number
+                        $walks->{lldpRemPortId}->{OID} . "." . $port_number
                     }
                 }
             };
diff --git a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm
index d51d1a7..9e3b4a7 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory/Manufacturer/Procurve.pm
@@ -26,7 +26,7 @@ sub setConnectedDevicesMacAddress {
 
         my $ifIndex =
             $results->{dot1dBasePortIfIndex}->{
-                $walks->{dot1dBasePortIfIndex}->{OID} . '.' .  $ifKey_part
+                $walks->{dot1dBasePortIfIndex}->{OID} . '.' . $ifKey_part
             };
         next unless defined $ifIndex;
 
@@ -64,22 +64,22 @@ sub setConnectedDevices {
 
             my $port_number =
                 getNextToLastElement($oid) . "." . getLastElement($oid, -1);
-                
+
             $ports->{getNextToLastElement($oid)}->{CONNECTIONS} = {
                 CDP        => 1,
                 CONNECTION => {
                     IP      => $ip,
                     IFDESCR => $results->{cdpCacheDevicePort}->{
-                        $walks->{cdpCacheDevicePort}->{OID} . "." .$port_number
+                        $walks->{cdpCacheDevicePort}->{OID} . "." . $port_number
                     },
                     SYSDESCR => $results->{cdpCacheVersion}->{
-                        $walks->{cdpCacheVersion}->{OID} . "." .$port_number
+                        $walks->{cdpCacheVersion}->{OID} . "." . $port_number
                     },
                     SYSNAME  => $results->{cdpCacheDeviceId}->{
-                        $walks->{cdpCacheDeviceId}->{OID} . "." .$port_number
+                        $walks->{cdpCacheDeviceId}->{OID} . "." . $port_number
                     },
                     MODEL => $results->{cdpCachePlatform}->{
-                        $walks->{cdpCachePlatform}->{OID} . "." .$port_number
+                        $walks->{cdpCachePlatform}->{OID} . "." . $port_number
                     }
                 }
             };
@@ -98,13 +98,13 @@ sub setConnectedDevices {
                         $walks->{lldpRemPortDesc}->{OID} . "." . $port_number
                     },
                     SYSDESCR => $results->{lldpRemSysDesc}->{
-                        $walks->{lldpRemSysDesc}->{OID} . "." .$port_number
+                        $walks->{lldpRemSysDesc}->{OID} . "." . $port_number
                     },
                     SYSNAME  => $results->{lldpRemSysName}->{
-                        $walks->{lldpRemSysName}->{OID} . "." .$port_number
+                        $walks->{lldpRemSysName}->{OID} . "." . $port_number
                     },
                     IFNUMBER => $results->{lldpRemPortId}->{
-                        $walks->{lldpRemPortId}->{OID} . "." .$port_number
+                        $walks->{lldpRemPortId}->{OID} . "." . $port_number
                     }
                 }
             };


================================================================
  Commit: 5ef1da91377b264290237afa5c1de475c46cbba0
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/5ef1da91377b264290237afa5c1de475c46cbba0
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-05-02 (Wed, 02 May 2012)

  Changed paths:
    M lib/FusionInventory/Agent/Task/NetInventory.pm

  Log Message:
  -----------
  isolate vendor-specific operations in a function


diff --git a/lib/FusionInventory/Agent/Task/NetInventory.pm b/lib/FusionInventory/Agent/Task/NetInventory.pm
index c14f59b..0b4a919 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory.pm
@@ -105,62 +105,6 @@ my %printer_pagecounters_properties = (
     FAXTOTAL   => 'pagecountertotalpages_fax',
 );
 
-
-my @ports_dispatch_table = (
-    {
-        match   => qr/Cisco/,
-        trunk   => __PACKAGE__ . '::Manufacturer::Cisco',
-        devices => __PACKAGE__ . '::Manufacturer::Cisco',
-    },
-    {
-        match   => qr/ProCurve/,
-        trunk   => __PACKAGE__ . '::Manufacturer::Cisco',
-        devices => __PACKAGE__ . '::Manufacturer::Procurve',
-    },
-    {
-        match   => qr/Nortel/,
-        trunk   => __PACKAGE__ . '::Manufacturer::Nortel',
-        devices => __PACKAGE__ . '::Manufacturer::Nortel',
-    },
-    {
-        match   => qr/Juniper/,
-        devices => __PACKAGE__ . '::Manufacturer::Juniper',
-    }
-);
-
-my @mac_dispatch_table = (
-    {
-        match    => qr/3Com IntelliJack/,
-        module   =>  __PACKAGE__ . '::Manufacturer::3Com',
-        function => 'RewritePortOf225'
-    },
-    {
-        match    => qr/3Com/,
-        module   => __PACKAGE__ . '::Manufacturer::3Com',
-        function => 'setConnectedDevicesMacAddress'
-    },
-    {
-        match    => qr/ProCurve/,
-        module   => __PACKAGE__ . '::Manufacturer::Procurve',
-        function => 'setConnectedDevicesMacAddress'
-    },
-    {
-        match    => qr/Nortel/,
-        module   => __PACKAGE__ . '::Manufacturer::Nortel',
-        function => 'setConnectedDevicesMacAddress'
-    },
-    {
-        match    => qr/Allied Telesis/,
-        module   => __PACKAGE__ . '::Manufacturer::AlliedTelesis',
-        function => 'setConnectedDevicesMacAddress'
-    },
-    {
-        match    => qr/Juniper/,
-        module   => __PACKAGE__ . '::Manufacturer::Juniper',
-        function => 'setConnectedDevicesMacAddress'
-    }
-);
-
 sub isEnabled {
     my ($self, $response) = @_;
 
@@ -647,32 +591,9 @@ sub _setNetworkingProperties {
     my $comments = $datadevice->{INFO}->{COMMENTS};
     my $ports = $datadevice->{PORTS}->{PORT};
 
-    # trunk & connected devices
-    if (defined $comments) {
-        foreach my $entry (@ports_dispatch_table) {
-            next unless $comments =~ $entry->{match};
-
-            if (defined $entry->{trunk}) {
-                runFunction(
-                    module   => $entry->{trunk},
-                    function => 'setTrunkPorts',
-                    params   => { results => $results, ports => $ports },
-                    load     => 1
-                );
-            }
-
-            runFunction(
-                module   => $entry->{devices},
-                function => 'setConnectedDevices',
-                params   => {
-                    results => $results, ports => $ports, walks => $walks
-                },
-                load     => 1
-            );
+    _setTrunkPorts($comments, $results, $ports) if $comments;
 
-            last;
-        }
-    }
+    _setConnectedDevices($comments, $results, $ports, $walks) if $comments;
 
     # Detect VLAN
     if ($results->{vmvlan}) {
@@ -693,6 +614,7 @@ sub _setNetworkingProperties {
         values %{$walks};
 
     if ($vlan_query) {
+        # set connected devices mac addresses for each VLAN
         while (my ($oid, $name) = each %{$results->{vtpVlanName}}) {
             my $vlan_id = getLastElement($oid);
             # initiate a new SNMP connection on this VLAN
@@ -723,41 +645,166 @@ sub _setNetworkingProperties {
                     $snmp->walk($variable->{OID});
             }
 
-            # Detect mac adress on each port
-            if ($comments =~ /Cisco/) {
-                my $module = 'FusionInventory::Agent::Task::NetInventory::Manufacturer::Cisco';
-                runFunction(
-                    module   => $module,
-                    function => 'setConnectedDevicesMacAddress',
-                    params   => {
-                        results => $results,
-                        ports   => $ports,
-                        walks   => $walks,
-                        vlan_id => $vlan_id
-                    },
-                    load     => 1
-                );
-            }
+            _setConnectedDevicesMacAddress(
+                $comments, $results, $ports, $walks, $vlan_id
+            ) if $comments;
         }
     } else {
-        if (defined $comments) {
-            foreach my $entry (@mac_dispatch_table) {
-                next unless $comments =~ $entry->{match};
-
-                runFunction(
-                    module   => $entry->{module},
-                    function => $entry->{function},
-                    params   => {
-                        results => $results, ports => $ports, walks => $walks
-                    },
-                    load     => 1
-                );
+        # set connected devices mac addresses only once
+        _setConnectedDevicesMacAddress($comments, $results, $ports, $walks)
+            if $comments;
+    }
 
-                last;
-            }
+    # hardware-specific hacks
+    _performSpecificCleanup($comments, $results, $ports) if $comments;
+}
+
+sub _setTrunkPorts {
+    my ($description, $results, $ports) = @_;
+
+    my @dispatch_table = (
+        {
+            match  => qr/Cisco/,
+            module => __PACKAGE__ . '::Manufacturer::Cisco',
+        },
+        {
+            match  => qr/ProCurve/,
+            module => __PACKAGE__ . '::Manufacturer::Cisco',
+        },
+        {
+            match  => qr/Nortel/,
+            module => __PACKAGE__ . '::Manufacturer::Nortel',
+        },
+    );
+
+    foreach my $entry (@dispatch_table) {
+        next unless $description =~ $entry->{match};
+
+        runFunction(
+            module   => $entry->{module},
+            function => 'setTrunkPorts',
+            params   => { results => $results, ports => $ports },
+            load     => 1
+        );
+
+        last;
+    }
+
+}
+
+sub _setConnectedDevices {
+    my ($description, $results, $ports, $walks) = @_;
+
+    my @dispatch_table = (
+        {
+            match  => qr/Cisco/,
+            module => __PACKAGE__ . '::Manufacturer::Cisco',
+        },
+        {
+            match  => qr/ProCurve/,
+            module => __PACKAGE__ . '::Manufacturer::Procurve',
+        },
+        {
+            match  => qr/Nortel/,
+            module => __PACKAGE__ . '::Manufacturer::Nortel',
+        },
+        {
+            match  => qr/Juniper/,
+            module => __PACKAGE__ . '::Manufacturer::Juniper',
+        }
+    );
+
+    foreach my $entry (@dispatch_table) {
+        next unless $description =~ $entry->{match};
+
+        runFunction(
+            module   => $entry->{module},
+            function => 'setConnectedDevices',
+            params   => {
+                results => $results, ports => $ports, walks => $walks
+            },
+            load     => 1
+        );
+
+        last;
+    }
+}
+
+sub _setConnectedDevicesMacAddresses {
+    my ($description, $results, $ports, $walks, $vlan_id) = @_;
+
+    my @dispatch_table = (
+        {
+            match    => qr/Cisco/,
+            module   => __PACKAGE__ . '::Manufacturer::Cisco',
+        },
+        {
+            match    => qr/3Com/,
+            module   => __PACKAGE__ . '::Manufacturer::3Com',
+        },
+        {
+            match    => qr/ProCurve/,
+            module   => __PACKAGE__ . '::Manufacturer::Procurve',
+        },
+        {
+            match    => qr/Nortel/,
+            module   => __PACKAGE__ . '::Manufacturer::Nortel',
+        },
+        {
+            match    => qr/Allied Telesis/,
+            module   => __PACKAGE__ . '::Manufacturer::AlliedTelesis',
+        },
+        {
+            match    => qr/Juniper/,
+            module   => __PACKAGE__ . '::Manufacturer::Juniper',
         }
+    );
+
+    foreach my $entry (@dispatch_table) {
+        next unless $description =~ $entry->{match};
+
+        runFunction(
+            module   => $entry->{module},
+            function => 'setConnectedDevicesMacAddress',
+            params   => {
+                results => $results,
+                ports   => $ports,
+                walks   => $walks,
+                vlan_id => $vlan_id
+            },
+            load     => 1
+        );
+
+        last;
     }
+}
+
+sub _performSpecificCleanup {
+    my ($description, $results, $ports, $walks) = @_;
 
+    my @dispatch_table = (
+        {
+            match    => qr/3Com IntelliJack/,
+            module   =>  __PACKAGE__ . '::Manufacturer::3Com',
+            function => 'RewritePortOf225'
+        },
+    );
+
+    foreach my $entry (@dispatch_table) {
+        next unless $description =~ $entry->{match};
+
+        runFunction(
+            module   => $entry->{module},
+            function => $entry->{function},
+            params   => {
+                results => $results,
+                ports   => $ports
+            },
+            load     => 1
+        );
+
+        last;
+    }
 }
 
 sub _getPercentValue {


================================================================
  Commit: 25513c56cdce75cb2f075b8f54fbfb8999b25624
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/25513c56cdce75cb2f075b8f54fbfb8999b25624
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-05-02 (Wed, 02 May 2012)

  Changed paths:
    M lib/FusionInventory/Agent/Task/NetInventory.pm

  Log Message:
  -----------
  test description earlier


diff --git a/lib/FusionInventory/Agent/Task/NetInventory.pm b/lib/FusionInventory/Agent/Task/NetInventory.pm
index 0b4a919..6c3b2e1 100644
--- a/lib/FusionInventory/Agent/Task/NetInventory.pm
+++ b/lib/FusionInventory/Agent/Task/NetInventory.pm
@@ -591,10 +591,6 @@ sub _setNetworkingProperties {
     my $comments = $datadevice->{INFO}->{COMMENTS};
     my $ports = $datadevice->{PORTS}->{PORT};
 
-    _setTrunkPorts($comments, $results, $ports) if $comments;
-
-    _setConnectedDevices($comments, $results, $ports, $walks) if $comments;
-
     # Detect VLAN
     if ($results->{vmvlan}) {
         while (my ($oid, $vlan_id) = each %{$results->{vmvlan}}) {
@@ -608,6 +604,13 @@ sub _setNetworkingProperties {
         }
     }
 
+    # everything else is vendor-specific, and requires device description
+    return unless $comments;
+
+    _setTrunkPorts($comments, $results, $ports);
+
+    _setConnectedDevices($comments, $results, $ports, $walks);
+
     # check if vlan-specific queries are is needed
     my $vlan_query =
         any { $_->{VLAN} }
@@ -647,16 +650,15 @@ sub _setNetworkingProperties {
 
             _setConnectedDevicesMacAddress(
                 $comments, $results, $ports, $walks, $vlan_id
-            ) if $comments;
+            );
         }
     } else {
         # set connected devices mac addresses only once
-        _setConnectedDevicesMacAddress($comments, $results, $ports, $walks)
-            if $comments;
+        _setConnectedDevicesMacAddress($comments, $results, $ports, $walks);
     }
 
     # hardware-specific hacks
-    _performSpecificCleanup($comments, $results, $ports) if $comments;
+    _performSpecificCleanup($comments, $results, $ports);
 }
 
 sub _setTrunkPorts {


================================================================
  Commit: 9c702276a932a6bd098c9af81d58fb0d0fdfe31d
      https://github.com/fusinv/fusioninventory-agent-task-snmpquery/commit/9c702276a932a6bd098c9af81d58fb0d0fdfe31d
  Author: Guillaume Rousse <guillomovitch at gmail.com>
  Date:   2012-05-02 (Wed, 02 May 2012)

  Changed paths:
    A t/dispatch.t

  Log Message:
  -----------
  initial import


diff --git a/t/dispatch.t b/t/dispatch.t
new file mode 100644
index 0000000..c8127dd
--- /dev/null
+++ b/t/dispatch.t
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use FusionInventory::Agent::Task::NetInventory;
+
+# each item is an arrayref of three elements:
+# - input parameters (sysdescr, results, ports list)
+# - expected resulting ports list
+# - test explication
+my @trunk_ports_tests = (
+    [
+        [ 'unknown', undef, undef ],
+        undef,
+        'unknown vendor'
+    ],
+    [
+        [ 'Cisco',
+            {
+                vlanTrunkPortDynamicStatus => {
+                    '1.2.0' => 1,
+                    '1.2.1' => 0,
+                    '1.2.2' => 1
+                }
+            },
+            {
+            }
+        ],
+        {
+            0 => {
+                TRUNK => 1
+            },
+            1 => {
+                TRUNK => 0
+            },
+            2 => {
+                TRUNK => 1
+            },
+        },
+        'cisco'
+    ]
+);
+
+my @connected_devices_tests = (
+    [
+        [ 'unknown', undef, undef, undef ],
+        undef,
+        'unknown vendor'
+    ]
+);
+
+plan tests => 
+    scalar @trunk_ports_tests +
+    scalar @connected_devices_tests;
+
+foreach my $test (@trunk_ports_tests) {
+    FusionInventory::Agent::Task::NetInventory::_setTrunkPorts(
+        @{$test->[0]}
+    );
+
+    is_deeply(
+        $test->[0]->[2],
+        $test->[1],
+        $test->[2],
+    );
+}
+
+foreach my $test (@connected_devices_tests) {
+    FusionInventory::Agent::Task::NetInventory::_setConnectedDevices(
+        @{$test->[0]}
+    );
+
+    is_deeply(
+        $test->[0]->[2],
+        $test->[1],
+        $test->[2],
+    );
+}


================================================================
Compare: https://github.com/fusinv/fusioninventory-agent-task-snmpquery/compare/3dcb56a...9c70227


More information about the Fusioninventory-commit mailing list