Changeset 218 for trunk/klask
- Timestamp:
- Feb 18, 2017, 3:56:47 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r217 r218 7 7 use strict; 8 8 use warnings; 9 use version; our $VERSION = qv('0.6. 0');9 use version; our $VERSION = qv('0.6.1'); 10 10 11 11 use Readonly; … … 24 24 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 25 25 # arping net-tools fping bind9-host arpwatch 26 27 ################################################################ 28 # general initialization 29 ################################################################ 26 30 27 31 my $KLASK_VAR = '/var/lib/klask'; … … 85 89 ); 86 90 87 Readonly my %INTERNAL_PORT_MAP => (88 0 => 'A',89 1 => 'B',90 2 => 'C',91 3 => 'D',92 4 => 'E',93 5 => 'F',94 6 => 'G',95 7 => 'H',96 );97 Readonly my %INTERNAL_PORT_MAP_REV => reverse %INTERNAL_PORT_MAP;91 #Readonly my %INTERNAL_PORT_MAP => ( 92 # 0 => 'A', 93 # 1 => 'B', 94 # 2 => 'C', 95 # 3 => 'D', 96 # 4 => 'E', 97 # 5 => 'F', 98 # 6 => 'G', 99 # 7 => 'H', 100 # ); 101 #Readonly my %INTERNAL_PORT_MAP_REV => reverse %INTERNAL_PORT_MAP; 98 102 99 103 Readonly my %SWITCH_KIND => ( … … 180 184 Readonly my $RE_FLOAT_HOSTNAME => qr{ ^float }xms; 181 185 182 ################ 186 ################################################################ 183 187 # main program 184 ################ 188 ################################################################ 185 189 186 190 my $cmd = shift @ARGV || 'help'; … … 196 200 exit; 197 201 198 ################ 202 ################################################################ 199 203 # subroutine 200 ################ 201 204 ################################################################ 205 206 #--------------------------------------------------------------- 202 207 sub test_running_environnement { 203 208 die "Configuration file $KLASK_CFG_FILE does not exists. Klask need it !\n" if not -e "$KLASK_CFG_FILE"; … … 206 211 } 207 212 213 #--------------------------------------------------------------- 208 214 sub test_switchdb_environnement { 209 215 die "Switch database $KLASK_SW_FILE does not exists. Launch updatesw before this command !\n" if not -e "$KLASK_SW_FILE"; … … 211 217 } 212 218 219 #--------------------------------------------------------------- 213 220 sub test_maindb_environnement { 214 221 die "Main database $KLASK_DB_FILE does not exists. Launch updatedb before this command !\n" if not -e "$KLASK_DB_FILE"; … … 216 223 } 217 224 218 # ##225 #--------------------------------------------------------------- 219 226 # fast ping dont l'objectif est de remplir la table arp de la machine 220 227 sub fast_ping { … … 224 231 } 225 232 233 #--------------------------------------------------------------- 226 234 sub shell_command { 227 235 my $cmd = shift; … … 236 244 } 237 245 238 # ##246 #--------------------------------------------------------------- 239 247 # donne l'@ ip, dns, arp en fonction du dns OU de l'ip 240 248 sub resolve_ip_arp_host { … … 339 347 } 340 348 341 # ##349 #--------------------------------------------------------------- 342 350 # va rechercher le nom des switchs pour savoir qui est qui 343 351 sub init_switch_names { … … 399 407 } 400 408 401 # ##409 #--------------------------------------------------------------- 402 410 # convertit l'hexa (uniquement 2 chiffres) en decimal 403 411 sub digit_hex_to_dec { … … 415 423 } 416 424 417 #--------------------------------------------------------------- -----------------425 #--------------------------------------------------------------- 418 426 419 427 sub normalize_mac_address { … … 430 438 } 431 439 432 #--------------------------------------------------------------- -----------------440 #--------------------------------------------------------------- 433 441 # convertit l'@ mac en decimal 434 442 sub mac_address_hex_to_dec { … … 444 452 } 445 453 446 # ##454 #--------------------------------------------------------------- 447 455 # va rechercher le port et le switch sur lequel est la machine 448 456 sub find_switch_port { … … 515 523 } 516 524 517 # ##525 #--------------------------------------------------------------- 518 526 # va rechercher les port et les switch sur lequel est la machine 519 527 sub find_all_switch_port { … … 568 576 } 569 577 578 #--------------------------------------------------------------- 570 579 sub get_list_network { 571 580 … … 573 582 } 574 583 584 #--------------------------------------------------------------- 575 585 sub get_current_interface { 576 586 my $vlan_name = shift; … … 579 589 } 580 590 591 #--------------------------------------------------------------- 581 592 sub get_current_vlan_id { 582 593 my $vlan_name = shift; … … 586 597 } 587 598 599 #--------------------------------------------------------------- 588 600 sub get_current_scan_mode { 589 601 my $vlan_name = shift; … … 592 604 } 593 605 606 #--------------------------------------------------------------- 594 607 sub get_current_vlan_name_for_interface { 595 608 my $interface = shift; … … 601 614 } 602 615 603 # ##616 #--------------------------------------------------------------- 604 617 # liste l'ensemble des adresses ip d'un réseau 605 618 sub get_list_ip { … … 630 643 } 631 644 645 #--------------------------------------------------------------- 632 646 # liste l'ensemble des routeurs du réseau 633 647 sub get_list_main_router { … … 643 657 } 644 658 659 #--------------------------------------------------------------- 645 660 sub get_human_readable_port { 646 661 my $sw_model = shift; … … 650 665 # get port name by snmp 651 666 return $sw_port; 652 653 if ($sw_model eq 'HP8000M') { 654 655 my $reste = (($sw_port - 1) % 8) + 1; 656 my $major = int (($sw_port - 1) / 8); 657 return "$INTERNAL_PORT_MAP{$major}$reste"; 658 } 659 660 if ($sw_model eq 'HP2424M') { 661 if ($sw_port > 24) { 662 663 my $reste = $sw_port - 24; 664 return "A$reste"; 665 } 666 } 667 668 if ($sw_model eq 'HP1600M') { 669 if ($sw_port > 16) { 670 671 my $reste = $sw_port - 16; 672 return "A$reste"; 673 } 674 } 675 676 if ($sw_model eq 'HP2810-48G' or $sw_model eq 'HP2810-24G') { 677 if ($sw_port > 48) { 678 679 my $reste = $sw_port - 48; 680 return "Trk$reste"; 681 } 682 } 683 684 if ($sw_model eq 'HP3500-24G') { 685 if ($sw_port > 289) { 686 687 my $reste = $sw_port - 289; 688 return "Trk$reste"; 689 } 690 } 691 692 return $sw_port; 693 } 694 695 sub get_numerical_port { 696 my $sw_model = shift; 697 my $sw_port = shift; 698 699 if ($sw_model eq 'HP8000M') { 700 701 my $letter = substr $sw_port, 0, 1; 702 my $reste = substr $sw_port, 1; 703 704 return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste; 705 } 706 707 if ($sw_model eq 'HP2424M') { 708 if ($sw_port =~ m/^A/xms ) { 709 710 my $reste = substr $sw_port, 1; 711 712 return 24 + $reste; 713 } 714 } 715 716 if ($sw_model eq 'HP1600M') { 717 if ($sw_port =~ m/^A/xms ) { 718 719 my $reste = substr $sw_port, 1; 720 721 return 16 + $reste; 722 } 723 } 724 725 if ($sw_model eq 'HP2810-48G' or $sw_model eq 'HP2810-24G') { 726 if ($sw_port =~ m/^Trk/xms ) { 727 728 my $reste = substr $sw_port, 3; 729 730 return 48 + $reste; 731 } 732 } 733 734 if ($sw_model eq 'HP3500-24G') { 735 if ($sw_port =~ m/^Trk/xms ) { 736 737 my $reste = substr $sw_port, 3; 738 739 return 289 + $reste; 740 } 741 } 742 743 return $sw_port; 744 } 745 667 } 668 669 # if ($sw_model eq 'HP8000M') { 670 # 671 # my $reste = (($sw_port - 1) % 8) + 1; 672 # my $major = int (($sw_port - 1) / 8); 673 # return "$INTERNAL_PORT_MAP{$major}$reste"; 674 # } 675 # 676 # if ($sw_model eq 'HP2424M') { 677 # if ($sw_port > 24) { 678 # 679 # my $reste = $sw_port - 24; 680 # return "A$reste"; 681 # } 682 # } 683 # 684 # if ($sw_model eq 'HP1600M') { 685 # if ($sw_port > 16) { 686 # 687 # my $reste = $sw_port - 16; 688 # return "A$reste"; 689 # } 690 # } 691 # 692 # if ($sw_model eq 'HP2810-48G' or $sw_model eq 'HP2810-24G') { 693 # if ($sw_port > 48) { 694 # 695 # my $reste = $sw_port - 48; 696 # return "Trk$reste"; 697 # } 698 # } 699 # 700 # if ($sw_model eq 'HP3500-24G') { 701 # if ($sw_port > 289) { 702 # 703 # my $reste = $sw_port - 289; 704 # return "Trk$reste"; 705 # } 706 # } 707 # 708 # return $sw_port; 709 710 #sub get_numerical_port { 711 # my $sw_model = shift; 712 # my $sw_port = shift; 713 # 714 # if ($sw_model eq 'HP8000M') { 715 # 716 # my $letter = substr $sw_port, 0, 1; 717 # my $reste = substr $sw_port, 1; 718 # 719 # return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste; 720 # } 721 # 722 # if ($sw_model eq 'HP2424M') { 723 # if ($sw_port =~ m/^A/xms ) { 724 # 725 # my $reste = substr $sw_port, 1; 726 # 727 # return 24 + $reste; 728 # } 729 # } 730 # 731 # if ($sw_model eq 'HP1600M') { 732 # if ($sw_port =~ m/^A/xms ) { 733 # 734 # my $reste = substr $sw_port, 1; 735 # 736 # return 16 + $reste; 737 # } 738 # } 739 # 740 # if ($sw_model eq 'HP2810-48G' or $sw_model eq 'HP2810-24G') { 741 # if ($sw_port =~ m/^Trk/xms ) { 742 # 743 # my $reste = substr $sw_port, 3; 744 # 745 # return 48 + $reste; 746 # } 747 # } 748 # 749 # if ($sw_model eq 'HP3500-24G') { 750 # if ($sw_port =~ m/^Trk/xms ) { 751 # 752 # my $reste = substr $sw_port, 3; 753 # 754 # return 289 + $reste; 755 # } 756 # } 757 # 758 # return $sw_port; 759 # } 760 761 #--------------------------------------------------------------- 746 762 sub normalize_port_human_readable { 747 763 my $sw_port_hr = shift; … … 762 778 } 763 779 780 #--------------------------------------------------------------- 764 781 sub snmp_get_switchport_hr { 765 782 my ($snmp_session, $swport) = @_; … … 781 798 } 782 799 800 #--------------------------------------------------------------- 783 801 # Reverse search port number 784 802 sub snmp_get_switchport_num { … … 819 837 } 820 838 839 #--------------------------------------------------------------- 821 840 # Load computer database 822 841 sub computerdb_load { … … 834 853 } 835 854 836 ################ 837 # Les commandes 838 ################ 839 855 ################################################################ 856 # command 857 ################################################################ 858 859 #--------------------------------------------------------------- 840 860 sub cmd_help { 841 861 … … 868 888 } 869 889 890 #--------------------------------------------------------------- 870 891 sub cmd_version { 871 892 … … 904 925 } 905 926 927 #--------------------------------------------------------------- 906 928 sub cmd_searchdb { 907 929 my @ARGV = @_; … … 925 947 926 948 949 #--------------------------------------------------------------- 927 950 sub cmd_searchdb_host { 928 951 my @computer = @_; … … 954 977 } 955 978 979 #--------------------------------------------------------------- 956 980 sub cmd_searchdb_mac { 957 981 my @mac = map { normalize_mac_address($_) } @_; … … 984 1008 } 985 1009 1010 #--------------------------------------------------------------- 986 1011 sub cmd_updatedb { 987 1012 @ARGV = @_; … … 1173 1198 } 1174 1199 1200 #--------------------------------------------------------------- 1175 1201 sub cmd_removedb { 1176 1202 my @computer = @_; … … 1201 1227 } 1202 1228 1229 #--------------------------------------------------------------- 1203 1230 sub cmd_cleandb { 1204 1231 my @ARGV = @_; … … 1315 1342 } 1316 1343 1344 #--------------------------------------------------------------- 1317 1345 sub cmd_exportdb { 1318 1346 @ARGV = @_; … … 1335 1363 } 1336 1364 1365 #--------------------------------------------------------------- 1337 1366 sub cmd_exportdb_txt { 1338 1367 test_maindb_environnement(); … … 1374 1403 } 1375 1404 1405 #--------------------------------------------------------------- 1376 1406 sub cmd_exportdb_html { 1377 1407 test_maindb_environnement(); … … 1596 1626 } 1597 1627 1628 #--------------------------------------------------------------- 1598 1629 sub cmd_bad_vlan_id { 1599 1630 test_maindb_environnement(); … … 1684 1715 } 1685 1716 1717 #--------------------------------------------------------------- 1686 1718 sub cmd_set_vlan_port { 1687 1719 my $switch_name = shift || q{}; … … 1731 1763 } 1732 1764 1765 #--------------------------------------------------------------- 1733 1766 sub cmd_get_vlan_port { 1734 1767 @ARGV = @_; … … 1774 1807 } 1775 1808 1809 #--------------------------------------------------------------- 1776 1810 sub cmd_set_vlan_name { 1777 1811 } 1778 1812 1813 #--------------------------------------------------------------- 1779 1814 # snmpset -v 1 -c public sw1-batG0-legi.hmg.priv "$OID_NUMBER{'hpicfReset'}.0" i 2; 1780 1815 sub cmd_rebootsw { … … 1810 1845 } 1811 1846 1847 #--------------------------------------------------------------- 1812 1848 sub cmd_get_vlan_name { 1813 1849 my $switch_name = shift || q{}; … … 1848 1884 } 1849 1885 1886 #--------------------------------------------------------------- 1850 1887 sub cmd_ip_location { 1851 1888 my $computerdb = computerdb_load(); … … 1872 1909 } 1873 1910 1911 #--------------------------------------------------------------- 1874 1912 sub cmd_ip_free { 1875 1913 @ARGV = @_; # VLAN name with option … … 1948 1986 } 1949 1987 1988 #--------------------------------------------------------------- 1950 1989 sub cmd_ip_free_txt { 1951 1990 my %result_ip = @_; … … 1960 1999 } 1961 2000 2001 #--------------------------------------------------------------- 1962 2002 sub cmd_ip_free_html { 1963 2003 my %result_ip = @_; … … 2012 2052 } 2013 2053 2054 #--------------------------------------------------------------- 2014 2055 sub cmd_enable { 2015 2056 @ARGV = @_; … … 2056 2097 } 2057 2098 2099 #--------------------------------------------------------------- 2058 2100 sub cmd_disable { 2059 2101 @ARGV = @_; … … 2098 2140 } 2099 2141 2142 #--------------------------------------------------------------- 2100 2143 sub cmd_status { 2101 2144 @ARGV = @_; … … 2143 2186 } 2144 2187 2188 #--------------------------------------------------------------- 2145 2189 sub cmd_search_mac_on_switch { 2146 2190 @ARGV = @_; … … 2202 2246 } 2203 2247 2248 #--------------------------------------------------------------- 2204 2249 sub cmd_updatesw { 2205 2250 @ARGV = @_; … … 2421 2466 } 2422 2467 2468 #--------------------------------------------------------------- 2423 2469 sub cmd_exportsw { 2424 2470 @ARGV = @_; … … 2443 2489 } 2444 2490 2491 #--------------------------------------------------------------- 2445 2492 sub cmd_exportsw_txt { 2446 2493 … … 2479 2526 } 2480 2527 2528 #--------------------------------------------------------------- 2481 2529 sub cmd_exportsw_dot { 2482 2530 … … 2580 2628 2581 2629 2630 ################################################################ 2631 # documentation 2632 ################################################################ 2633 2582 2634 __END__ 2583 2635 … … 2645 2697 2646 2698 This command activate a port on a switch by SNMP. 2647 So you need to give the switch and the port numberon the command line.2648 Actually, port number must be a number and not the name alias...2699 So you need to give the switch and a port on the command line. 2700 See L<ABBREVIATION FOR PORT>. 2649 2701 2650 2702 … … 2652 2704 2653 2705 This command deactivate a port on a switch by SNMP. 2654 So you need to give the switch and the port numberon the command line.2655 Actually, port number must be a number and not the name alias...2706 So you need to give the switch and a port on the command line. 2707 See L<ABBREVIATION FOR PORT>. 2656 2708 2657 2709 … … 2659 2711 2660 2712 This command return the status of a port number on a switch by SNMP. 2661 So you need to give the switch name and the port number on the command line. 2662 Actually, port number must be a number and not the name alias... 2663 2713 So you need to give the switch and a port on the command line. 2714 See L<ABBREVIATION FOR PORT>. 2664 2715 2665 2716 =head2 updatedb … … 2760 2811 2761 2812 2813 =head1 ABBREVIATION FOR PORT 2814 2815 HP Procurve and Nexans switches have a simplistic numbering scheme. 2816 It's just number: 1, 2, 3... 24. 2817 On HP8000 chassis, ports names begin with an uppercase letter: A1, A2... 2818 Nothing is done on theses ports names. 2819 2820 On HP Comware and DELL, port digitization schema use a port speed word (generally a very verbose word) 2821 followed by tree number. 2822 In order to have short name, 2823 we made the following rules: 2824 2825 Bridge-Aggregation -> Br 2826 FastEthernet -> Fa 2827 Forty-GigabitEthernet -> Fo 2828 FortyGigabitEthernet -> Fo 2829 GigabitEthernet -> Gi 2830 Giga -> Gi 2831 Port-Channel -> Po 2832 Ten-GigabitEthernet -> Te 2833 TenGigabitEthernet -> Te 2834 Ten -> Te 2835 2836 All Klask command automatically normalize the port name on standart output 2837 and also on input command line. 2838 2839 2762 2840 =head1 FILES 2763 2841
Note: See TracChangeset
for help on using the changeset viewer.