E
erik
I am ultimately trying to make CGI where we can Quality Assure Cisco
routers. My script does log into the router, but I don't think it is
storing in my array. I try to print the array and I get nothing. It
hangs within the check_logging_settings subscript.
(I have the ARGV scalars because I am testing it via command line
rather than the browser. )
But like I said the problem is definitely in teh check_logging_settings
sub script. Any advice would be appreciated.
#!/usr/bin/perl -w
#################################################################
# Global Variables #
#################################################################
use Expect;
use CGI(":standard");
use Term::ANSIColor;
#$device = param("device");
#$username = param("username");
#$password = param("password");
#$enable = "enable";
#$enable_password = param(enable_password");
$device = $ARGV[0];
$username = $ARGV[1] ;
$password = $ARGV[2];
$enable = $ARGV[3];
$enable_password = $ARGV[4];
$LoggingMsg = "Do you have logging back to the NTP server";
#Error Report Array
my @failed_tests;
#################################################################
# Create Session with router #
#################################################################
sub spawn_session
{
#open session with router
$command = Expect->spawn("telnet $device");
#Wait for password prompt or send error.
$command->expect($timeout, -re => "Username:") or do
{
print "\nFailed to get username prompt\n";
exit 2;
};
#Send Tacacs Username to router, exit if Username is incorrect
print $command "$username\r";
$command->expect($timeout, -re => "Password:") or do
{
print "\nFailed to get password prompt\n";
exit 4;
};
#Send password to router, exit if password is incorrect
print $command "$password\r";
$command->expect($timeout, -re => ">") or do
{
print "\nDid not get a \> in prompt\n";
exit 5;
};
#Send enable pass to router, exit if password is incorrect
print $command "$enable\r";
$command->expect($timeout, -re => "assword") or do
{
print "\nDid not get a \> in prompt\n";
exit 5;
};
#Send enable pass to router, exit if password is incorrect
print $command "$enable_password\r";
} #end sub
#################################################################
# Ensures that only one interface has manage ssh set #
#################################################################
sub check_logging_settings
{
my $no_logging = "You are missing logging 199.11.x.xx";
$command->clear_accum();
print $command "show config \| inc logging 199.11.x.xx\r";
unless ($command->expect($timeout, -re, '->')) {
return "Never got ssh prompt".$command->exp_error()."\n";
}
my $read = $command->exp_before();
my @read = split ('\n', $read);
my $x = 0;
my $count = 0;
for ($x=0; $x<$#read; $x++)
{
if ($read[$x] =~ /^logging 199.11.1.22$/)
{ $count += 1; }
}
if ($count < 1)
{
push (@failed_tests, $no_logging);
$action = "FAIL";
}
else
{
$action = "OK";
}#end if
print "$action We got here";
}
#################################################################
# Exits the Telnet Session #
#################################################################
sub exit_session
{
print $command "exit\r";
}#end sub
#################################################################
# Prints the failed test error descriptions #
#################################################################
sub print_error_report
{
print <<html1
Conent-Type: text/html\n\n
<html><head><title>QA REPORT</title></head>
<body bgcolor="#ffffff">
<p>
<h2>QA Results</h2>
<ul>
<body>
<b>$LoggingMsg</b><br>
</body>
print <<EndFooter;
</ul>
<p>
</body>
</html>
html1
}
#################################################################
# Main Program Module #
#################################################################
spawn_session();
check_logging_settings();
exit_session();
print_error_report();
routers. My script does log into the router, but I don't think it is
storing in my array. I try to print the array and I get nothing. It
hangs within the check_logging_settings subscript.
(I have the ARGV scalars because I am testing it via command line
rather than the browser. )
But like I said the problem is definitely in teh check_logging_settings
sub script. Any advice would be appreciated.
#!/usr/bin/perl -w
#################################################################
# Global Variables #
#################################################################
use Expect;
use CGI(":standard");
use Term::ANSIColor;
#$device = param("device");
#$username = param("username");
#$password = param("password");
#$enable = "enable";
#$enable_password = param(enable_password");
$device = $ARGV[0];
$username = $ARGV[1] ;
$password = $ARGV[2];
$enable = $ARGV[3];
$enable_password = $ARGV[4];
$LoggingMsg = "Do you have logging back to the NTP server";
#Error Report Array
my @failed_tests;
#################################################################
# Create Session with router #
#################################################################
sub spawn_session
{
#open session with router
$command = Expect->spawn("telnet $device");
#Wait for password prompt or send error.
$command->expect($timeout, -re => "Username:") or do
{
print "\nFailed to get username prompt\n";
exit 2;
};
#Send Tacacs Username to router, exit if Username is incorrect
print $command "$username\r";
$command->expect($timeout, -re => "Password:") or do
{
print "\nFailed to get password prompt\n";
exit 4;
};
#Send password to router, exit if password is incorrect
print $command "$password\r";
$command->expect($timeout, -re => ">") or do
{
print "\nDid not get a \> in prompt\n";
exit 5;
};
#Send enable pass to router, exit if password is incorrect
print $command "$enable\r";
$command->expect($timeout, -re => "assword") or do
{
print "\nDid not get a \> in prompt\n";
exit 5;
};
#Send enable pass to router, exit if password is incorrect
print $command "$enable_password\r";
} #end sub
#################################################################
# Ensures that only one interface has manage ssh set #
#################################################################
sub check_logging_settings
{
my $no_logging = "You are missing logging 199.11.x.xx";
$command->clear_accum();
print $command "show config \| inc logging 199.11.x.xx\r";
unless ($command->expect($timeout, -re, '->')) {
return "Never got ssh prompt".$command->exp_error()."\n";
}
my $read = $command->exp_before();
my @read = split ('\n', $read);
my $x = 0;
my $count = 0;
for ($x=0; $x<$#read; $x++)
{
if ($read[$x] =~ /^logging 199.11.1.22$/)
{ $count += 1; }
}
if ($count < 1)
{
push (@failed_tests, $no_logging);
$action = "FAIL";
}
else
{
$action = "OK";
}#end if
print "$action We got here";
}
#################################################################
# Exits the Telnet Session #
#################################################################
sub exit_session
{
print $command "exit\r";
}#end sub
#################################################################
# Prints the failed test error descriptions #
#################################################################
sub print_error_report
{
print <<html1
Conent-Type: text/html\n\n
<html><head><title>QA REPORT</title></head>
<body bgcolor="#ffffff">
<p>
<h2>QA Results</h2>
<ul>
<body>
<b>$LoggingMsg</b><br>
</body>
print <<EndFooter;
</ul>
<p>
</body>
</html>
html1
}
#################################################################
# Main Program Module #
#################################################################
spawn_session();
check_logging_settings();
exit_session();
print_error_report();