use Modern::Perl; use utf8; use telnet; async onu_cdata => 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/User name:/, $login); await $t->reply(qr/User password:/, $password); $t->print("enable"); await $t->waitfor("#"); $t->prompt(qr/#\s?$/); await $t->cmd("config"); await $t->cmd("vty output show-all"); $t->print("interface epon 0/0"); $t->prompt(qr/#\s?$/); my @lines = await $t->cmd("show ont info $tree all"); #say Dumper @lines; my $onu_count_line = @lines[@lines-3]; $onu_count_line =~ m|Total: (\d+), online (\d+)|; my $total_onu_cnt = $1; my $online_onu_cnt = $2; my $offline_onu_cnt = $total_onu_cnt - $online_onu_cnt; $t->close; if (@lines[2] =~ /Error/) { $total_onu_cnt = 0; $online_onu_cnt = 0; $offline_onu_cnt = 0; } my $res = "Всего: $total_onu_cnt Количество активных ONU: $online_onu_cnt Количество неактивных ONU: $offline_onu_cnt \n"; return $res; }; 1;