onu_cdata.pm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use Modern::Perl;
  2. use utf8;
  3. use telnet;
  4. use Exporter;
  5. our @ISA= qw( Exporter );
  6. our @EXPORT = qw( onu_cdata );
  7. async onu_cdata => sub
  8. {
  9. my $ip = shift;
  10. my $login = shift;
  11. my $password = shift;
  12. my $tree = shift;
  13. my $t = new telnet($ip);
  14. # $t->debug(1);
  15. await $t->connect;
  16. await $t->reply(qr/User name:/, $login);
  17. await $t->reply(qr/User password:/, $password);
  18. $t->print("enable");
  19. await $t->waitfor("#");
  20. $t->prompt(qr/#\s?$/);
  21. await $t->cmd("config");
  22. await $t->cmd("vty output show-all");
  23. $t->print("interface epon 0/0");
  24. $t->prompt(qr/#\s?$/);
  25. my @lines = await $t->cmd("show ont info $tree all");
  26. my $onu_count_line = @lines[@lines-3];
  27. $onu_count_line =~ m|Total: (\d+), online (\d+)|;
  28. my $total_onu_cnt = $1;
  29. my $online_onu_cnt = $2;
  30. my $offline_onu_cnt = $total_onu_cnt - $online_onu_cnt;
  31. $t->close;
  32. if ($lines[2] =~ /Error/) {
  33. $total_onu_cnt = 0;
  34. $online_onu_cnt = 0;
  35. $offline_onu_cnt = 0;
  36. }
  37. my $res = "Всего: $total_onu_cnt
  38. Количество активных ONU: $online_onu_cnt
  39. Количество неактивных ONU: $offline_onu_cnt
  40. \n";
  41. return $res;
  42. };
  43. 1;