I have the following program which worked fine when it queried 1 router for info and outputed the query to a table. Now I need to query 2 routers and output the results side by side. I think I need to somehow have one foreach loop query both routers and use one write statement. Here is my code:
# This program performs an SNMPWALK command for the Cisco BGP MIB and prints the results.
# Set up variables and import modules
use strict;
use Socket;
my $cs = "jf7RKD76";
my $OID = ".1.3.6.1.2.1.15.3.1.2";
my $EAST = "172.16.255.187";
my $WEST = "172.16.255.251";
chomp $EAST;
chomp $WEST;
my $ipeast;
my $ipwest;
my $stateast;
my $statwest;
my $reseast;
my $reswest;
my $hosteast;
my $hostwest;
my $answest;
my $anseast;
# Perform snmpwalk on inputed variable from OpenView and resolve ipaddresses
my @reseast = `snmpwalk -c $cs $EAST $OID`;
foreach (@reseast) {
($ipeast,$stateast) = /(\d+\.\d+\.\d+\.\d+).*?\s+(\w+)\Z/;
$reseast = inet_aton("$ipeast"
$hosteast = gethostbyaddr($reseast, AF_INET);
$anseast=$hosteast || $ipeast;
write();
}
my @reswest = `snmpwalk -c $cs $WEST $OID`;
foreach (@reswest) {
($ipwest,$statwest) = /(\d+\.\d+\.\d+\.\d+).*?\s+(\w+)\Z/;
$reswest = inet_aton("$ipwest"
$hostwest = gethostbyaddr($reswest, AF_INET);
$answest=$hostwest || $ipwest;
write();
}
# Output format for write command
format STDOUT_TOP =
------------ -------------
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<
$anseast $stateast $answest $statwest
.
The output looks like this now:
tsg-ws28.osu.qwest.net idle
qwest7-denver-rtr1 established
63.236.121.60 idle
uac08-rtr01-qwest4.aon.storabili established
uac13-rtr02-qwest9.aon.storabili established
uac01-rtr02-inslogic1.aon.storab established
uac02-rtr01-covisint.aon.storabi established
198.94.30.43 idle
199.93.193.59 active
uac16-rtr01-ctc01.aon.storabilit established
uac06-rtr01-qwest2.aon.storabili established
uac09-rtr01-qwest5.aon.storabili idle
uac09-rtr02-qwest5.aon.storabili established
208.45.147.60 established
rtr01.ams02.storability.net established
rtr02.ams01.storability.net established
rtr02.mcd01.storability.net established
216.34.168.201 idle
uac15-rtr02-mydoc.aon.storabilit established
217.71.130.45 idle
217.71.130.45 idle uac11-rtr02-qwest7.aon.storabili established
217.71.130.45 idle hoc-ws4.iad2.qwest.net established
217.71.130.45 idle uac13-rtr01-qwest9.aon.storabili established
217.71.130.45 idle uac01-rtr01-inslogic1.aon.storab established
217.71.130.45 idle uac02-rtr02-covisint.aon.storabi established
217.71.130.45 idle 199.93.193.58 active
217.71.130.45 idle uac16-rtr02-ctc01.aon.storabilit established
217.71.130.45 idle uac06-rtr02-qwest2.aon.storabili established
217.71.130.45 idle uac09-rtr01-qwest5.aon.storabili established
217.71.130.45 idle uac10-rtr02-qwest6.aon.storabili established
217.71.130.45 idle rtr02.ams02.storability.net established
217.71.130.45 idle rtr01.ams01.storability.net established
217.71.130.45 idle uac05-rtr01-workscape.aon.storab established
217.71.130.45 idle rtr01.mcd01.storability.net established
217.71.130.45 idle uac15-rtr01-mydoc.aon.storabilit established
I want the results side by side.
Any ideas?
# This program performs an SNMPWALK command for the Cisco BGP MIB and prints the results.
# Set up variables and import modules
use strict;
use Socket;
my $cs = "jf7RKD76";
my $OID = ".1.3.6.1.2.1.15.3.1.2";
my $EAST = "172.16.255.187";
my $WEST = "172.16.255.251";
chomp $EAST;
chomp $WEST;
my $ipeast;
my $ipwest;
my $stateast;
my $statwest;
my $reseast;
my $reswest;
my $hosteast;
my $hostwest;
my $answest;
my $anseast;
# Perform snmpwalk on inputed variable from OpenView and resolve ipaddresses
my @reseast = `snmpwalk -c $cs $EAST $OID`;
foreach (@reseast) {
($ipeast,$stateast) = /(\d+\.\d+\.\d+\.\d+).*?\s+(\w+)\Z/;
$reseast = inet_aton("$ipeast"
$hosteast = gethostbyaddr($reseast, AF_INET);
$anseast=$hosteast || $ipeast;
write();
}
my @reswest = `snmpwalk -c $cs $WEST $OID`;
foreach (@reswest) {
($ipwest,$statwest) = /(\d+\.\d+\.\d+\.\d+).*?\s+(\w+)\Z/;
$reswest = inet_aton("$ipwest"
$hostwest = gethostbyaddr($reswest, AF_INET);
$answest=$hostwest || $ipwest;
write();
}
# Output format for write command
format STDOUT_TOP =
------------ -------------
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<
$anseast $stateast $answest $statwest
.
The output looks like this now:
tsg-ws28.osu.qwest.net idle
qwest7-denver-rtr1 established
63.236.121.60 idle
uac08-rtr01-qwest4.aon.storabili established
uac13-rtr02-qwest9.aon.storabili established
uac01-rtr02-inslogic1.aon.storab established
uac02-rtr01-covisint.aon.storabi established
198.94.30.43 idle
199.93.193.59 active
uac16-rtr01-ctc01.aon.storabilit established
uac06-rtr01-qwest2.aon.storabili established
uac09-rtr01-qwest5.aon.storabili idle
uac09-rtr02-qwest5.aon.storabili established
208.45.147.60 established
rtr01.ams02.storability.net established
rtr02.ams01.storability.net established
rtr02.mcd01.storability.net established
216.34.168.201 idle
uac15-rtr02-mydoc.aon.storabilit established
217.71.130.45 idle
217.71.130.45 idle uac11-rtr02-qwest7.aon.storabili established
217.71.130.45 idle hoc-ws4.iad2.qwest.net established
217.71.130.45 idle uac13-rtr01-qwest9.aon.storabili established
217.71.130.45 idle uac01-rtr01-inslogic1.aon.storab established
217.71.130.45 idle uac02-rtr02-covisint.aon.storabi established
217.71.130.45 idle 199.93.193.58 active
217.71.130.45 idle uac16-rtr02-ctc01.aon.storabilit established
217.71.130.45 idle uac06-rtr02-qwest2.aon.storabili established
217.71.130.45 idle uac09-rtr01-qwest5.aon.storabili established
217.71.130.45 idle uac10-rtr02-qwest6.aon.storabili established
217.71.130.45 idle rtr02.ams02.storability.net established
217.71.130.45 idle rtr01.ams01.storability.net established
217.71.130.45 idle uac05-rtr01-workscape.aon.storab established
217.71.130.45 idle rtr01.mcd01.storability.net established
217.71.130.45 idle uac15-rtr01-mydoc.aon.storabilit established
I want the results side by side.
Any ideas?