Changeset 211
- Timestamp:
- Feb 16, 2017, 9:51:57 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r210 r211 7 7 use strict; 8 8 use warnings; 9 use version; our $VERSION = qv('0. 5.9');9 use version; our $VERSION = qv('0.6.0'); 10 10 11 11 use Readonly; … … 490 490 491 491 my $swport_num = $result->{$research1}; 492 my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_swit hport_hr($session, $swport_num));492 my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num)); 493 493 494 494 $session->close; … … 544 544 if (defined $result and $result->{$research1} ne 'noSuchInstance') { 545 545 my $swport_num = $result->{$research1}; 546 my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_swit hport_hr($session, $swport_num));546 my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num)); 547 547 548 548 SWITCH_PORT_IGNORE: … … 757 757 } 758 758 759 sub snmp_get_swit hport_hr {759 sub snmp_get_switchport_hr { 760 760 my ($snmp_session, $swport) = @_; 761 761 … … 1559 1559 1560 1560 # create a database with the most recent computer by switch port 1561 my %swit hportdb = ();1561 my %switchportdb = (); 1562 1562 LOOP_ON_IP_ADDRESS: 1563 1563 for my $ip (keys %{$computerdb}) { … … 1574 1574 $computerdb->{$ip}{switch_hostname} || $computerdb->{$ip}{switch_description}, 1575 1575 $computerdb->{$ip}{switch_port_hr}; 1576 $swit hportdb{$swpt} ||= {1576 $switchportdb{$swpt} ||= { 1577 1577 ip => $ip, 1578 1578 timestamp => $ip_timestamp, … … 1584 1584 # if float computer, set date 15 day before warning... 1585 1585 my $ip_timestamp_mod = $ip_timestamp; 1586 my $ip_timestamp_ref = $swit hportdb{$swpt}->{timestamp};1586 my $ip_timestamp_ref = $switchportdb{$swpt}->{timestamp}; 1587 1587 $ip_timestamp_mod -= 15 * 24 * 3600 if $ip_hostname_fq =~ m/$RE_FLOAT_HOSTNAME/; 1588 $ip_timestamp_ref -= 15 * 24 * 3600 if $swit hportdb{$swpt}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/;1588 $ip_timestamp_ref -= 15 * 24 * 3600 if $switchportdb{$swpt}->{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/; 1589 1589 1590 1590 if ($ip_timestamp_mod > $ip_timestamp_ref) { 1591 $swit hportdb{$swpt} = {1591 $switchportdb{$swpt} = { 1592 1592 ip => $ip, 1593 1593 timestamp => $ip_timestamp, … … 1600 1600 1601 1601 LOOP_ON_RECENT_COMPUTER: 1602 for my $swpt (keys %swit hportdb) {1602 for my $swpt (keys %switchportdb) { 1603 1603 next LOOP_ON_RECENT_COMPUTER if $swpt =~ m/^\s*0$/; 1604 next LOOP_ON_RECENT_COMPUTER if $swit hportdb{$swpt}->{hostname_fq} !~ m/$RE_FLOAT_HOSTNAME/;1605 1606 my $src_ip = $swit hportdb{$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}; 1607 1607 my $src_timestamp = 0; 1608 1608 LOOP_ON_IP_ADDRESS: 1609 1609 for my $ip (keys %{$computerdb}) { 1610 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{mac_address} ne $swit hportdb{$swpt}->{mac_address};1610 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{mac_address} ne $switchportdb{$swpt}->{mac_address}; 1611 1611 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{hostname_fq} =~ m/$RE_FLOAT_HOSTNAME/; 1612 1612 next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{timestamp} < $src_timestamp; … … 1618 1618 # keep only if float computer is the most recent 1619 1619 next LOOP_ON_RECENT_COMPUTER if $src_timestamp == 0; 1620 next LOOP_ON_RECENT_COMPUTER if $swit hportdb{$swpt}->{timestamp} < $src_timestamp;1621 1622 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $swit hportdb{$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}; 1623 1623 $year += 1900; 1624 1624 $mon++; … … 1633 1633 1634 1634 printf "%s / %-10s +-> %-10s(%i) %s %s %s %s\n", 1635 $swpt, $swit hportdb{$swpt}->{vlan}, $computerdb->{$src_ip}{network}, $vlan_id,1635 $swpt, $switchportdb{$swpt}->{vlan}, $computerdb->{$src_ip}{network}, $vlan_id, 1636 1636 $date, 1637 1637 $src_date, … … 2130 2130 if (defined $result and $result->{$research1} ne 'noSuchInstance') { 2131 2131 my $swport_num = $result->{$research1}; 2132 my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_swit hport_hr($session, $swport_num));2132 my $swport_hr = get_human_readable_port($sw->{model}, snmp_get_switchport_hr($session, $swport_num)); 2133 2133 print "Klask find MAC $mac_address on switch $sw_name port $swport_hr\n"; 2134 2134 } … … 2545 2545 klask enable switch port 2546 2546 klask disable switch port 2547 klask status swit h port2547 klask status switch port 2548 2548 2549 2549
Note: See TracChangeset
for help on using the changeset viewer.