alakiza 2 жил өмнө
parent
commit
fc6b795bd4

+ 1 - 1
modules/bdcom.pm

@@ -207,7 +207,7 @@ async bdcom_purge => sub
 
     if ( $onu_info{'active_cnt'} != $onu_info{'total_cnt'} ) {
         $res = $res . "Общее количество ONU и количество активных ONU не совпадает.
-Лучше обратиться к Вашему системноу администратору\n";
+Лучше обратиться к Вашему системному администратору\n";
     }
 
     $res = $res . "Удалённые ONU:\n" . join("\n", @deleted_onu) if @deleted_onu > 0;

+ 4 - 4
modules/cdata.pm

@@ -151,15 +151,15 @@ async cdata_purge => sub
         return "Нечего чистить.";
     }
 
-    say Dumper \%onu_info;
+    #say Dumper \%onu_info;
 
     await $t->cmd("interface epon 0/0");
 
     foreach my $i ( @{$onu_info{'inactive'}} ) {
-        say Dumper @$i[0];
+        #say Dumper @$i[0];
         my $onu_num = @$i[0];
         my @tmp = await $t->cmd("ont delete $tree $onu_num");
-        say Dumper @tmp;
+        #say Dumper @tmp;
     }
 
     await $t->cmd("exit");
@@ -178,7 +178,7 @@ async cdata_purge => sub
 
     if ( $onu_info{'active_cnt'} != $onu_info{'total_cnt'} ) {
         $res = $res . "Общее количество ONU и количество активных ONU не совпадает.
-Лучше обратиться к Вашему системноу администратору\n";
+Лучше обратиться к Вашему системному администратору\n";
     }
 
     $res = $res . "Удалённые ONU:\n" . join("\n", @deleted_onu) if @deleted_onu > 0;

+ 4 - 7
modules/commands.pm

@@ -3,12 +3,6 @@ use utf8;
 
 use Mojo::AsyncAwait;
 use Data::Dumper;
-#use purge_cdata qw(purge_cdata);
-#use purge_bdcom qw(purge_bdcom);
-#use inspect_bdcom qw(inspect_bdcom);
-#use inspect_cdata qw(inspect_cdata);
-#use onu_bdcom qw(onu_bdcom);
-#use onu_cdata qw(onu_cdata);
 
 use bdcom;
 use cdata;
@@ -24,9 +18,12 @@ sub command_help
   my $chatid = shift;
   my $rest = shift;
   
+
+# TEMP
+# <b>/purge-all-trees</b> <i>ip-адрес-устройства</i> - Очистить все деревья PON
+#
   notify($chatid, 
 "<b>/purge </b> <i>ip-адрес-устройства номер-дерева</i> - Очистить дерево PON
-<b>/purge-all-trees</b> <i>ip-адрес-устройства</i> - Очистить все деревья PON
 <b>/inspect</b> <i>ip-адрес-устройства номер-дерева</i> - Информация об ONU на дереве
 <b>/onu</b> <i>ip-адрес-устройства номер-дерева</i> - Краткая информация ONU на дереве", $rest);
 }

+ 0 - 108
modules/inspect_bdcom.pm

@@ -1,108 +0,0 @@
-#package inspect_bdcom;
-
-use Modern::Perl;
-use utf8;
-
-use telnet;
-
-use Exporter;
-our @ISA= qw( Exporter );
-our @EXPORT = qw( inspect_bdcom );
-
-sub inspect_bdcom::_extract_onu_num {
-    my $onu_name = shift;
-
-    $onu_name =~ m|EPON0/\d+:(\d+)|;
-
-    return $1;
-};
-
-sub inspect_bdcom::_extract_onu_info {
-    my @lines = @_;
-
-    return map([substr($_, 0, 11), split(' ', substr($_, 11, -1))], @lines[3..@lines-3]);
-};
-
-async inspect_bdcom => 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/Username:/, $login);
-    await $t->reply(qr/Password:/, $password);
-
-    my @greeting = await $t->waitfor(qr/>/);
-    my $version = "C";
-
-    for (@greeting)
-    {
-        $version = $1 if /Welcome to BDCOM P3310(\w)/;
-    }
-
-    $t->print("enable");
-
-    my @next = await $t->waitfor(qr/#|password:/);
-
-    if (grep {$_ =~ /password:/} @next)
-    {
-        $t->print($password);
-        await $t->waitfor(qr/#/);
-    }
-
-    $t->prompt(qr/#/);
-
-    await $t->cmd("terminal length 0");
-    await $t->cmd("terminal width 200");
-
-  #######################
-
-    my @inactive_onu = await $t->cmd("show epon inactive-onu interface ePON 0/$tree");
-    $inactive_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    my $inactive_count = $1 || "?";
-    if (@inactive_onu <= 1) {
-        $inactive_count = 0;
-    }
-
-    my @active_onu = await $t->cmd("show epon active-onu interface ePON 0/$tree");
-    $active_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    my $active_count = $1 || "?";
-    if (@active_onu <= 1) {
-        $active_count = 0;
-    }
-
-    my $total_count = $active_count + $inactive_count;
-
-    $t->close;
-
-    my $res = "Всего: $total_count
-Количество активных ONU: $active_count
-Количество неактивных ONU: $inactive_count
-\n";
-
-    my @in_onu_info = inspect_bdcom::_extract_onu_info(@inactive_onu);
-    my @compact_in_onu_info = map( [inspect_bdcom::_extract_onu_num(@$_[0]), @$_[1]], @in_onu_info );
-    @compact_in_onu_info = map( join(" ", @$_), @compact_in_onu_info);
-
-    say Dumper @active_onu;
-    my @a_onu_info = inspect_bdcom::_extract_onu_info(@active_onu);
-    say "test2";
-    my @compact_a_onu_info = map( [inspect_bdcom::_extract_onu_num(@$_[0]), @$_[1]], @a_onu_info );
-    @compact_a_onu_info = map( join(" ", @$_), @compact_a_onu_info);
-
-    $res = $res . "Неактивные ONU:\n" . join("\n", @compact_in_onu_info) . "\n\n";
-
-    $res = $res . "Активные ONU:\n" . join("\n", @compact_a_onu_info);
-
-    return $res;
-};
-
-1;

+ 0 - 79
modules/inspect_cdata.pm

@@ -1,79 +0,0 @@
-use Modern::Perl;
-use utf8;
-
-use telnet;
-
-use Exporter;
-our @ISA= qw( Exporter );
-our @EXPORT = qw( inspect_cdata );
-
-sub inspect_cdata::_extract_onu_info {
-    my @lines = @_;
-
-    my @onu_info = @lines[6..@lines-5];
-
-    return map([ split(' ', $_) ], @onu_info );
-};
-
-async inspect_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");
-
-    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 @onu_info = inspect_cdata::_extract_onu_info(@lines);
-
-    my @online_onu = grep { @$_[5] =~ "online" }  @onu_info;
-    @online_onu = map join(' ', @$_[2,3]), @online_onu;
-
-    my @offline_onu = grep { @$_[5] =~ "offline|powerdown" }  @onu_info;
-    @offline_onu = map join(' ', @$_[2,3]), @offline_onu;
-
-    my $res = "Всего: $total_onu_cnt
-Количество активных ONU: $online_onu_cnt
-Количество неактивных ONU: $offline_onu_cnt
-\n";
-
-    $res = $res . "Неактивные ONU:\n" . join("\n", @offline_onu) . "\n\n" if $offline_onu_cnt;
-
-    $res = $res . "Активные ONU:\n" . join("\n", @online_onu) if $online_onu_cnt;
-
-    return $res;
-};
-
-1;

+ 0 - 81
modules/onu_bdcom.pm

@@ -1,81 +0,0 @@
-use Modern::Perl;
-use utf8;
-
-use telnet;
-
-use Exporter;
-our @ISA= qw( Exporter );
-our @EXPORT = qw( onu_bdcom );
-
-async onu_bdcom => 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/Username:/, $login);
-    await $t->reply(qr/Password:/, $password);
-
-    my @greeting = await $t->waitfor(qr/>/);
-    my $version = "C";
-
-    for (@greeting)
-    {
-        $version = $1 if /Welcome to BDCOM P3310(\w)/;
-    }
-
-    $t->print("enable");
-
-    my @next = await $t->waitfor(qr/#|password:/);
-
-    if (grep {$_ =~ /password:/} @next)
-    {
-        $t->print($password);
-        await $t->waitfor(qr/#/);
-    }
-
-    $t->prompt(qr/#/);
-
-    await $t->cmd("terminal length 0");
-    await $t->cmd("terminal width 200");
-
-  #######################
-
-    my @inactive_onu = await $t->cmd("show epon inactive-onu interface ePON 0/$tree");
-    $inactive_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    my $inactive_count = $1 || "?";
-    if (@inactive_onu <= 1) {
-        $inactive_count = 0;
-    }
-
-    $t->prompt(qr/#/);
-
-    my @active_onu = await $t->cmd("show epon active-onu interface ePON 0/$tree");
-    $active_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    my $active_count = $1 || "?";
-    if (@active_onu <= 1) {
-        $active_count = 0;
-    }
-
-
-    my $total_count = $active_count + $inactive_count;
-
-    $t->close;
-
-    my $res = "Всего: $total_count
-Количество активных ONU: $active_count
-Количество неактивных ONU: $inactive_count
-\n";
-
-    return $res;
-};
-
-1;

+ 0 - 59
modules/onu_cdata.pm

@@ -1,59 +0,0 @@
-use Modern::Perl;
-use utf8;
-
-use telnet;
-
-use Exporter;
-our @ISA= qw( Exporter );
-our @EXPORT = qw( onu_cdata );
-
-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");
-
-    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;

+ 0 - 134
modules/purge_bdcom.pm

@@ -1,134 +0,0 @@
-use Modern::Perl;
-use utf8;
-
-use telnet;
-
-use Exporter;
-our @ISA= qw( Exporter );
-our @EXPORT = qw( purge_bdcom );
-
-sub purge_bdcom::_extract_onu_num {
-    my $onu_name = shift;
-
-    $onu_name =~ m|EPON0/\d+:(\d+)|;
-
-    return $1;
-};
-
-sub purge_bdcom::_extract_onu_info {
-    my @lines = @_;
-
-    return map([substr($_, 0, 11), split(' ', substr($_, 11, -1))], @lines[3..@lines-3]);
-};
-
-async purge_bdcom => 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/Username:/, $login);
-    await $t->reply(qr/Password:/, $password);
-
-    my @greeting = await $t->waitfor(qr/>/);
-    my $version = "C";
-
-    for (@greeting)
-    {
-        $version = $1 if /Welcome to BDCOM P3310(\w)/;
-    }
-
-    $t->print("enable");
-
-    my @next = await $t->waitfor(qr/#|password:/);
-
-    if (grep {$_ =~ /password:/} @next)
-    {
-        $t->print($password);
-        await $t->waitfor(qr/#/);
-    }
-
-    $t->prompt(qr/#/);
-  
-    await $t->cmd("terminal length 0");
-    await $t->cmd("terminal width 200");
-  
-  #######################
-
-    my @inactive_onu = await $t->cmd("show epon inactive-onu interface ePON 0/$tree");
-    $inactive_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    my $inactive_count = $1 || "?";
-    if (@inactive_onu <= 1) {
-        $inactive_count = 0;
-    }
-
-    my @active_onu = await $t->cmd("show epon active-onu interface ePON 0/$tree");
-    $active_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    my $active_count = $1 || "?";
-    if (@active_onu <= 1) {
-        $active_count = 0;
-    }
-
-    my $total_count = $active_count + $inactive_count;
-  
-    if ($inactive_count == 0) {
-        $t->close;
-        return "Нечего чистить";
-    }
-
-    await $t->cmd("config");
-    await $t->cmd("interface EPON0/$tree");
-
-    my @in_onu_info = purge_bdcom::_extract_onu_info(@inactive_onu);
-    my @compact_in_onu_info = map( [purge_bdcom::_extract_onu_num(@$_[0]), @$_[1]], @in_onu_info );
-
-    foreach my $i ( @compact_in_onu_info ) {
-        say Dumper @$i[1];
-        my $onu_mac = @$i[1];
-        my @tmp = await $t->cmd("no epon bind-onu mac $onu_mac");
-        say Dumper @tmp;
-    }
-
-    my @deleted_onu = map( join(" ", @$_), @compact_in_onu_info);
-
-    await $t->cmd("exit");
-
-    @inactive_onu = await $t->cmd("show epon inactive-onu interface ePON 0/$tree");
-    $inactive_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    $inactive_count = $1 || "?";
-    if (@inactive_onu <= 1) {
-        $inactive_count = 0;
-    }
-
-    @active_onu = await $t->cmd("show epon active-onu interface ePON 0/$tree");
-    $active_onu[0] =~ m|Interface EPON0/\d+ has bound (\d+)|;
-    $active_count = $1 || "?";
-    if (@active_onu <= 1) {
-        $active_count = 0;
-    }
-
-    $total_count = $active_count + $inactive_count;
-
-    await $t->cmd("write all");
-
-    $t->close;
-
-    my $res = "После чистки осталось ONU: $total_count
-Количество активных ONU: $active_count
-Количество неактивных ONU: $inactive_count
-\n";
-
-    $res = $res . "Удалённые ONU:\n" . join("\n", @deleted_onu) if @deleted_onu > 0;
-
-    return $res;
-};
-
-1;

+ 0 - 104
modules/purge_cdata.pm

@@ -1,104 +0,0 @@
-use Modern::Perl;
-use utf8;
-
-use telnet;
-
-use Exporter;
-our @ISA= qw( Exporter );
-our @EXPORT = qw( purge_cdata );
-
-sub purge_cdata::_extract_onu_info {
-    my @lines = @_;
-
-    my @onu_info = @lines[6..@lines-5];
-
-    return map([ split(' ', $_) ], @onu_info );
-};
-
-async purge_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");
-
-    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;
-
-    if ($lines[2] =~ /Error/) {
-        $total_onu_cnt   = 0;
-        $online_onu_cnt  = 0;
-        $offline_onu_cnt = 0;
-    }
-
-    if ($offline_onu_cnt == 0) {
-        $t->close;
-        return "Нечего чистить.";
-    }
-
-    my @onu_info = purge_cdata::_extract_onu_info(@lines);
-
-    my @offline_onu = grep { @$_[5] =~ "offline|powerdown" }  @onu_info;
-
-    foreach my $i (@offline_onu) {
-        my $onu_num = @$i[2];
-        my @tmp = await $t->cmd("ont delete $tree $onu_num");
-    }
-
-    my @deleted_onu = map join(' ', @$_[2,3]), @offline_onu;
-
-    @lines = await $t->cmd("show ont info $tree all");
-    $onu_count_line = @lines[@lines-3];
-
-    $onu_count_line =~ m|Total: (\d+), online (\d+)|;
-    $total_onu_cnt   = $1;
-    $online_onu_cnt  = $2;
-    $offline_onu_cnt = $total_onu_cnt - $online_onu_cnt;
-
-    if ($lines[2] =~ /Error/) {
-        $total_onu_cnt   = 0;
-        $online_onu_cnt  = 0;
-        $offline_onu_cnt = 0;
-    }
-
-
-    my $res = "После чистки осталось ONU: $total_onu_cnt
-Количество активных ONU: $online_onu_cnt
-Количество неактивных ONU: $offline_onu_cnt
-\n";
-
-    $res = $res . "Удалённые ONU:\n" . join("\n", @deleted_onu) if @deleted_onu > 0;
-
-    await $t->cmd("exit");
-
-    await $t->cmd("save");
-
-    $t->close;
-
-    return $res;
-};
-
-1;