Changeset 369 for trunk


Ignore:
Timestamp:
Dec 8, 2017, 11:37:55 PM (6 years ago)
Author:
g7moreau
Message:
  • Just try to better indent code
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/klask

    r368 r369  
    44#
    55# $Id$
     6#
     7# perltidy -i=3 -ci=3 -pt=2 -icb -cti=3 -sbt=2 -bt=2 -bbt=2 -nsfs -bar -otr -olc -nolq -l=132 -vmll -msc=1 -iscl -nbbc -nola -st klask > klask.tmp
    68
    79use strict;
     
    4749LEVEL_OF_EACH_SWITCH:
    4850for my $sw (@SWITCH_LIST) {
    49    $SWITCH_LEVEL{$sw->{'hostname'}} = $sw->{'level'} || $DEFAULT{'switch_level'}  || 2;
     51   $SWITCH_LEVEL{$sw->{'hostname'}} = $sw->{'level'} || $DEFAULT{'switch_level'} || 2;
    5052   $SWITCH_DB{$sw->{'hostname'}} = $sw;
    5153
     
    6264   $sw->{'snmp_param_session'} = \%session;
    6365   }
    64 @SWITCH_LIST = reverse sort { $SWITCH_LEVEL{$a->{'hostname'}} <=> $SWITCH_LEVEL{$b->{'hostname'}} } @{$KLASK_CFG->{'switch'}};
     66@SWITCH_LIST = reverse sort {$SWITCH_LEVEL{$a->{'hostname'}} <=> $SWITCH_LEVEL{$b->{'hostname'}}} @{$KLASK_CFG->{'switch'}};
    6567
    6668#my %SWITCH_PORT_COUNT = ();
     
    177179   sysContact      => '1.3.6.1.2.1.1.4.0',
    178180   sysLocation     => '1.3.6.1.2.1.1.6.0',
    179    searchPort1     => '1.3.6.1.2.1.17.4.3.1.2',          # BRIDGE-MIB (802.1D).
    180    searchPort2     => '1.3.6.1.2.1.17.7.1.2.2.1.2',      # Q-BRIDGE-MIB (802.1Q) add 0 if unknown vlan id
    181    vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1',      # dot1qPvid
    182    vlanStatus      => '1.3.6.1.2.1.17.7.1.4.3.1.5',      # integer 4 Create, 6 Destroy
    183    vlanName        => '1.3.6.1.2.1.17.7.1.4.3.1.1',      # string
    184    HPicfReset      => '1.3.6.1.4.1.11.2.14.11.1.4.1',    # HP reboot switch
    185    ifIndex         => '1.3.6.1.2.1.17.1.4.1.2',          # dot1dBasePortIfIndex - Interface index redirection
    186    ifName          => '1.3.6.1.2.1.31.1.1.1.1',          # Interface name (give port number)
    187    portUpDown      => '1.3.6.1.2.1.2.2.1.7',             # 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up)  = 2 (down)
    188    poeState        => '1.3.6.1.2.1.105.1.1.1.3.1',       # 1.3.6.1.2.1.105.1.1.1.3.1.NoPort = 1 (poe up)  = 2 (poe down) - Cisco and Zyxel
    189    NApoeState      => '1.3.6.1.4.1.266.20.3.1.1.21',     # .NoPort = 2 (poe off)  = 8 (poe atHighPower) - Nexans
    190    ifAggregator    => '1.2.840.10006.300.43.1.2.1.1.12', # dot3adAggPortSelectedAggID - 0 not part of an  Aggregator - Ciso Dell HP Comware -  See https://stackoverflow.com/questions/14960157/how-to-map-portchannel-to-interfaces-via-snmp https://gist.github.com/bldewolf/6314435
     181   searchPort1     => '1.3.6.1.2.1.17.4.3.1.2',       # BRIDGE-MIB (802.1D).
     182   searchPort2     => '1.3.6.1.2.1.17.7.1.2.2.1.2',   # Q-BRIDGE-MIB (802.1Q) add 0 if unknown vlan id
     183   vlanPortDefault => '1.3.6.1.2.1.17.7.1.4.5.1.1',   # dot1qPvid
     184   vlanStatus      => '1.3.6.1.2.1.17.7.1.4.3.1.5',   # integer 4 Create, 6 Destroy
     185   vlanName        => '1.3.6.1.2.1.17.7.1.4.3.1.1',   # string
     186   HPicfReset      => '1.3.6.1.4.1.11.2.14.11.1.4.1', # HP reboot switch
     187   ifIndex         => '1.3.6.1.2.1.17.1.4.1.2',       # dot1dBasePortIfIndex - Interface index redirection
     188   ifName          => '1.3.6.1.2.1.31.1.1.1.1',       # Interface name (give port number)
     189   portUpDown      => '1.3.6.1.2.1.2.2.1.7',          # 1.3.6.1.2.1.2.2.1.7.NoPort = 1 (up)  = 2 (down)
     190   poeState        => '1.3.6.1.2.1.105.1.1.1.3.1',    # 1.3.6.1.2.1.105.1.1.1.3.1.NoPort = 1 (poe up)  = 2 (poe down) - Cisco and Zyxel
     191   NApoeState      => '1.3.6.1.4.1.266.20.3.1.1.21',  # .NoPort = 2 (poe off)  = 8 (poe atHighPower) - Nexans
     192   ifAggregator => '1.2.840.10006.300.43.1.2.1.1.12', # dot3adAggPortSelectedAggID - 0 not part of an  Aggregator - Ciso Dell HP Comware -  See https://stackoverflow.com/questions/14960157/how-to-map-portchannel-to-interfaces-via-snmp https://gist.github.com/bldewolf/6314435
    191193   );
    192194
     
    201203Readonly my $RE_FLOAT_HOSTNAME => $DEFAULT{'float-regex'} || qr{ ^float }xms;
    202204
    203 Readonly my $SEP_AGGREGATOR_PORT => ',';  # : is already use to join switch and port
     205Readonly my $SEP_AGGREGATOR_PORT => ','; # : is already use to join switch and port
    204206Readonly my $SEP_SWITCH_PORT     => ':';
    205207
     
    269271sub resolve_ip_arp_host {
    270272   my $param_ip_or_host = shift;
    271    my $interface = shift || q{*};
    272    my $type      = shift || q{fast};
    273    my $already   = shift || q{yes};
     273   my $interface        = shift || q{*};
     274   my $type             = shift || q{fast};
     275   my $already          = shift || q{yes};
    274276
    275277   my %ret = (
     
    307309   my $nowtimestamp = time;
    308310
    309    if ( $type eq 'fast' and ( not defined $timestamp or $timestamp < ( $nowtimestamp - 45 * 60 ) ) ) { # 45 min
     311   if ($type eq 'fast' and (not defined $timestamp or $timestamp < ($nowtimestamp - 45 * 60))) { # 45 min
    310312      $ret{'mac_address'} = 'unknow';
    311313      return %ret;
     
    328330      # Last chance to have the mac_address
    329331      if ($ret{'interface'} eq '*') {
    330          my $cmd_arp  = shell_command "ip neigh show to $ret{'ipv4_address'}";
    331          if ( $cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s dev \s ([\w\d\.\:]+) \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms ) {
     332         my $cmd_arp = shell_command "ip neigh show to $ret{'ipv4_address'}";
     333         if ($cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s dev \s ([\w\d\.\:]+) \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms) {
    332334            ($ret{'interface'}, $ret{'mac_address'}) = ($1, $2);
    333335            }
    334336         }
    335337      else {
    336          my $cmd_arp  = shell_command "ip neigh show to $ret{'ipv4_address'} dev $ret{'interface'}";
    337          if ( $cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms ) {
     338         my $cmd_arp = shell_command "ip neigh show to $ret{'ipv4_address'} dev $ret{'interface'}";
     339         if ($cmd_arp =~ m{ ^$RE_IPv4_ADDRESS \s lladdr \s ( $RE_MAC_ADDRESS ) \s }xms) {
    338340            $ret{'mac_address'} = $1;
    339341            }
     
    344346   if ($ret{'mac_address'} ne 'unknow') {
    345347      my @paquets = ();
    346       for ( split m/ : /xms, $ret{'mac_address'} ) {
     348      for (split m/ : /xms, $ret{'mac_address'}) {
    347349         my @chars = split m//xms, uc "00$_";
    348350         push @paquets, "$chars[-2]$chars[-1]";
     
    391393   my ($verbose, $verb_description, $check_hostname, $check_location) = @_;
    392394
    393    printf "%-26s                %-25s %s\n",'Switch','Description','Type(Revision)' if $verbose;
     395   printf "%-26s                %-25s %s\n", 'Switch', 'Description', 'Type(Revision)' if $verbose;
    394396   print "----------------------------------------------------------------------------------\n" if $verbose;
    395397
    396398   INIT_EACH_SWITCH:
    397399   for my $sw (my @CLONE = @SWITCH_LIST) { # Make a local clone because some element can be deleted
    398       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     400      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    399401      print "$error \n" if $error;
    400402
     
    411413         $session->close();
    412414         # Remove bad switch
    413          @SWITCH_LIST = grep { $_->{'hostname'} ne $sw->{'hostname'} } @SWITCH_LIST;
     415         @SWITCH_LIST = grep {$_->{'hostname'} ne $sw->{'hostname'}} @SWITCH_LIST;
    414416         delete $SWITCH_LEVEL{$sw->{'hostname'}} if exists $SWITCH_LEVEL{$sw->{'hostname'}};
    415417         delete $SWITCH_DB{$sw->{'hostname'}}    if exists $SWITCH_DB{$sw->{'hostname'}};
     
    17211723      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
    17221724
    1723       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
     1725      my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'};
    17241726      $year += 1900;
    17251727      $mon++;
     
    17291731      $vlan = $computerdb->{$ip}{'network'}.'('.get_current_vlan_id($computerdb->{$ip}{'network'}).')' if $computerdb->{$ip}{'network'};
    17301732
    1731       my $arrow ='<---';
    1732          $arrow ='<===' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
     1733      my $arrow = '<---';
     1734      $arrow = '<===' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
    17331735
    17341736      $tb_computer->add(
     
    17571759   my $computerdb = computerdb_load();
    17581760
    1759 #<link rel="stylesheet" type="text/css" href="style-klask.css" />
    1760 #<script src="sorttable-klask.js"></script>
     1761   #<link rel="stylesheet" type="text/css" href="style-klask.css" />
     1762   #<script src="sorttable-klask.js"></script>
    17611763
    17621764   print <<'END_HTML';
     
    17961798      next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} eq ($computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'}); # switch on himself !
    17971799
    1798       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
     1800      my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'};
    17991801      $year += 1900;
    18001802      $mon++;
    18011803      my $date = sprintf '%04i-%02i-%02i %02i:%02i', $year, $mon, $mday, $hour, $min;
    18021804
    1803 #      $odd_or_even++;
    1804 #      my $typerow = $odd_or_even % 2 ? 'odd' : 'even';
     1805      #      $odd_or_even++;
     1806      #      my $typerow = $odd_or_even % 2 ? 'odd' : 'even';
    18051807      $typerow = $typerow eq 'even' ? 'odd' : 'even';
    18061808
    18071809      #my $arrow ='&#8592;';
    18081810      #   $arrow ='&#8656;' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
    1809       my $arrow ='&#10229;';
    1810          $arrow ='&#10232;' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
     1811      my $arrow = '&#10229;';
     1812      $arrow = '&#10232;' if $computerdb->{$ip}{'switch_port_hr'} =~ m/^(Trk|Br|Po)/;
    18111813
    18121814      my $switch_hostname = $computerdb->{$ip}{'switch_hostname'} || $computerdb->{$ip}{'switch_description'} || 'unkown';
     
    18191821
    18201822      $computerdb->{$ip}{'hostname_fq'} = 'unknow' if $computerdb->{$ip}{'hostname_fq'} =~ m/^ \d+ \. \d+ \. \d+ \. \d+ $/xms;
    1821       my ( $host_short ) = split m/ \. /xms, $computerdb->{$ip}{'hostname_fq'};
     1823      my ($host_short) = split m/ \. /xms, $computerdb->{$ip}{'hostname_fq'};
    18221824
    18231825      my $vlan = '';
     
    18601862      #my $arrow ='&#8702;';
    18611863      #   $arrow ='&#8680;' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
    1862       my $arrow ='&#10236;';
    1863          $arrow ='&#10238;' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
     1864      my $arrow = '&#10236;';
     1865      $arrow = '&#10238;' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
    18641866
    18651867      if (exists $db_switch_parent{$sw}) {
     
    18721874         my $timestamp    = $db_switch{$db_switch_parent{$sw}->{'switch'}}->{'timestamp'};
    18731875
    1874          my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $timestamp;
     1876         my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $timestamp;
    18751877         $year += 1900;
    18761878         $mon++;
     
    19111913         my $host_short = format_switchport4sort($sw, $db_switch_output_port{$sw});
    19121914
    1913          my $mac_address = $db_switch{$sw}->{'mac_address'};
     1915         my $mac_address  = $db_switch{$sw}->{'mac_address'};
    19141916         my $ipv4_address = $db_switch{$sw}->{'ipv4_address'};
    1915          my $timestamp = $db_switch{$sw}->{'timestamp'};
    1916 
    1917          my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $timestamp;
     1917         my $timestamp    = $db_switch{$sw}->{'timestamp'};
     1918
     1919         my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $timestamp;
    19181920         $year += 1900;
    19191921         $mon++;
     
    19251927
    19261928         my $vlan = $db_switch{$sw}->{'network'};
    1927          $vlan .= ' ('.get_current_vlan_id($db_switch{$sw}->{'network'}).')' if $db_switch{$sw}->{'network'};
    1928 
    1929          my $arrow ='&#10235;';
    1930             $arrow ='&#10237;' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
     1929         $vlan .= ' (' . get_current_vlan_id($db_switch{$sw}->{'network'}) . ')' if $db_switch{$sw}->{'network'};
     1930
     1931         my $arrow = '&#10235;';
     1932         $arrow = '&#10237;' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
    19311933
    19321934         fqdn_html_breakable($sw);
     
    19551957         my $switch_hostname_sort = format_switchport4sort($sw_connect, $port_connect);
    19561958
    1957          my $mac_address = $db_switch{$sw}->{'mac_address'};
     1959         my $mac_address  = $db_switch{$sw}->{'mac_address'};
    19581960         my $ipv4_address = $db_switch{$sw}->{'ipv4_address'};
    1959          my $timestamp = $db_switch{$sw}->{'timestamp'};
    1960 
    1961          my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $timestamp;
     1961         my $timestamp    = $db_switch{$sw}->{'timestamp'};
     1962
     1963         my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $timestamp;
    19621964         $year += 1900;
    19631965         $mon++;
    1964          my $date = sprintf '%04i-%02i-%02i %02i:%02i', $year,$mon,$mday,$hour,$min;
     1966         my $date = sprintf '%04i-%02i-%02i %02i:%02i', $year, $mon, $mday, $hour, $min;
    19651967
    19661968         my $ip_sort = sprintf '%03i%03i%03i%03i', split m/ [\.\*] /xms, $ipv4_address; # \* for fake-ip
     
    19721974         #my $arrow ='&#8701;';
    19731975         #   $arrow ='&#8678;' if $port_connect =~ m/^(Trk|Br|Po)/;
    1974          my $arrow ='&#10235;';
    1975             $arrow ='&#10237;' if $port_connect =~ m/^(Trk|Br|Po)/;
     1976         my $arrow = '&#10235;';
     1977         $arrow = '&#10237;' if $port_connect =~ m/^(Trk|Br|Po)/;
    19761978
    19771979         my $vlan = $db_switch{$sw}->{'network'};
    1978          $vlan .= ' ('.get_current_vlan_id($db_switch{$sw}->{'network'}).')' if $db_switch{$sw}->{'network'};
     1980         $vlan .= ' (' . get_current_vlan_id($db_switch{$sw}->{'network'}) . ')' if $db_switch{$sw}->{'network'};
    19791981
    19801982         if (exists $db_switch_output_port{$sw}) {
    19811983
    1982             my $host_short = format_switchport4sort(split( m/\./xms, $sw, 1), $db_switch_output_port{$sw});
     1984            my $host_short = format_switchport4sort(split(m/\./xms, $sw, 1), $db_switch_output_port{$sw});
    19831985
    19841986            my $parent_port_hr = format_aggregator4html($port_connect);
     
    20512053
    20522054   GetOptions(
    2053       'day|d=i'      => \$days_before_alert,
    2054       'format|f=s'   => \$format,
     2055      'day|d=i'    => \$days_before_alert,
     2056      'format|f=s' => \$format,
    20552057      );
    20562058
     
    20582060      txt  => \&cmd_bad_vlan_id_txt,
    20592061      html => \&cmd_bad_vlan_id_html,
    2060       none => sub {},
     2062      none => sub { },
    20612063      );
    20622064   $format = 'txt' if not defined $possible_format{$format};
     
    21142116      next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{'hostname_fq'} !~ m/$RE_FLOAT_HOSTNAME/;
    21152117
    2116       my $src_ip = $switchportdb{$swpt}->{'ip'};
     2118      my $src_ip        = $switchportdb{$swpt}->{'ip'};
    21172119      my $src_timestamp = 0;
    21182120      LOOP_ON_IP_ADDRESS:
    21192121      for my $ip (keys %{$computerdb}) {
    2120          next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'mac_address'} ne  $switchportdb{$swpt}->{'mac_address'};
     2122         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'mac_address'} ne $switchportdb{$swpt}->{'mac_address'};
    21212123         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'hostname_fq'} =~ m/$RE_FLOAT_HOSTNAME/;
    21222124         next LOOP_ON_IP_ADDRESS if $computerdb->{$ip}{'timestamp'} < $src_timestamp;
    21232125
    2124          $src_ip = $ip;
     2126         $src_ip        = $ip;
    21252127         $src_timestamp = $computerdb->{$ip}{'timestamp'};
    21262128         }
     
    21302132      next LOOP_ON_RECENT_COMPUTER if $switchportdb{$swpt}->{'timestamp'} < $src_timestamp;
    21312133
    2132       my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $switchportdb{$swpt}->{'timestamp'};
     2134      my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $switchportdb{$swpt}->{'timestamp'};
    21332135      $year += 1900;
    21342136      $mon++;
    21352137      my $date = sprintf '%04i-%02i-%02i/%02i:%02i', $year, $mon, $mday, $hour, $min;
    21362138
    2137       ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$src_ip}{'timestamp'};
     2139      ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$src_ip}{'timestamp'};
    21382140      $year += 1900;
    21392141      $mon++;
     
    21422144      my $vlan_id = get_current_vlan_id($computerdb->{$src_ip}{'network'});
    21432145      my ($switch_hostname, $port_hr) = split /\s+/, $swpt, 2;
    2144      
     2146
    21452147      push @result, {
    21462148         switch      => $switch_hostname,
    21472149         port_hr     => $port_hr,
    21482150         vlan_bad    => $switchportdb{$swpt}->{'vlan'},
    2149          vlan_good   =>$computerdb->{$src_ip}{'network'},
     2151         vlan_good   => $computerdb->{$src_ip}{'network'},
    21502152         vlan_id     => $vlan_id,
    21512153         date_last   => $date,
     
    22312233
    22322234      my $switch_hostname_sort = format_switchport4sort($item->{'switch'}, $item->{'port_hr'});
    2233       my ( $host_short ) = split m/ \. /xms, $item->{'hostname_fq'};
     2235      my ($host_short) = split m/ \. /xms, $item->{'hostname_fq'};
    22342236
    22352237      my $vlan_nameid = $item->{'vlan_good'} . ' (' . $item->{'vlan_id'} . ')';
     
    22982300         -varbindlist => [$oid_search, INTEGER, 8], # Only NEXANS
    22992301         );
    2300       print $session->error()."\n" if $session->error_status();
     2302      print $session->error() . "\n" if $session->error_status();
    23012303
    23022304      $session->close;
     
    23362338         -varbindlist => [$oid_search, INTEGER, 2], # Only NEXANS
    23372339         );
    2338       print $session->error()."\n" if $session->error_status();
     2340      print $session->error() . "\n" if $session->error_status();
    23392341
    23402342      $session->close;
     
    23682370
    23692371      my $sw = $SWITCH_DB{$sw_name};
    2370       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2372      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    23712373      print "$error \n" if $error;
    23722374
     
    24002402      );
    24012403
    2402    my $switch_name = shift @ARGV || q{};
     2404   my $switch_name     = shift @ARGV || q{};
    24032405   my $switch_location = shift @ARGV || q{};
    24042406
     
    24382440      }
    24392441
    2440    $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*};
     2442   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST) if $switch_name eq q{*};
    24412443
    24422444   for my $sw_name (split /,/, $switch_name) {
     
    24462448
    24472449      my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
    2448       my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. 0 . mac_address_hex2dec($mac_address);
     2450      my $oid_search_port2 = $OID_NUMBER{'searchPort2'} . '.' . 0 . mac_address_hex2dec($mac_address);
    24492451      print "Klask search OID $oid_search_port1 on switch $sw_name\n";
    24502452      print "Klask search OID $oid_search_port2 on switch $sw_name\n";
    24512453
    24522454      my $sw = $SWITCH_DB{$sw_name};
    2453       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2455      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    24542456      print "$error \n" if $error;
    24552457
     
    25012503
    25022504      my $sw = $SWITCH_DB{$sw_name};
    2503       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2505      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    25042506      print "$error \n" if $error;
    25052507
     
    25682570      }
    25692571
    2570    $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*};
     2572   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST) if $switch_name eq q{*};
    25712573
    25722574   for my $sw_name (split /,/, $switch_name) {
     
    25782580
    25792581      my $sw = $SWITCH_DB{$sw_name};
    2580       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2582      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    25812583      print "$error \n" if $error;
    25822584
     
    26062608      }
    26072609
    2608    $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*};
     2610   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST) if $switch_name eq q{*};
    26092611
    26102612   for my $sw_name (split /,/, $switch_name) {
     
    26142616
    26152617      my $sw = $SWITCH_DB{$sw_name};
    2616       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2618      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    26172619      print "$error \n" if $error;
    26182620
     
    26622664
    26632665   GetOptions(
    2664       'day|d=i'      => \$days_to_death,
    2665       'format|f=s'   => \$format,
    2666       'verbose|v'    => \$verbose,
     2666      'day|d=i'    => \$days_to_death,
     2667      'format|f=s' => \$format,
     2668      'verbose|v'  => \$verbose,
    26672669      );
    26682670
     
    26702672      txt  => \&cmd_ip_free_txt,
    26712673      html => \&cmd_ip_free_html,
    2672       none => sub {},
     2674      none => sub { },
    26732675      );
    26742676   $format = 'txt' if not defined $possible_format{$format};
     
    26782680
    26792681   my $computerdb = {};
    2680       $computerdb = computerdb_load() if -e "$KLASK_DB_FILE";
     2682   $computerdb = computerdb_load() if -e "$KLASK_DB_FILE";
    26812683   my $timestamp = time;
    26822684
     
    27062708         my $ip_date_last_detection = '';
    27072709         if (exists $computerdb->{$ip}) {
    2708             my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $computerdb->{$ip}{'timestamp'};
     2710            my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $computerdb->{$ip}{'timestamp'};
    27092711            $year += 1900;
    27102712            $mon++;
     
    27122714            }
    27132715
    2714          my $packed_ip = scalar gethostbyname($ip);
     2716         my $packed_ip   = scalar gethostbyname($ip);
    27152717         my $hostname_fq = 'unknown';
    27162718            $hostname_fq = scalar gethostbyaddr($packed_ip, AF_INET) || 'unknown' if defined $packed_ip and get_current_scan_mode($vlan) eq 'active';
     
    27202722         $result_ip{$ip} ||= {};
    27212723         $result_ip{$ip}->{'date_last_detection'} = $ip_date_last_detection;
    2722          $result_ip{$ip}->{'hostname_fq'} = $hostname_fq;
    2723          $result_ip{$ip}->{'vlan'} = $vlan;
     2724         $result_ip{$ip}->{'hostname_fq'}         = $hostname_fq;
     2725         $result_ip{$ip}->{'vlan'}                = $vlan;
    27242726
    27252727         printf "VERBOSE_1: %-15s %-12s %s\n", $ip, $vlan, $hostname_fq if $verbose;
     
    27452747   LOOP_ON_IP_ADDRESS:
    27462748   for my $ip (Net::Netmask::sort_by_ip_address(keys %result_ip)) {
    2747       my $vlan_nameid = $result_ip{$ip}->{'vlan'}.'('.get_current_vlan_id($result_ip{$ip}->{'vlan'}).')';
     2749      my $vlan_nameid = $result_ip{$ip}->{'vlan'} . '(' . get_current_vlan_id($result_ip{$ip}->{'vlan'}) . ')';
    27482750      #printf "%-15s %-40s %-16s %s\n", $ip, $result_ip{$ip}->{'hostname_fq'}, $result_ip{$ip}->{'date_last_detection'}, $vlan_nameid;
    27492751      $tb_computer->add(
     
    27852787
    27862788      my $ip_sort = sprintf '%03i%03i%03i%03i', split m/ \. /xms, $ip;
    2787       my ( $host_short ) = split m/ \. /xms, $result_ip{$ip}->{'hostname_fq'};
    2788 
    2789       my $vlan_nameid = $result_ip{$ip}->{'vlan'}.' ('.get_current_vlan_id($result_ip{$ip}->{'vlan'}).')';
     2789      my ($host_short) = split m/ \. /xms, $result_ip{$ip}->{'hostname_fq'};
     2790
     2791      my $vlan_nameid = $result_ip{$ip}->{'vlan'} . ' (' . get_current_vlan_id($result_ip{$ip}->{'vlan'}) . ')';
    27902792
    27912793      fqdn_html_breakable(my $hostname_fq_html = $result_ip{$ip}->{'hostname_fq'});
     
    28432845   die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
    28442846
    2845    my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
     2847   my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} . '.' . $port_id;
    28462848   print "Info: switch $switch_name port $port_hr SNMP OID $oid_search_portstatus\n" if $verbose;
    28472849
     
    28882890   die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
    28892891
    2890    my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
     2892   my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} . '.' . $port_id;
    28912893   print "Info: switch $switch_name port $port_hr SNMP OID $oid_search_portstatus\n" if $verbose;
    28922894
     
    29242926
    29252927   my $sw = $SWITCH_DB{$switch_name};
    2926    my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2928   my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    29272929   print "$error \n" if $error;
    29282930
     
    29312933   die "Error : Port $port_hr does not exist on switch $switch_name\n" if not $port_id =~ m/^\d+$/;
    29322934
    2933    my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} .'.'. $port_id;
     2935   my $oid_search_portstatus = $OID_NUMBER{'portUpDown'} . '.' . $port_id;
    29342936   print "Info: switch $switch_name port $port_hr ($port_id) SNMP OID $oid_search_portstatus\n" if $verbose;
    29352937
     
    29682970
    29692971   $mac_address = normalize_mac_address($mac_address);
    2970    $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST ) if $switch_name eq q{*} or $switch_name eq q{all};
     2972   $switch_name = join(',', map {$_->{'hostname'}} @SWITCH_LIST) if $switch_name eq q{*} or $switch_name eq q{all};
    29712973
    29722974   for my $sw_name (split /,/, $switch_name) {
     
    29762978
    29772979      my $oid_search_port1 = $OID_NUMBER{'searchPort1'} . mac_address_hex2dec($mac_address);
    2978       my $oid_search_port2 = $OID_NUMBER{'searchPort2'} .'.'. $vlan_id . mac_address_hex2dec($mac_address);
     2980      my $oid_search_port2 = $OID_NUMBER{'searchPort2'} . '.' . $vlan_id . mac_address_hex2dec($mac_address);
    29792981      print "Klask search OID $oid_search_port1 on switch $sw_name\n" if $verbose;
    29802982      print "Klask search OID $oid_search_port2 on switch $sw_name\n" if $verbose;
    29812983
    29822984      my $sw = $SWITCH_DB{$sw_name};
    2983       my ($session, $error) = Net::SNMP->session( %{$sw->{'snmp_param_session'}} );
     2985      my ($session, $error) = Net::SNMP->session(%{$sw->{'snmp_param_session'}});
    29842986      print "$error \n" if $error;
    29852987
     
    30273029   test_switchdb_environnement();
    30283030
    3029    my $format = 'txt';
     3031   my $format       = 'txt';
    30303032   my $graph_modulo = 0;
    30313033   my $graph_shift  = 1;
    30323034
    30333035   GetOptions(
    3034       'format|f=s'  => \$format,
    3035       'modulo|m=i'  => \$graph_modulo,
    3036       'shift|s=i'   => \$graph_shift,
     3036      'format|f=s' => \$format,
     3037      'modulo|m=i' => \$graph_modulo,
     3038      'shift|s=i'  => \$graph_shift,
    30373039      );
    30383040
     
    30703072      );
    30713073   for my $sw (sort keys %db_switch_output_port) {
    3072       my $arrow ='--->';
    3073          $arrow ='===>' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
     3074      my $arrow = '--->';
     3075      $arrow = '===>' if $db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/;
    30743076      if (exists $db_switch_parent{$sw}) {
    30753077         $tb_child->add($sw, $db_switch_output_port{$sw}, $arrow, $db_switch_parent{$sw}->{'port_hr'}, $db_switch_parent{$sw}->{'switch'});
     
    30803082         }
    30813083      }
    3082    my @colrange = map { scalar $tb_child->colrange($_) } (0 .. 4); # force scaler context
    3083    $tb_child->add(map { ' ' x $_ } reverse @colrange); # add empty line to force symetric table output
     3084   my @colrange = map {scalar $tb_child->colrange($_)} (0 .. 4); # force scaler context
     3085   $tb_child->add(map {' ' x $_} reverse @colrange);            # add empty line to force symetric table output
    30843086   print $tb_child->title();
    30853087   print $tb_child->rule('-');
    3086    print $tb_child->body(0, $tb_child->body_height()-1); # remove last fake line
     3088   print $tb_child->body(0, $tb_child->body_height() - 1);      # remove last fake line
    30873089   $tb_child->clear;
    30883090
    30893091   # Switch parent and children port inter-connection
    30903092   print "\n";
    3091    my $tb_parent = Text::Table->new( # http://www.perlmonks.org/?node_id=988320
     3093   my $tb_parent = Text::Table->new(                             # http://www.perlmonks.org/?node_id=988320
    30923094      {align => 'left',   align_title => 'left',   title => 'Parent-Switch'},
    30933095      {align => 'right',  align_title => 'right',  title => 'Input-Port'},
     
    30993101      my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2;
    31003102      for my $sw (keys %{$db_switch_connected_on_port{$swport}}) {
    3101          my $arrow ='<---';
    3102             $arrow ='<===' if $port_connect =~ m/^(Trk|Br|Po)/;
     3103         my $arrow = '<---';
     3104         $arrow = '<===' if $port_connect =~ m/^(Trk|Br|Po)/;
    31033105         if (exists $db_switch_output_port{$sw}) {
    31043106            $tb_parent->add($sw_connect, $port_connect, $arrow, $db_switch_output_port{$sw}, $sw);
     
    31093111         }
    31103112      }
    3111    @colrange = map { scalar $tb_parent->colrange($_) } (0 .. 4); # force scaler context
    3112    $tb_parent->add(map { ' ' x $_ } reverse @colrange); # add empty line to force symetric table output
     3113   @colrange = map {scalar $tb_parent->colrange($_)} (0 .. 4); # force scaler context
     3114   $tb_parent->add(map {' ' x $_} reverse @colrange);          # add empty line to force symetric table output
    31133115   print $tb_parent->title();
    31143116   print $tb_parent->rule('-');
    3115    print $tb_parent->body(0, $tb_parent->body_height()-1); # remove last fake line
     3117   print $tb_parent->body(0, $tb_parent->body_height() - 1);  # remove last fake line
    31163118   $tb_parent->clear;
    31173119
     
    31353137   my $invisible_node = 0; # Count number of invisible node
    31363138
    3137    my %db_building= ();
     3139   my %db_building    = ();
    31383140   my %db_switch_line = (); # Number of line drawed on a switch
    31393141   for my $sw (values %db_switch_global) {
     
    31413143      $db_building{$building} ||= {};
    31423144      $db_building{$building}->{$location} ||= {};
    3143       $db_building{$building}->{$location}{ $sw->{'hostname'} } = 'y';
     3145      $db_building{$building}->{$location}{$sw->{'hostname'}} = 'y';
    31443146
    31453147      $db_switch_line{$sw} = 0;
     
    31543156   print "internet [label=\"internet\", color=black, fillcolor=cyan, shape=house, style=filled];\n";
    31553157
    3156    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime $timestamp;
     3158   my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime $timestamp;
    31573159   $year += 1900;
    31583160   $mon++;
     
    31613163   print "site -> \"$date\" [style=invis];\n";
    31623164
    3163    my $b=0;
     3165   my $b = 0;
    31643166   for my $building (keys %db_building) {
    31653167      $b++;
     
    31793181
    31803182            my $peripheries = 1;
    3181             my $color = 'lightblue';
     3183            my $color       = 'lightblue';
    31823184            if ($db_switch_output_port{$sw} =~ m/^(Trk|Br|Po)/) {
    31833185               $peripheries = 2;
    3184                $color = "\"$color:$color\"";
     3186               $color       = "\"$color:$color\"";
    31853187               }
    31863188            print "\"$sw:$db_switch_output_port{$sw}\" [label=\"".format_aggregator4dot($db_switch_output_port{$sw})."\", color=black, fillcolor=lightblue, peripheries=$peripheries, style=filled];\n";
     
    31983200               next if $port_connect eq $db_switch_output_port{$sw};
    31993201               my $peripheries = 1;
    3200                my $color = 'plum';
     3202               my $color       = 'plum';
    32013203               if ($port_connect =~ m/^(Trk|Br|Po)/) {
    32023204                  $peripheries = 2;
    3203                   $color = "\"$color:$color\"";
     3205                  $color       = "\"$color:$color\"";
    32043206                  }
    32053207               print "\"$sw:$port_connect\" [label=\"".format_aggregator4dot($port_connect)."\", color=black, fillcolor=plum, peripheries=$peripheries, style=filled];\n";
     
    32153217               #   print "$invisible            -> \"$sw\"    [style=invis]\n";
    32163218               #   }
    3217               }
     3219               }
    32183220            }
    32193221         }
    32203222      }
    32213223
    3222 #   print "Switch output port and parent port connection\n";
    3223 #   print "---------------------------------------------\n";
     3224   #   print "Switch output port and parent port connection\n";
     3225   #   print "---------------------------------------------\n";
    32243226   for my $sw (sort keys %db_switch_output_port) {
    32253227      if (exists $db_switch_parent{$sw}) {
     
    32413243   my $graph_breaker = 1;
    32423244
    3243 #   print "Switch parent and children port inter-connection\n";
    3244 #   print "------------------------------------------------\n";
     3245   #   print "Switch parent and children port inter-connection\n";
     3246   #   print "------------------------------------------------\n";
    32453247   for my $swport (sort keys %db_switch_connected_on_port) {
    32463248      my ($sw_connect, $port_connect) = split m/ $SEP_SWITCH_PORT /xms, $swport, 2;
     
    32823284      }
    32833285
    3284 print "}\n";
     3286   print "}\n";
    32853287   return;
    32863288   }
Note: See TracChangeset for help on using the changeset viewer.