onu_cdata.pm 1.2 KB

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