ZTEMSAN with pager problems
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 10 May 2011 19:42:48 +0000 (21:42 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 10 May 2011 19:42:48 +0000 (21:42 +0200)
lib/H1/ZTEMSAN.pm [new file with mode: 0755]
t/ZTEMSAN.t [new file with mode: 0755]

diff --git a/lib/H1/ZTEMSAN.pm b/lib/H1/ZTEMSAN.pm
new file mode 100755 (executable)
index 0000000..316acad
--- /dev/null
@@ -0,0 +1,98 @@
+package H1::ZTEMSAN;
+use warnings;
+use strict;
+
+use Net::Telnet;
+use Data::Dump qw(dump);
+
+sub hash {
+       my $self = shift;
+       my $args = {@_};
+
+       warn "# info ", dump($args);
+
+my $t = Net::Telnet->new( Timeout => 20, Port => 1123, Prompt => '/#/' );
+
+$t->dump_log('/tmp/log') if $ENV{DEBUG};
+
+warn "open";
+$t->open( $args->{ip} );
+
+$t->waitfor('/Login:/');
+$t->print('root');
+$t->waitfor('/Password:/');
+$t->print('root');
+#$t->waitfor('/>/');
+#$t->print('en');
+#$t->waitfor('/Please input password:/');
+#$t->print('admin');
+$t->waitfor('/#/');
+
+warn "login OK";
+
+my $port = "$args->{shelf}/$args->{slot}/$args->{port}";
+
+sub command {
+       my $command = shift;
+
+       warn "# command $command\n";
+       $t->print($command);
+
+       my $out;
+       while (1) {
+               warn "waitfor";
+               my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/');
+               $out .= $prematch;
+               last if $match eq '#';
+               $t->put(" ");
+       }
+
+       warn "## out = [$out]";
+
+       my $hash;
+       foreach my $line ( split(/[\n\r]+/, $out) ) {
+               warn "# $line\n";
+               if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) {
+                       my ($n,$v) = ($1,$2);
+                       $n =~ s/\(.+\)//;
+                       $hash->{$n} = $v;
+                       warn "## $n = $v\n";
+               }
+
+       }
+
+       warn dump $hash;
+
+       return $hash;
+}
+
+our ( $row, $hash );
+
+sub copy {
+       my @what = @_ ? @_ : keys %$hash;
+       foreach my $name (@what) {
+               warn "# copy $name ", dump( $hash->{$name} ),$/;
+               $row->{$name} = $hash->{$name};
+       }
+}
+
+$hash = command "show adsl port $port";
+copy;
+
+$hash = command "show adsl port $port line-config";
+copy;
+
+$hash = command "show adsl port $port physical-table";
+copy;
+
+warn "# row = ",dump $row;
+
+warn "logout";
+$t->print('logout');
+$t->waitfor('/:/');
+$t->print('y');
+
+
+} # sub
+1;
+
diff --git a/t/ZTEMSAN.t b/t/ZTEMSAN.t
new file mode 100755 (executable)
index 0000000..9aaa90b
--- /dev/null
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Data::Dump qw(dump);
+
+use lib 'lib';
+
+use_ok 'H1::ZTEMSAN';
+
+ok my $hash = H1::ZTEMSAN->hash( ip => '10.99.2.115', shelf => 0, slot => 15, port => 0 ), 'new';
+
+diag dump $hash;