onu_bdcom.pm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. use Modern::Perl;
  2. use utf8;
  3. use telnet;
  4. use Exporter;
  5. our @ISA= qw( Exporter );
  6. our @EXPORT = qw( onu_bdcom );
  7. async onu_bdcom => sub
  8. {
  9. my $ip = shift;
  10. my $login = shift;
  11. my $password = shift;
  12. my $tree = shift;
  13. ############################
  14. my $t = new telnet($ip);
  15. # $t->debug(1);
  16. await $t->connect;
  17. await $t->reply(qr/Username:/, $login);
  18. await $t->reply(qr/Password:/, $password);
  19. my @greeting = await $t->waitfor(qr/>/);
  20. my $version = "C";
  21. for (@greeting)
  22. {
  23. $version = $1 if /Welcome to BDCOM P3310(\w)/;
  24. }
  25. $t->print("enable");
  26. my @next = await $t->waitfor(qr/#|password:/);
  27. if (grep {$_ =~ /password:/} @next)
  28. {
  29. $t->print($password);
  30. await $t->waitfor(qr/#/);
  31. }
  32. $t->prompt(qr/#/);
  33. await $t->cmd("terminal length 0");
  34. await $t->cmd("terminal width 200");
  35. #######################
  36. my @inactive_onu = await $t->cmd("show epon inactive-onu interface ePON 0/$tree");
  37. $inactive_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
  38. my $inactive_count = $1 || "?";
  39. if (@inactive_onu <= 1) {
  40. $inactive_count = 0;
  41. }
  42. $t->prompt(qr/#/);
  43. my @active_onu = await $t->cmd("show epon active-onu interface ePON 0/$tree");
  44. $active_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
  45. my $active_count = $1 || "?";
  46. if (@active_onu <= 1) {
  47. $active_count = 0;
  48. }
  49. my $total_count = $active_count + $inactive_count;
  50. $t->close;
  51. my $res = "Всего: $total_count
  52. Количество активных ONU: $active_count
  53. Количество неактивных ONU: $inactive_count
  54. \n";
  55. return $res;
  56. };
  57. 1;