onu_bdcom.pm 1.5 KB

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