Changeset 51 for trunk/klask


Ignore:
Timestamp:
Jul 24, 2009, 12:22:32 AM (15 years ago)
Author:
g7moreau
Message:
  • Suppress perlcritic warning level 3 Capture variable used outside conditional Be carrefull, I am not sure klask still capture expression !
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r50 r51  
    88use warnings;
    99
     10use Readonly;
    1011use Net::SNMP;
    1112#use YAML;
     
    6061   );
    6162
    62 my %INTERNAL_PORT_MAP = (
     63Readonly my %INTERNAL_PORT_MAP => (
    6364   0 => 'A',
    6465   1 => 'B',
     
    7071   7 => 'H',
    7172   );
    72 my %INTERNAL_PORT_MAP_REV = reverse %INTERNAL_PORT_MAP;
    73 
    74 my %SWITCH_KIND = (
     73Readonly my %INTERNAL_PORT_MAP_REV => reverse %INTERNAL_PORT_MAP;
     74
     75Readonly my %SWITCH_KIND => (
    7576   J3299A => { model => 'HP224M',     match => 'HP J3299A ProCurve Switch 224M'  },
    7677   J4120A => { model => 'HP1600M',    match => 'HP J4120A ProCurve Switch 1600M' },
     
    8889   );
    8990
    90 my %OID_NUMBER = (
    91    sysDescription    => '1.3.6.1.2.1.1.1.0',
    92    sysName     => '1.3.6.1.2.1.1.5.0',
    93    sysContact  => '1.3.6.1.2.1.1.4.0',
    94    sysLocation => '1.3.6.1.2.1.1.6.0',
     91Readonly my %OID_NUMBER => (
     92   sysDescription  => '1.3.6.1.2.1.1.1.0',
     93   sysName         => '1.3.6.1.2.1.1.5.0',
     94   sysContact      => '1.3.6.1.2.1.1.4.0',
     95   sysLocation     => '1.3.6.1.2.1.1.6.0',
    9596   );
     97
     98Readonly my $RE_MAC_ADDRESS  => qr{ [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} : [0-9,A-Z]{2} }xms;
     99Readonly my $RE_IPv4_ADDRESS => qr{ [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} }xms;
     100
    96101
    97102################
     
    177182   # tech7meylan.hmg.inpg.fr (194.254.66.240) at 00:14:22:45:28:A9 [ether] on eth0
    178183   # sw2-batF0-legi.hmg.priv (192.168.22.112) at 00:30:c1:76:9c:01 [ether] on eth0.37
    179    my $cmd_arp  = `arp -a $param_ip_or_host 2>/dev/null`;
     184   my $cmd_arp  = `arp -a $param_ip_or_host 2> /dev/null`;
    180185   chomp $cmd_arp;
    181    $cmd_arp =~ /(\S*)\s\(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\)\sat\s([0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2}:[0-9,A-Z]{2})/x;
    182    $ret{hostname_fq}  = $1 if(defined($1));
    183    $ret{ipv4_address} = $2 if(defined($2));
    184    $ret{mac_address}  = $3 if(defined($3));
     186   if ( $cmd_arp =~ m{ (\S*) \s \( ( $RE_IPv4_ADDRESS ) \) \s at \s ( $RE_MAC_ADDRESS ) }xms ) {
     187      ( $ret{hostname_fq}, $ret{ipv4_address}, $ret{mac_address} )  = ($1, $2, $3);
     188      }
    185189
    186190   # resultat de la commande host si le parametre est ip
    187191   # 250.66.254.194.in-addr.arpa domain name pointer legihp2100.hmg.inpg.fr.
    188    my $cmd_host = `host $param_ip_or_host 2>/dev/null`;
     192   my $cmd_host = `host $param_ip_or_host 2> /dev/null`;
    189193   chomp $cmd_host;
    190    $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/x;
    191    $ret{hostname_fq} = $1 if defined $1;
     194   if ( $cmd_host =~ m/domain \s name \s pointer \s (\S+) \.$/xms ) {
     195      $ret{hostname_fq} = $1;
     196      }
    192197
    193198   # resultat de la commande host si parametre est hostname
    194199   # tech7meylan.hmg.inpg.fr has address 194.254.66.240
    195    $cmd_host =~ m/(\S*) \s has \s address \s ( [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} \. [0-9]{1,3} )$/x;
    196    $ret{hostname_fq}  = $1 if defined $1;
    197    $ret{ipv4_address} = $2 if defined $2;
    198 
    199    $cmd_host =~ m/ \b ([0-9]{1,3}) \. ([0-9]{1,3}) \. ([0-9]{1,3}) \. ([0-9]{1,3}) \. in-addr \. arpa \s/x;
    200    $ret{ipv4_address} = "$4.$3.$2.$1"     if defined $1 and  defined $2 and  defined $3 and  defined $4;
    201    $ret{hostname_fq}  = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow';
     200   if ( $cmd_host =~ m/(\S*) \s has \s address \s ( $RE_IPv4_ADDRESS )$/xms ) {
     201      ( $ret{hostname_fq}, $ret{ipv4_address} ) = ($1, $2);
     202      }
     203
     204   if ( $cmd_host =~ m/ \b ( $RE_IPv4_ADDRESS ) \. in-addr \. arpa \s/xms ) {
     205      $ret{ipv4_address} = $1;
     206      }
     207   #$ret{hostname_fq}  = $param_ip_or_host if not defined $1 and $ret{hostname_fq} eq 'unknow';
    202208
    203209   unless ($ret{mac_address} eq 'unknow') {
    204210      my @paquets = ();
    205211      foreach ( split m/ : /x, $ret{mac_address} ) {
    206          my @chars = split m//x, uc("00$_");
     212         my @chars = split m//xms, uc("00$_");
    207213         push @paquets, "$chars[-2]$chars[-1]";
    208214         }
Note: See TracChangeset for help on using the changeset viewer.