Changeset 22
- Timestamp:
- Feb 2, 2008, 9:59:29 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/klask
r21 r22 181 181 # Find Surname of a switch 182 182 sub get_switch_model { 183 my $sw_ description = shift || '?';183 my $sw_snmp_description = shift || 'unknow'; 184 184 185 185 for my $sw_kind (keys %SWITCH_KIND) { 186 next if not $sw_ description =~ m/$SWITCH_KIND{$sw_kind}->{match}/;186 next if not $sw_snmp_description =~ m/$SWITCH_KIND{$sw_kind}->{match}/; 187 187 188 188 return $SWITCH_KIND{$sw_kind}->{model}; 189 189 } 190 190 191 return $sw_ description;191 return $sw_snmp_description; 192 192 } 193 193 … … 231 231 #$sw->{contact} = $result->{"1.3.6.1.2.1.1.4.0"} || $sw->{hostname}; 232 232 $session->close; 233 233 234 # Ligne à virer car on récupère maintenant le modèle du switch 234 235 my ($desc, $type) = split ':', $sw->{description}, 2; 235 236 # printf "%-25s 0--------->>>> %-25s %s\n", $sw->{hostname}, $desc, uc($type)."**" if $verbose; … … 281 282 return %ret if $arp eq 'unknow';; 282 283 283 my @ SWITCH_search = @SWITCH;284 my @switch_search = @SWITCH; 284 285 if ($switch_proposal ne '') { 285 286 for my $sw (@SWITCH) { 286 287 next if $sw->{hostname} ne $switch_proposal; 287 unshift @ SWITCH_search, $sw;288 unshift @switch_search, $sw; 288 289 last; 289 290 } … … 293 294 294 295 LOOP_ON_SWITCH: 295 for my $sw (@ SWITCH_search) {296 for my $sw (@switch_search) { 296 297 my ($session, $error) = Net::SNMP->session( %{$sw->{local_session}} ); 297 print "$error \n" if $error; 298 # -hostname => $sw->{hostname}, 299 # -community => $sw->{community} || $DEFAULT{community} || 'public', 300 # -port => $sw->{snmpport} || $DEFAULT{snmpport} || 161 301 # ); 302 #print "$sw->{hostname} -- $research \n"; 298 print "$error \n" if $error; 299 303 300 my $result = $session->get_request( 304 301 -varbindlist => [$research] 305 302 ); 306 # if(defined($result)) {307 303 if (not defined($result) or $result->{$research} eq 'noSuchInstance') { 308 #print "$sw->{hostname} -- $research --".$session->error()."\n";309 304 $session->close; 310 305 next LOOP_ON_SWITCH; … … 323 318 SWITCH_PORT_IGNORE: 324 319 foreach my $p (@{$sw->{portignore}}) { 325 next SWITCH_PORT_IGNORE if $swport ne get_numerical_port($sw->{ hostname},$p);320 next SWITCH_PORT_IGNORE if $swport ne get_numerical_port($sw->{model},$p); 326 321 # $flag = 1; 327 322 next LOOP_ON_SWITCH; … … 330 325 $ret{switch_hostname} = $sw->{hostname}; 331 326 $ret{switch_description} = $sw->{description}; 332 $ret{switch_port} = get_human_readable_port($sw->{ hostname}, $swport); # $swport;327 $ret{switch_port} = get_human_readable_port($sw->{model}, $swport); # $swport; 333 328 334 329 last LOOP_ON_SWITCH; … … 369 364 $ret->{$sw->{hostname}}{hostname} = $sw->{hostname}; 370 365 $ret->{$sw->{hostname}}{description} = $sw->{description}; 371 $ret->{$sw->{hostname}}{port} = get_human_readable_port($sw->{ hostname}, $swport);366 $ret->{$sw->{hostname}}{port} = get_human_readable_port($sw->{model}, $swport); 372 367 373 368 $SWITCH_PORT_COUNT{$sw->{hostname}}->{$swport}++; … … 433 428 434 429 sub get_human_readable_port { 435 my $sw = shift;436 my $ port= shift;437 438 return $ port if not $sw eq 'sw8000-batA.hmg.priv';439 440 my $reste = (($ port - 1) % 8) + 1;441 my $major = int( ($ port - 1) / 8 );430 my $sw_model = shift; 431 my $sw_port = shift; 432 433 return $sw_port if not $sw_model eq 'HP8000M'; 434 435 my $reste = (($sw_port - 1) % 8) + 1; 436 my $major = int( ($sw_port - 1) / 8 ); 442 437 443 438 return "$INTERNAL_PORT_MAP{$major}$reste"; … … 445 440 446 441 sub get_numerical_port { 447 my $sw 448 my $ port= shift;449 450 return $ port if not $sw eq 'sw8000-batA.hmg.priv';451 452 my $letter = substr($ port, 0, 1);442 my $sw_model = shift; 443 my $sw_port = shift; 444 445 return $sw_port if not $sw_model eq 'HP8000'; 446 447 my $letter = substr($sw_port, 0, 1); 453 448 454 449 # return $port if $letter =~ m/\d/; 455 450 456 my $reste = substr($ port, 1);451 my $reste = substr($sw_port, 1); 457 452 458 453 return $INTERNAL_PORT_MAP_REV{$letter} * 8 + $reste; … … 527 522 my $computerdb = YAML::LoadFile("$KLASK_DB_FILE"); 528 523 my $timestamp = time; 529 524 530 525 my %computer_not_detected = (); 531 526 my $timestamp_last_week = $timestamp - (3600 * 24 * 7); … … 535 530 my $i = 0; 536 531 my $detected_computer = 0; 537 532 538 533 init_switch_names('yes'); #nomme les switchs 534 535 { # Remplis le champs portignore des ports d'inter-connection pour chaque switch 536 my $switch_connection = YAML::LoadFile("$KLASK_SW_FILE"); 537 my %db_switch_output_port = %{$switch_connection->{output_port}}; 538 my %db_switch_connected_on_port = %{$switch_connection->{connected_on_port}}; 539 my %db_switch_chained_port = (); 540 for my $swport (keys %db_switch_connected_on_port) { 541 my ($sw_connect,$port_connect) = split ':', $swport; 542 $db_switch_chained_port{$sw_connect} .= "$port_connect:"; 543 } 544 for my $sw (@SWITCH){ 545 push @{$sw->{portignore}}, $db_switch_output_port{$sw->{hostname}} if exists $db_switch_output_port{$sw->{hostname}}; 546 if ( exists $db_switch_chained_port{$sw->{hostname}} ) { 547 chop $db_switch_chained_port{$sw->{hostname}}; 548 push @{$sw->{portignore}}, split(':',$db_switch_chained_port{$sw->{hostname}}); 549 } 550 # print "$sw->{hostname} ++ @{$sw->{portignore}}\n"; 551 } 552 } 539 553 540 554 my %router_mac_ip = ();
Note: See TracChangeset
for help on using the changeset viewer.