First of all, a good place to obtain MIBs and query them is SNMP-Link: http://www.snmplink.org/OnLineMIB/.
To use Expect with Perl, a code snippet from Emulab snmpit tool:
To use Expect with Perl, a code snippet from Emulab snmpit tool:
my $spawn_cmd = "telnet $self->{NAME}";
my $exp = new Expect();
if (!$exp) {
# upper layer will check this
return undef;
}
$exp->raw_pty(0);
$exp->log_stdout(0);
$exp->spawn($spawn_cmd)
or die "Cannot spawn $spawn_cmd: $!\n";
# have to send a newline to make login prompt come out
$exp->send("\n");
$exp->expect($CLI_TIMEOUT,
["login:", sub {
my $e = shift;
$e->send("admin\n");
exp_continue;}],
["password:", sub {
my $e = shift;
$e->send($self->{PASSWORD}."\n");
exp_continue;}],
[timeout => sub {
my $e = shift;
$e->hard_close();
die "timeout when connect to switch!\n";}],
[qr/$self->{CLI_PROMPT}/, sub {;}]);
# Disable paging in CLI output so that no "next page"
# will bother us.
$exp->send("disable clipaging\n");
$exp->expect($CLI_TIMEOUT,
[qr/$CLI_ERROR_PATTERN/,
sub {
my $e = shift;
die "Incorrect command and result: ".$e->match().
$e->after()."\n";}],
[qr/$CLI_PROMPT/ => sub {;}],
[timeout => sub {
my $e = shift;
$e->hard_close();
die "timeout when connect to switch!\n";}]);
No comments:
Post a Comment