[GTER] Ferramenta Perl para visualização de Sessão BGP

willian pires willian_pires at hotmail.com
Wed Jul 1 16:17:57 -03 2015


Só funciona em cisco.
Att 

> From: willian_pires at hotmail.com
> To: gter at eng.registro.br
> Date: Wed, 1 Jul 2015 15:00:17 -0400
> Subject: [GTER] Ferramenta Perl para visualização de Sessão BGP
> 
> Senhores segue um "software/script" em perl que auxilia o seu suporte,consegue assim ver quais sessões em bgp estão ativas e "grifa" as inativas.
> Basicamente, crie um arquivo verbgp.pl e de permissão de execução.O host de onde vc vai visualizar a sessão tem que ter permissão de snmp  public.
> Aí execute: 
> $verbgp.pl 178.55.21.1
> Aceito sugestões de melhorias.
> 
> #!/usr/bin/perl
> # script: versao 1.0 # autor: willian pires de souza willian_pires[ARROBA]emailquente.com# verbgp: depende de ping,snmpwalk e que o host onde executa tenha acesso snmp# bom uso.
> use Term::ANSIColor;
> 
> $destino = $ARGV[0];$ptipo =  $ARGV[1];$destino=~s/\s+//;
> print "\e[H\e[J";print "\e[H";
> 
> if($ptipo eq ""){        $ptipo="ether";}
> 
> if($destino eq ""){	print "Digite um ip exemplo 10.16.9.17";	exit();}else{
> 	$pstatus=`fping $destino | grep -i alive`;
> 		print "O host: $destino sera acessado.\r\n";		sleep(1);	if($pstatus ne ""){		&getall();			}else{		print "---- O Host: $destino esta indisponivel...\n";	}}
> 
> 
> sub sec2human {    my $secs = shift; 	$secs = int($secs);	$tret="";
>     if ($secs >= 86400) { $tret .= sprintf("%02d",int($secs/86400))."d ";$secs = $secs - ((int($secs/86400)*86400)); } else {$tret.="00d ";}    if ($secs >= 3600) { $tret .= sprintf("%02d",int($secs/3600))."h ";$secs = $secs - ((int($secs/3600)*3600)); }else {$tret.="00h ";}    if ($secs >= 60) { $tret .= sprintf("%02d",int($secs/60))."m ";$secs = $secs - ((int($secs/60)*60)); }else {$tret.="00m ";}    if ($secs >= 0) { $tret .= sprintf("%02d",int($secs))."s "; }else { $tret.="00s";}	return $tret;}
> 
> sub getall(){print "\e[H\e[J";print "\e[H";
> 
> print "Acessando: $destino ";
> $oid_as="snmpwalk -c public -v2c $destino 1.3.6.1.2.1.15.3.1.9 | awk -F \"INTEGER: \" '{ print \$2 }'";$oid_peer="snmpwalk -c public -v2c $destino 1.3.6.1.2.1.15.3.1.7 | awk -F \"IpAddress: \" '{ print \$2 }'";$oid_state="snmpwalk -c public -v2c $destino 1.3.6.1.2.1.15.3.1.2 | awk -F \"INTEGER: \" '{ print \$2 }'";$oid_msgrec="snmpwalk -c public -v2c $destino 1.3.6.1.2.1.15.3.1.12 | awk -F \"Counter32: \" '{ print \$2 }'";$oid_msgsen="snmpwalk -c public -v2c $destino 1.3.6.1.2.1.15.3.1.13 | awk -F \"Counter32: \" '{ print \$2 }'";$oid_prefixes="snmpwalk -c public -v2c $destino 1.3.6.1.4.1.9.9.187.1.2.4.1.1 | awk -F \"Counter32: \" '{ print \$2 }'";$oid_dprefixes="snmpwalk -c public -v2c $destino 1.3.6.1.4.1.9.9.187.1.2.4.1.6 | awk -F \"Gauge32: \" '{ print \$2 }'";$oid_uptime="snmpwalk -c public -v2c $destino 1.3.6.1.2.1.15.3.1.16 | awk -F \"Gauge32: \" '{ print \$2 }'";$getname=`snmpwalk -c public -v2c $destino SNMPv2-MIB::sysName.0 | awk -F \"STRING: \" '{ print \$2 }'`;
> 
> $getname=~s/\n+//;
> @lista=`$oid_as`;print ".";@listb=`$oid_peer`;print ".";@listc=`$oid_state`;print ".";@listd=`$oid_msgrec`;print ".";@liste=`$oid_msgsen`;print ".";@listf=`$oid_prefixes`;print ".";@listg=`$oid_dprefixes`;print ".";@listh=`$oid_uptime`;print ".";
> $port=0;print "\e[H\e[J";print "\e[H";
> 
> 	print color 'bold blue';	print "Dispositivo: $getname \nEndereco IP: $destino \r\n\n";	print color 'bold blue on_black';
> 	printf("%-19s %-15s %-15s %-10s %-10s %-10s %-10s %-18s\n","Peer" ,"ASN", "Status","Msg Rec", "Msg Send", "Prefixes", "Denied", "Uptime");	print color 'reset';while(<@listb>){	$alias=substr($lista[$port],0,20);	$descr=substr($listb[$port],0,20);
> 	if(length($alias) > 2 && length($descr) > 2 && $alias eq $descr ){		$talias=$alias;	}elsif(length($alias) > 2 && length($descr) > 2 && $alias ne $descr){		if(length($alias) > length($descr)){			$talias=$descr;		}else{			$talias=$alias;		}	}elsif(length($alias)>2){		$talias=$alias;			}elsif(length($descr) > 2){		$talias=$descr;
> 	}
> 	$talias=~s/\n+//;
> 	$opers=$listc[$port];	$msgrec=$listd[$port];	$msgsen=$liste[$port];	$prefixes=$listf[$port];	$dprefixes=$listg[$port];	$uptime=$listh[$port];	$alias=~s/\n//;	$descr=~s/\n//;	$opers=~s/\n//;	$msgrec=~s/\n//;	$msgsen=~s/\n//;	$prefixes=~s/\n//;	$dprefixes=~s/\n//;	$uptime=~s/\n//;	$ouptime=&sec2human($uptime);
> 	$pcolor="blue";	if($opers eq "1"){$pstate="Idle";$pcolor="bold white on_red";}elsif($opers eq "2"){$pstate="Connect";}elsif($opers eq "3"){$pstate="Active";$pcolor="bold red on_white";}elsif($opers eq "4"){$pstate="OpenSent";}elsif($opers eq "5"){$pstate="OpenConfirm";}elsif($opers eq "6"){$pstate="Established";$pcolor="green";}		print color $pcolor;		printf("%-19s %-15s %-15s %-10s %-10s %-10s %-10s %-18s\n",$descr ,$talias, $pstate, $msgrec,$msgsen,$prefixes,$dprefixes,$ouptime);		print  color 'reset';	$port++;}}
>  		 	   		  
> --
> gter list    https://eng.registro.br/mailman/listinfo/gter
 		 	   		  


More information about the gter mailing list