X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=lib%2FH1%2FZTEDSLAM.pm;h=8f9e8563a3b84b43c55c72e72ae9bca56abff430;hb=50a815ae91cf4d7bd387f9e560e950f36e0a0af0;hp=6308a5cd136a05221355d012b193ecc2b441e5c2;hpb=ba12dfef29f624a8dfaa96b251312b42768d6dff;p=APKPM.git diff --git a/lib/H1/ZTEDSLAM.pm b/lib/H1/ZTEDSLAM.pm old mode 100755 new mode 100644 index 6308a5c..8f9e856 --- a/lib/H1/ZTEDSLAM.pm +++ b/lib/H1/ZTEDSLAM.pm @@ -1,23 +1,15 @@ package H1::ZTEDSLAM; -use warnings; -use strict; +use Moose; -use Net::Telnet; -use Data::Dump qw(dump); +with 'H1::ZTE'; - -our $telnet; - -sub telnet { - my ($ip) = @_; - - return $telnet->{$ip} if exists $telnet->{$ip}; +sub connect { + my ( $self, $ip ) = @_; my $t = Net::Telnet->new( Timeout => 10, Prompt => '/#/' ); $t->dump_log('/tmp/log') if $ENV{DEBUG}; - warn "open"; $t->open( $ip ); $t->print(""); @@ -33,38 +25,17 @@ sub telnet { warn "login OK"; - return $telnet->{$ip} = $t; + return $t; } -sub hash { - my ($class,$ip,$port) = @_; - - warn "# hash $ip $port"; - - my $t = telnet($ip); - -sub command { - my $command = shift; - - $command .= ' ' . $port; - warn "# $command\n"; - $t->print($command); - - my $out; - while (1) { - my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/'); - $out .= $prematch; - last if $match eq '#'; - $t->print(''); - } - - warn "## out = [$out]" if $ENV{DEBUG}; +sub parse { + my ( $self, $out ) = @_; my $hash; foreach my $line ( split(/[\n\r]+/, $out) ) { warn "# $line\n" if $ENV{DEBUG}; - if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) { + if ( $line =~ m/^(\S+.*?)\s*:\s+(\S+.*)$/ ) { my ($n,$v) = ($1,$2); $n =~ s/\(.+\)//; $hash->{$n} = $v; @@ -73,34 +44,19 @@ sub command { } - warn "## $ip $command ",dump $hash; - return $hash; } -our ( $row, $hash ); - -sub copy { - foreach my $name (@_) { -# warn "# copy $name ", dump( $row ),$/; - $row->{$name} = $hash->{$name}; - } -} - -$hash = command 'show interface'; -copy qw( +sub commands {{ + 'show interface %s' => [ qw( AdminStatus LinkStatus LastLinkUpTime -); - -$hash = command 'show adsl status'; -copy qw( + )], + 'show adsl status %s' => [ qw( LineConfProfile -); - -$hash = command 'show adsl physical'; -copy qw( + )], + 'show adsl physical %s' => [ qw( AtucCurrSnrMgn AtucCurrAtn AtucCurrStatus @@ -113,30 +69,8 @@ AturCurrStatus AturCurrOutputPwr AturAttainableRate AturDMTState -); - -warn "# row = ",dump $row; - -return $row; - -} # sub - - -sub logout { - my ($ip) = @_; - my $t = $telnet->{$ip} || die "no $ip telnet in ",dump($telnet); - - warn "logout $ip"; - $t->print('logout'); - $t->waitfor('/:/'); - $t->print('y'); - -} - -sub DESTROY { - warn "# telnet = ",dump($telnet); - logout($_) foreach keys %$telnet; -} + )], +}} 1;