Changeset 11
- Timestamp:
- Jan 31, 2008, 11:16:17 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r10 r11 13 13 # libcrypt-des-perl libcrypt-hcesha-perl libdigest-hmac-perl 14 14 15 our$KLASK_DB = '/var/cache/klask/klaskdb';16 our$KLASK_SW = '/var/cache/klask/switchdb';17 our$KLASK_CFG = '/etc/klask.conf';18 19 my $ switchdb= YAML::LoadFile("$KLASK_CFG");20 21 our %default = %{$switchdb->{default}};22 our @switch = @{$switchdb->{switch}};23 24 our%switch_level = ();15 my $KLASK_DB = '/var/cache/klask/klaskdb'; 16 my $KLASK_SW = '/var/cache/klask/switchdb'; 17 my $KLASK_CFG = '/etc/klask.conf'; 18 19 my $SWITCH_DB = YAML::LoadFile("$KLASK_CFG"); 20 21 my %DEFAULT = %{$SWITCH_DB->{default}}; 22 my @SWITCH = @{$SWITCH_DB->{switch}}; 23 24 my %switch_level = (); 25 25 LEVEL_OF_EACH_SWITCH: 26 for my $sw (@ switch){27 $switch_level{$sw->{hostname}} = $sw->{level} || $ default{switch_level} || 2;28 } 29 @ switch = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$switchdb->{switch}};30 31 our%switch_port_count = ();32 33 our %cmddb= (26 for my $sw (@SWITCH){ 27 $switch_level{$sw->{hostname}} = $sw->{level} || $DEFAULT{switch_level} || 2; 28 } 29 @SWITCH = sort { $switch_level{$b->{hostname}} <=> $switch_level{$a->{hostname}} } @{$SWITCH_DB->{switch}}; 30 31 my %switch_port_count = (); 32 33 my %CMD_DB = ( 34 34 help => \&cmd_help, 35 35 exportdb => \&cmd_exportdb, … … 47 47 ); 48 48 49 our %INTERNALPORTMAP = (49 my %INTERNAL_PORT_MAP = ( 50 50 0 => 'A', 51 51 1 => 'B', … … 57 57 7 => 'H', 58 58 ); 59 our %INTERNALPORTMAPREV = reverse %INTERNALPORTMAP;59 my %INTERNAL_PORT_MAP_REV = reverse %INTERNAL_PORT_MAP; 60 60 61 61 … … 64 64 ################ 65 65 66 my $cmd = shift || 'help';67 if (defined $ cmddb{$cmd}) {68 $ cmddb{$cmd}->(@ARGV);66 my $cmd = shift @ARGV || 'help'; 67 if (defined $CMD_DB{$cmd}) { 68 $CMD_DB{$cmd}->(@ARGV); 69 69 } 70 70 else { 71 71 print STDERR "klask: command $cmd not found\n\n"; 72 $ cmddb{help}->();72 $CMD_DB{help}->(); 73 73 exit 1; 74 74 } … … 168 168 169 169 INIT_EACH_SWITCH: 170 for my $sw (@ switch) {170 for my $sw (@SWITCH) { 171 171 #print "$sw->{hostname} \n"; 172 172 my %session = ( -hostname => $sw->{hostname} ); 173 173 $session{-version} = $sw->{version} || 1; 174 $session{-port} = $sw->{snmpport} || $ default{snmpport} || 161;174 $session{-port} = $sw->{snmpport} || $DEFAULT{snmpport} || 161; 175 175 if (exists $sw->{version} and $sw->{version} eq 3) { 176 176 $session{-username} = $sw->{username} || 'snmpadmin'; … … 181 181 } 182 182 else { 183 $session{-community} = $sw->{community} || $ default{community} || 'public';183 $session{-community} = $sw->{community} || $DEFAULT{community} || 'public'; 184 184 } 185 185 … … 189 189 # -hostname => $sw->{hostname}, 190 190 # -version => $sw->{version} || 1, 191 # -community => $sw->{community} || $ default{community} || 'public',191 # -community => $sw->{community} || $DEFAULT{community} || 'public', 192 192 # -username => $sw->{username} || 'snmpadmin', 193 # -port => $sw->{snmpport} || $ default{snmpport} || 161,193 # -port => $sw->{snmpport} || $DEFAULT{snmpport} || 161, 194 194 # ); 195 195 # if (exists $sw->{version} and $sw->{version} eq 3) { … … 252 252 return %ret if $arp eq 'unknow';; 253 253 254 my @ switch_search = @switch;254 my @SWITCH_search = @SWITCH; 255 255 if ($switch_proposal ne '') { 256 for my $sw (@ switch) {256 for my $sw (@SWITCH) { 257 257 next if $sw->{hostname} ne $switch_proposal; 258 unshift @ switch_search, $sw;258 unshift @SWITCH_search, $sw; 259 259 last; 260 260 } … … 264 264 265 265 LOOP_ON_SWITCH: 266 for my $sw (@ switch_search) {266 for my $sw (@SWITCH_search) { 267 267 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 268 268 print "$error \n" if $error; 269 269 # -hostname => $sw->{hostname}, 270 # -community => $sw->{community} || $ default{community} || 'public',271 # -port => $sw->{snmpport} || $ default{snmpport} || 161270 # -community => $sw->{community} || $DEFAULT{community} || 'public', 271 # -port => $sw->{snmpport} || $DEFAULT{snmpport} || 161 272 272 # ); 273 273 #print "$sw->{hostname} -- $research \n"; … … 323 323 return $ret if $arp eq 'unknow'; 324 324 325 for my $sw (@ switch) {325 for my $sw (@SWITCH) { 326 326 $switch_port_count{$sw->{hostname}} = {} if not exists $switch_port_count{$sw->{hostname}}; 327 327 # $sw->{_port} = {} if not exists $sw->{_port}; … … 331 331 #print " $arp -> $research\n"; 332 332 LOOP_ON_ALL_SWITCH: 333 for my $sw (@ switch) {333 for my $sw (@SWITCH) { 334 334 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 335 335 print "$error \n" if $error; 336 336 # -hostname => $sw->{hostname}, 337 # -community => $sw->{community} || $ default{community} || 'public',338 # -port => $sw->{snmpport} || $ default{snmpport} || 161337 # -community => $sw->{community} || $DEFAULT{community} || 'public', 338 # -port => $sw->{snmpport} || $DEFAULT{snmpport} || 161 339 339 # ); 340 340 #print "$sw->{hostname} -- $research \n"; … … 366 366 sub get_list_network { 367 367 368 return keys %{$ switchdb->{network}};368 return keys %{$SWITCH_DB->{network}}; 369 369 } 370 370 … … 372 372 my $network = shift; 373 373 374 return $ switchdb->{network}{$network}{interface};374 return $SWITCH_DB->{network}{$network}{interface}; 375 375 } 376 376 … … 383 383 384 384 for my $net (@network) { 385 my @line = @{$ switchdb->{network}{$net}{'ip-subnet'}};385 my @line = @{$SWITCH_DB->{network}{$net}{'ip-subnet'}}; 386 386 for my $cmd (@line) { 387 387 for my $method (keys %$cmd){ … … 411 411 412 412 for my $net (@network) { 413 push @res, $ switchdb->{network}{$net}{'main-router'};413 push @res, $SWITCH_DB->{network}{$net}{'main-router'}; 414 414 } 415 415 … … 426 426 my $major = int( ($port - 1) / 8 ); 427 427 428 return "$INTERNAL PORTMAP{$major}$reste";428 return "$INTERNAL_PORT_MAP{$major}$reste"; 429 429 } 430 430 … … 441 441 my $reste = substr($port, 1); 442 442 443 return $INTERNAL PORTMAPREV{$letter} * 8 + $reste;443 return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste; 444 444 } 445 445 … … 722 722 723 723 my $sw_location = ''; 724 for my $sw (@ switch) {724 for my $sw (@SWITCH) { 725 725 next if $sw_hostname ne $sw->{hostname}; 726 726 $sw_location = $sw->{location}; … … 767 767 DETECT_ALL_ROUTER: 768 768 # for my $one_computer ('194.254.66.254') { 769 for my $one_ computer ( get_list_main_router(get_list_network()) ) {770 my %resol_arp = resolve_ip_arp_host($one_ computer,'*','low'); #resolution arp769 for my $one_router ( get_list_main_router(get_list_network()) ) { 770 my %resol_arp = resolve_ip_arp_host($one_router,'*','low'); #resolution arp 771 771 next DETECT_ALL_ROUTER if $resol_arp{mac_address} eq 'unknow'; 772 772 … … 802 802 my @list_switch_ip = (); 803 803 my @list_switch_ipv4 = (); 804 for my $sw (@ switch){804 for my $sw (@SWITCH){ 805 805 push @list_switch_ip, $sw->{hostname}; 806 806 } … … 1000 1000 1001 1001 my %db_building= (); 1002 for my $sw (@ switch) {1002 for my $sw (@SWITCH) { 1003 1003 my ($building, $location) = split /\//, $sw->{location}, 2; 1004 1004 $db_building{$building} ||= {};
Note: See TracChangeset
for help on using the changeset viewer.