| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- use Modern::Perl;
- use utf8;
- use telnet;
- use Exporter;
- our @ISA= qw( Exporter );
- our @EXPORT = qw( onu_bdcom );
- async onu_bdcom => sub
- {
- my $ip = shift;
- my $login = shift;
- my $password = shift;
- my $tree = shift;
- ############################
- my $t = new telnet($ip);
- # $t->debug(1);
- await $t->connect;
- await $t->reply(qr/Username:/, $login);
- await $t->reply(qr/Password:/, $password);
- my @greeting = await $t->waitfor(qr/>/);
- my $version = "C";
- for (@greeting)
- {
- $version = $1 if /Welcome to BDCOM P3310(\w)/;
- }
- $t->print("enable");
- my @next = await $t->waitfor(qr/#|password:/);
- if (grep {$_ =~ /password:/} @next)
- {
- $t->print($password);
- await $t->waitfor(qr/#/);
- }
- $t->prompt(qr/#/);
- await $t->cmd("terminal length 0");
- await $t->cmd("terminal width 200");
- #######################
- my @inactive_onu = await $t->cmd("show epon inactive-onu interface ePON 0/$tree");
- $inactive_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
- my $inactive_count = $1 || "?";
- if (@inactive_onu <= 1) {
- $inactive_count = 0;
- }
- $t->prompt(qr/#/);
- my @active_onu = await $t->cmd("show epon active-onu interface ePON 0/$tree");
- $active_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
- my $active_count = $1 || "?";
- if (@active_onu <= 1) {
- $active_count = 0;
- }
- my $total_count = $active_count + $inactive_count;
- $t->close;
- my $res = "Всего: $total_count
- Количество активных ONU: $active_count
- Количество неактивных ONU: $inactive_count
- \n";
- return $res;
- };
- 1;
|