Changeset 211


Ignore:
Timestamp:
Feb 16, 2017, 9:51:57 PM (8 years ago)
Author:
g7moreau
Message:
  • Update doc and error swith -> switch
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r210 r211  
    77use strict;
    88use warnings;
    9 use version; our $VERSION = qv('0.5.9');
     9use version; our $VERSION = qv('0.6.0');
    1010
    1111use Readonly;
     
    490490
    491491      my $swport_num = $result->{$research1};
    492       my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_swithport_hr($session, $swport_num));
     492      my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num));
    493493
    494494      $session->close;
     
    544544      if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    545545         my $swport_num = $result->{$research1};
    546          my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_swithport_hr($session, $swport_num));
     546         my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num));
    547547
    548548         SWITCH_PORT_IGNORE:
     
    757757   }
    758758
    759 sub snmp_get_swithport_hr {
     759sub snmp_get_switchport_hr {
    760760   my ($snmp_session, $swport) = @_;
    761761
     
    15591559
    15601560   # create a database with the most recent computer by switch port
    1561    my %swithportdb = ();
     1561   my %switchportdb = ();
    15621562   LOOP_ON_IP_ADDRESS:
    15631563   for my $ip (keys %{$computerdb}) {
     
    15741574         $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description},
    15751575         $computerdb->{$ip}{switch_port_hr};
    1576       $swithportdb{$swpt} ||= {
     1576      $switchportdb{$swpt} ||= {
    15771577         ip          => $ip,
    15781578         timestamp   => $ip_timestamp,
     
    15841584      # if float computer, set date 15 day before warning...
    15851585      my $ip_timestamp_mod = $ip_timestamp;
    1586       my $ip_timestamp_ref = $swithportdb{$swpt}->{timestamp};
     1586      my $ip_timestamp_ref = $switchportdb{$swpt}->{timestamp};
    15871587      $ip_timestamp_mod -= 15 * 24 * 3600 if $ip_hostname_fq =~ m/$RE_FLOAT_HOSTNAME/;
    1588       $ip_timestamp_ref -= 15 * 24 * 3600 if $swithportdb{$swpt}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
     1588      $ip_timestamp_ref -= 15 * 24 * 3600 if $switchportdb{$swpt}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
    15891589
    15901590      if ($ip_timestamp_mod > $ip_timestamp_ref) {
    1591          $swithportdb{$swpt} = {
     1591         $switchportdb{$swpt} = {
    15921592            ip          => $ip,
    15931593            timestamp   => $ip_timestamp,
     
    16001600
    16011601   LOOP_ON_RECENT_COMPUTER:
    1602    for my $swpt (keys %swithportdb) {
     1602   for my $swpt (keys %switchportdb) {
    16031603      next LOOP_ON_RECENT_COMPUTER if $swpt =~ m/^\s*0$/;
    1604       next LOOP_ON_RECENT_COMPUTER if $swithportdb{$swpt}->{hostname_fq} !~ m/$RE_FLOAT_HOSTNAME/;
    1605 
    1606       my $src_ip = $swithportdb{$swpt}->{ip};
     1604      next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{hostname_fq} !~ m/$RE_FLOAT_HOSTNAME/;
     1605
     1606      my $src_ip = $switchportdb{$swpt}->{ip};
    16071607      my $src_timestamp = 0;
    16081608      LOOP_ON_IP_ADDRESS:
    16091609      for my $ip (keys %{$computerdb}) {
    1610          next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{mac_address} ne  $swithportdb{$swpt}->{mac_address};
     1610         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{mac_address} ne  $switchportdb{$swpt}->{mac_address};
    16111611         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;
    16121612         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{timestamp} < $src_timestamp;
     
    16181618      # keep only if float computer is the most recent
    16191619      next LOOP_ON_RECENT_COMPUTER if $src_timestamp == 0;
    1620       next LOOP_ON_RECENT_COMPUTER if $swithportdb{$swpt}->{timestamp} < $src_timestamp;
    1621 
    1622       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $swithportdb{$swpt}->{timestamp};
     1620      next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{timestamp} < $src_timestamp;
     1621
     1622      my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $switchportdb{$swpt}->{timestamp};
    16231623      $year += 1900;
    16241624      $mon++;
     
    16331633
    16341634      printf "%s / %-10s +-> %-10s(%i)  %s %s %s %s\n",
    1635          $swpt, $swithportdb{$swpt}->{vlan}, $computerdb->{$src_ip}{network}, $vlan_id,
     1635         $swpt, $switchportdb{$swpt}->{vlan}, $computerdb->{$src_ip}{network}, $vlan_id,
    16361636         $date,
    16371637         $src_date,
     
    21302130      if (defined $result and $result->{$research1} ne 'noSuchInstance') {
    21312131         my $swport_num = $result->{$research1};
    2132          my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_swithport_hr($session, $swport_num));
     2132         my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num));
    21332133         print "Klask find MAC $mac_address on switch $sw_name port $swport_hr\n";
    21342134         }
     
    25452545 klask enable  switch port
    25462546 klask disable switch port
    2547  klask status  swith port
     2547 klask status  switch port
    25482548
    25492549
Note: See TracChangeset for help on using the changeset viewer.