Changeset 133


Ignore:
Timestamp:
Nov 1, 2013, 8:12:34 PM (11 years ago)
Author:
g7moreau
Message:
  • Small format
  • Rename methode vab-vlan-config to bad-vlan-id (as in real switch)
  • Name loop
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r132 r133  
    4949
    5050my %CMD_DB = (
    51    help       => \&cmd_help,
    52    version    => \&cmd_version,
    53    exportdb   => \&cmd_exportdb,
    54    updatedb   => \&cmd_updatedb,
    55    searchdb   => \&cmd_searchdb,
    56    removedb   => \&cmd_removedb,
    57    cleandb    => \&cmd_cleandb,
    58    search     => \&cmd_search,
    59    enable     => \&cmd_enable,
    60    disable    => \&cmd_disable,
    61    status     => \&cmd_status,
    62    updatesw   => \&cmd_updatesw,
    63    exportsw   => \&cmd_exportsw,
    64    iplocation => \&cmd_ip_location,
    65    'ip-free'  => \&cmd_ip_free,
     51   'help'                 => \&cmd_help,
     52   'version'              => \&cmd_version,
     53   'exportdb'             => \&cmd_exportdb,
     54   'updatedb'             => \&cmd_updatedb,
     55   'searchdb'             => \&cmd_searchdb,
     56   'removedb'             => \&cmd_removedb,
     57   'cleandb'              => \&cmd_cleandb,
     58   'search'               => \&cmd_search,
     59   'enable'               => \&cmd_enable,
     60   'disable'              => \&cmd_disable,
     61   'status'               => \&cmd_status,
     62   'updatesw'             => \&cmd_updatesw,
     63   'exportsw'             => \&cmd_exportsw,
     64   'iplocation'          => \&cmd_ip_location,
     65   'ip-free'              => \&cmd_ip_free,
    6666   'search-mac-on-switch' => \&cmd_search_mac_on_switch,
    67    'bad-vlan-config'  => \&cmd_bad_vlan_config,
    68    'set-vlan-port'  => \&cmd_set_vlan_port,
    69    'get-vlan-port'  => \&cmd_get_vlan_port,
    70    'set-vlan-name'  => \&cmd_set_vlan_name,
    71    'get-vlan-name'  => \&cmd_get_vlan_name,
     67   'bad-vlan-id'          => \&cmd_bad_vlan_id,
     68   'set-vlan-port'        => \&cmd_set_vlan_port,
     69   'get-vlan-port'        => \&cmd_get_vlan_port,
     70   'set-vlan-name'        => \&cmd_set_vlan_name,
     71   'get-vlan-name'        => \&cmd_get_vlan_name,
    7272   );
    7373
     
    8686Readonly my %SWITCH_KIND => (
    8787   # HP
    88    J3299A => { model => 'HP224M',     match => 'HP J3299A ProCurve Switch 224M'  },
    89    J4120A => { model => 'HP1600M',    match => 'HP J4120A ProCurve Switch 1600M' },
    90    J9029A => { model => 'HP1800-8G',  match => 'PROCURVE J9029A'                 },
    91    J9449A => { model => 'HP1810-8G',  match => 'HP ProCurve 1810G - 8 GE'        },
    92    J4093A => { model => 'HP2424M',    match => 'HP J4093A ProCurve Switch 2424M' },
    93    J9279A => { model => 'HP2510G-24', match => 'ProCurve J9279A Switch 2510G-24' },
    94    J9280A => { model => 'HP2510G-48', match => 'ProCurve J9280A Switch 2510G-48' },
    95    J4813A => { model => 'HP2524',     match => 'HP J4813A ProCurve Switch 2524'  },
    96    J4900A => { model => 'HP2626A',    match => 'HP J4900A ProCurve Switch 2626'  },
    97    J4900B => { model => 'HP2626B',    match => 'J4900B.+?Switch 2626'            },# ProCurve J4900B Switch 2626 # HP J4900B ProCurve Switch 2626
    98    J4899B => { model => 'HP2650',     match => 'ProCurve J4899B Switch 2650'     },
    99    J9021A => { model => 'HP2810-24G', match => 'ProCurve J9021A Switch 2810-24G' },
    100    J9022A => { model => 'HP2810-48G', match => 'ProCurve J9022A Switch 2810-48G' },
     88   J3299A => { model => 'HP224M',     match => 'HP J3299A ProCurve Switch 224M'    },
     89   J4120A => { model => 'HP1600M',    match => 'HP J4120A ProCurve Switch 1600M'   },
     90   J9029A => { model => 'HP1800-8G',  match => 'PROCURVE J9029A'                   },
     91   J9449A => { model => 'HP1810-8G',  match => 'HP ProCurve 1810G - 8 GE'          },
     92   J4093A => { model => 'HP2424M',    match => 'HP J4093A ProCurve Switch 2424M'   },
     93   J9279A => { model => 'HP2510G-24', match => 'ProCurve J9279A Switch 2510G-24'   },
     94   J9280A => { model => 'HP2510G-48', match => 'ProCurve J9280A Switch 2510G-48'   },
     95   J4813A => { model => 'HP2524',     match => 'HP J4813A ProCurve Switch 2524'    },
     96   J4900A => { model => 'HP2626A',    match => 'HP J4900A ProCurve Switch 2626'    },
     97   J4900B => { model => 'HP2626B',    match => 'J4900B.+?Switch 2626'              },# ProCurve J4900B Switch 2626 # HP J4900B ProCurve Switch 2626
     98   J4899B => { model => 'HP2650',     match => 'ProCurve J4899B Switch 2650'       },
     99   J9021A => { model => 'HP2810-24G', match => 'ProCurve J9021A Switch 2810-24G'   },
     100   J9022A => { model => 'HP2810-48G', match => 'ProCurve J9022A Switch 2810-48G'   },
    101101   J8692A => { model => 'HP3500-24G', match => 'ProCurve J8692A Switch 3500yl-24G' },
    102    J4903A => { model => 'HP2824',     match => 'J4903A.+?Switch 2824,'           },
    103    J4110A => { model => 'HP8000M',    match => 'HP J4110A ProCurve Switch 8000M' },
    104    JD374A => { model => 'HP5500-24F', match => 'HP Comware.+?A5500-24G-SFP EI'   },
     102   J4903A => { model => 'HP2824',     match => 'J4903A.+?Switch 2824,'             },
     103   J4110A => { model => 'HP8000M',    match => 'HP J4110A ProCurve Switch 8000M'   },
     104   JD374A => { model => 'HP5500-24F', match => 'HP Comware.+?A5500-24G-SFP EI'     },
    105105   # BayStack
    106    BS350T => { model => 'BS350T',     match => 'BayStack 350T HW'                },
     106   BS350T => { model => 'BS350T',     match => 'BayStack 350T HW'                  },
    107107   # Nexans
    108    N3483G => { model => 'NA3483-6G',  match => 'GigaSwitch V3 TP SFP-I 48V ES3'  },
     108   N3483G => { model => 'NA3483-6G',  match => 'GigaSwitch V3 TP SFP-I 48V ES3'    },
    109109   # 3COM
    110    'H3C5500'        => { model => 'H3C5500',        match => 'H3C S5500-SI Series'           },
    111    '3C17203'        => { model => '3C17203',        match => '3Com SuperStack 3 24-Port'     },
    112    '3C17204'        => { model => '3C17204',        match => '3Com SuperStack 3 48-Port'     },
    113    '3CR17562-91'    => { model => '3CR17562-91',    match => '3Com Switch 4500 50-Port'      },
    114    '3CR17255-91'    => { model => '3CR17255-91',    match => '3Com Switch 5500G-EI 48-Port'  },
    115    '3CR17251-91'    => { model => '3CR17251-91',    match => '3Com Switch 5500G-EI 48-Port'  },
    116    '3CR17571-91'    => { model => '3CR17571-91',    match => '3Com Switch 4500 PWR 26-Port'  },
    117    '3CRWX220095A'   => { model => '3CRWX220095A',   match => '3Com Wireless LAN Controller'  },
    118    '3CR17254-91'    => { model => '3CR17254-91',    match => '3Com Switch 5500G-EI 24-Port'  },
    119    '3CRS48G-24S-91' => { model => '3CRS48G-24S-91', match => '3Com Switch 4800G 24-Port'     },
    120    '3CRS48G-48S-91' => { model => '3CRS48G-48S-91', match => '3Com Switch 4800G 48-Port'     },
    121    '3C17708'        => { model => '3C17708',        match => '3Com Switch 4050'              },
    122    '3C17709'        => { model => '3C17709',        match => '3Com Switch 4060'              },
    123    '3C17707'        => { model => '3C17707',        match => '3Com Switch 4070'              },
     110   'H3C5500'        => { model => 'H3C5500',        match => 'H3C S5500-SI Series'              },
     111   '3C17203'        => { model => '3C17203',        match => '3Com SuperStack 3 24-Port'        },
     112   '3C17204'        => { model => '3C17204',        match => '3Com SuperStack 3 48-Port'        },
     113   '3CR17562-91'    => { model => '3CR17562-91',    match => '3Com Switch 4500 50-Port'         },
     114   '3CR17255-91'    => { model => '3CR17255-91',    match => '3Com Switch 5500G-EI 48-Port'     },
     115   '3CR17251-91'    => { model => '3CR17251-91',    match => '3Com Switch 5500G-EI 48-Port'     },
     116   '3CR17571-91'    => { model => '3CR17571-91',    match => '3Com Switch 4500 PWR 26-Port'     },
     117   '3CRWX220095A'   => { model => '3CRWX220095A',   match => '3Com Wireless LAN Controller'     },
     118   '3CR17254-91'    => { model => '3CR17254-91',    match => '3Com Switch 5500G-EI 24-Port'     },
     119   '3CRS48G-24S-91' => { model => '3CRS48G-24S-91', match => '3Com Switch 4800G 24-Port'        },
     120   '3CRS48G-48S-91' => { model => '3CRS48G-48S-91', match => '3Com Switch 4800G 48-Port'        },
     121   '3C17708'        => { model => '3C17708',        match => '3Com Switch 4050'                 },
     122   '3C17709'        => { model => '3C17709',        match => '3Com Switch 4060'                 },
     123   '3C17707'        => { model => '3C17707',        match => '3Com Switch 4070'                 },
    124124   '3CR17258-91'    => { model => '3CR17258-91',    match => '3Com Switch 5500G-EI 24-Port SFP' },
    125125   '3CR17181-91'    => { model => '3CR17181-91',    match => '3Com Switch 5500-EI 28-Port FX'   },
     
    279279   my $verbose = shift;
    280280
    281    printf "%-26s                %-25s %s\n",'Switch','Description','Type';
     281   printf "%-26s                %-25s %s\n",'Switch','Description','Type' if $verbose;
    282282   print "------------------------------------------------------------------------------\n" if $verbose;
    283283
     
    649649 klask ip-free --day number_of_day --format [txt|html] [vlan_name]
    650650
    651  klask bad-vlan-config
     651 klask bad-vlan-id
    652652
    653653 klask enable  switch port
     
    676676   init_switch_names();    #nomme les switchs
    677677   fast_ping(@computer);
     678
     679   LOOP_ON_COMPUTER:
    678680   for my $clientname (@computer) {
    679681      my %resol_arp = resolve_ip_arp_host($clientname);          #resolution arp
    680682      my %where     = find_switch_port($resol_arp{mac_address}); #retrouve l'emplacement
    681       printf '%-22s %2i %-30s %-15s %18s', $where{switch_description}, $where{switch_port}, $resol_arp{hostname_fq}, $resol_arp{ipv4_address}, $resol_arp{mac_address}."\n"
    682          unless $where{switch_description} eq 'unknow' and $resol_arp{hostname_fq} eq 'unknow' and $resol_arp{mac_address} eq 'unknow';
     683
     684      next LOOP_ON_COMPUTER if $where{switch_description} eq 'unknow' or $resol_arp{hostname_fq} eq 'unknow' or $resol_arp{mac_address} eq 'unknow';
     685
     686      printf '%-22s %2i %-30s %-15s %18s',
     687         $where{switch_description},
     688         $where{switch_port},
     689         $resol_arp{hostname_fq},
     690         $resol_arp{ipv4_address},
     691         $resol_arp{mac_address}."\n";
    683692      }
    684693   return;
     
    12801289   }
    12811290
    1282 sub cmd_bad_vlan_config {
     1291sub cmd_bad_vlan_id {
    12831292   test_maindb_environnement();
    12841293
     
    13261335      }
    13271336
     1337   LOOP_ON_RECENT_COMPUTER:
    13281338   foreach my $swpt (keys %swithportdb) {
    1329       next if $swpt =~ m/^\s*0$/;
    1330       next if $swithportdb{$swpt}->{hostname_fq} !~ m/$RE_FLOAT_HOSTNAME/;
     1339      next LOOP_ON_RECENT_COMPUTER if $swpt =~ m/^\s*0$/;
     1340      next LOOP_ON_RECENT_COMPUTER if $swithportdb{$swpt}->{hostname_fq} !~ m/$RE_FLOAT_HOSTNAME/;
    13311341
    13321342      my $src_ip = $swithportdb{$swpt}->{ip};
    13331343      my $src_timestamp = 0;
     1344      LOOP_ON_IP_ADDRESS:
    13341345      foreach my $ip (keys %{$computerdb}) {
    1335          next if $computerdb->{$ip}{mac_address} ne  $swithportdb{$swpt}->{mac_address};
    1336          next if $computerdb->{$ip}{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
    1337          next if $computerdb->{$ip}{timestamp} < $src_timestamp;
     1346         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{mac_address} ne  $swithportdb{$swpt}->{mac_address};
     1347         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
     1348         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{timestamp} < $src_timestamp;
    13381349         
    13391350         $src_ip = $ip;
     
    13421353
    13431354      # keep only if float computer is the most recent
    1344       next if $src_timestamp == 0;
    1345       next if $swithportdb{$swpt}->{timestamp} < $src_timestamp;
     1355      next LOOP_ON_RECENT_COMPUTER if $src_timestamp == 0;
     1356      next LOOP_ON_RECENT_COMPUTER if $swithportdb{$swpt}->{timestamp} < $src_timestamp;
    13461357
    13471358      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $swithportdb{$swpt}->{timestamp};
     
    14841495
    14851496      my $sw_hostname = $computerdb->{$ip}{switch_hostname} || q{};
    1486       next if $sw_hostname eq 'unknow';
     1497      next LOOP_ON_IP_ADDRESS if $sw_hostname eq 'unknow';
    14871498
    14881499      my $sw_location = q{};
     1500      LOOP_ON_ALL_SWITCH:
    14891501      for my $sw (@SWITCH) {
    1490          next if $sw_hostname ne $sw->{hostname};
     1502         next LOOP_ON_ALL_SWITCH if $sw_hostname ne $sw->{hostname};
    14911503         $sw_location = $sw->{location};
    14921504         last;
Note: See TracChangeset for help on using the changeset viewer.