my $vlanId="1147";
my $contador=0;
my $pos=0;
######################################################################################
## Se Consultan las Vlan en los equipos del anillo para encontrar el principal
######################################################################################
$query10G="select n.NodeID, n.IP_Address, n.Caption, n.Vendor from Nodes n where n.Propiedad='10G'";
$r_query10G = $dbh01->selectall_arrayref("$query10G");
foreach $row_r_query10G (@$r_query10G) {
if($r_query10G->[$contador]->[0]==1675){
$pos=$contador;
#print "my pos: $pos\t$r_query10G->[$contador]->[0]\n\n";
my $ref_to_element = \$r_query10G[$pos];
push (@$r_query10G, splice(@$r_query10G, $pos, 1));
}
$contador++;
}
foreach $row_r_query10G (@$r_query10G) {
($NodeId,$IpAddress,$Caption,$Manufacturer) = @$row_r_query10G;
#print "Contador= $contador\n";
#print Dumper(@$r_query10G)."\n\n";
#exit 0;
my @port2Dev="";
my @toIpDev="";
my @portServDev="";
my $SID="";
my @portsDev=();
#print "arranque\n($NodeId,$IpAddress,$Caption,$Manufacturer)\n\n";
#####################################################################################
# Si se trata de un equipo Juniper, se procede de cierta forma para la eliminacion
#####################################################################################
if ($Manufacturer=~/Juniper/isg) {
@conn1 = conectar_telnet($IpAddress,$userbackupsdefault,$passbackupsdefault);
print "Conectado a $IpAddress\n";
if ($conn1[0]) {
$mensajeerror.="Equipo=$Caption, IP=$IpAddress, Descripcion=$conn1[0]\n<br>";
$conteoerrores++;
} else {
my $line="";
if($NodeId!=1675){
@out=$conn1[1]->cmd(String => "show vlans vlan$vlanId\n", Timeout => 10);
foreach $line (@out) {
#print "$line\n";
if ($line=~/\s+(.+)\.\d+\*\,\s?(.+)\.\d+\*\,\s?(.+)\.\d+\*/is){
push(@portsDev, $1);
print "$line\n--> $1, $2, $3\n\n";
}
}
}else{
@out=$conn1[1]->cmd(String => "show ethernet-switching table vlan $vlanId\n", Timeout => 10);
foreach $line (@out) {
#print "$line\n";
if ($line=~/Learn.+0\s(.+)\.0\s?/i){
push(@portsDev, $1);
print "$line\n--> $1\n\n";
}
}
}
$line="";
if($#portsDev > 0){
@portsDev = grep { /\S/ } @portsDev;
print "entro al if ya que el array es de tamano \@ports=$#portsDev\n\n";
foreach $port (@portsDev){
print "puerto: $port\n";
@out=$conn1[1]->cmd(String => "show interfaces descriptions $port\n", Timeout => 10);
foreach $line (@out){
if($line=~/.*\#\-.*\[(.+?)\].+?\-(?:\s+)?((?:\d+\.){3}\d+)/is){
push(@port2Dev,$1);
push(@toIpDev,$2);
print "$line\n\n(@port2Dev, @toIpDev)\n\n";
#print Dumper(@port2Dev, @toIpDev);
}
}
}
}
@out=$conn1[1]->cmd("exit\n");
}
cerrar_telnet($conn1[1]);
if($#port2Dev > 0 && $#toIpDev > 0){
@port2Dev = grep { /\S/ } @port2Dev;
@toIpDev = grep { /\S/ } @toIpDev;
print "Elements (@port2Dev ) - (@toIpDev)\n\n\n";
&getIpInterface(\@port2Dev,\@toIpDev,10);
}
}
#Validar si el Servicio $SID es Igual al que se reporta en el router.
}
sub getIpInterface {
print "Estoy en getIpInterface\n\n";
($port2Dev,$toIpDev,$algo)=@_;
@secPortDev="";
@secToIpDev="";
print "entre a la funcion: (@$port2Dev, @$toIpDev) $algo\n\n";
print "tamanio: ($#$port2Dev, $#$toIpDev)\n\n";
# exit 0;
if($#$port2Dev > 0 && $#$toIpDev > 0){
$contador=0;
print "existen: port2Dev (@$port2Dev) y toIpDev (@$toIpDev)\n\n";
print Dumper(@$port2Dev)."\n"; Dumper(@$toIpDev)."\n";
foreach $toIp (@$toIpDev){
$queryAccess="select n.NodeID, n.IP_Address, n.Caption, n.Vendor from Nodes n WITH (NOLOCK) where n.Ip_Address = '$toIp'";
print "QueryAccess: $queryAccess\n";
$r_queryAccess = $dbh01->selectall_arrayref("$queryAccess");
foreach $row_r_queryAccess (@$r_queryAccess) {
($NodeId,$IpAddress,$Caption,$Manufacturer) = @$row_r_queryAccess;
#print "arranque\n($NodeId,$IpAddress,$Caption,$Manufacturer)\n\n";
#####################################################################################
# Si se trata de un equipo Juniper, se procede de cierta forma para la eliminacion
#####################################################################################
if ($Manufacturer=~/Juniper/is) {
@conn1 = conectar_telnet($toIp,$userbackupsdefault,$passbackupsdefault);
if ($conn1[0]) {
$mensajeerror.="IP=$toIp, Descripcion=$conn1[0]\n<br>";
$conteoerrores++;
} else {
@out=$conn1[1]->cmd(String => "show interfaces descriptions $$port2Dev[$contador]\n", Timeout => 10);
foreach my $line (@out){
print "Juniper: $line\n";
# if($line=~/.*\#\-.*\[(.+?)\].+?\-(?:\s+)?((?:\d+\.){3}\d+)/is){
# push(@port2Dev,$1);
# push(@toIpDev,$2);
# print "Added: (@port2Dev, @toIpDev)\n\n";
# }else{
# #Indicar Logica para ver descripcion de interfaz de Servicio
# }
}
@out=$conn1[1]->cmd("exit\n")
}
cerrar_telnet($conn1[1]);
}elsif($Manufacturer=~/Cisco/is){
@conn1 = conectar_telnet_cisco($toIp,$userbackupsdefault,$passbackupsdefault);
if ($conn1[0]) {
$mensajeerror.="IP=$toIp, Descripcion=$conn1[0]\n<br>";
$conteoerrores++;
} else {
@out=$conn1[1]->cmd(String => "terminal length 0");
@out=$conn1[1]->cmd(String => "show vlan id $vlanId\n", Timeout => 10);
foreach my $line (@out){
if($line=~/.+active\s+(.+?)\,\s?(.+)/i){
push(@portServDev,$1);
push(@portServDev,$2);
print "Cisco: $line\nPuerto servicio: $1,$2\n\n";
}
}
if($#portServDev>0){
@portServDev = grep { /\S/ } @portServDev;
foreach my $portServ (@portServDev){
@out=$conn1[1]->cmd(String => "show interfaces $portServ | i Description\n", Timeout => 10);
foreach my $line (@out){
if ($line=~/(?:\s+)?description\:?\s?(\d+)\s\#/i){
$SID=$1;
print "$line\n\n-*-*-*-*-*-\tServicio: $SID\n";
}elsif($line=~/.*\#\-.*\[(.+?)\].+?\-(?:\s+)?((?:\d+\.){3}\d+)/is){
push(@secPortDev,$1);
push(@secToIpDev,$2);
print "2. $line\n\n(@secPortDev), (@secToIpDev)\n\n";
}
}
}
}
@out=$conn1[1]->cmd("exit\n");
}
cerrar_telnet_cisco($conn1[1]);
if($#secPortDev > 0 && $#secToIpDev > 0){
@secPortDev = grep { /\S/ } @secPortDev;
@secToIpDev = grep { /\S/ } @secToIpDev;
print "New elements (@secPortDev) - (@secToIpDev)\n\n\n";
&getIpInterface(\@secPortDev,\@secToIpDev, 2222);
}
}
}
$contador++;
}
}
}