X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fnms.pm;fp=include%2Fnms.pm;h=5b5ec9ceb1868f57bcf994fdd95c58fe624152e5;hb=c9a49d1f02efac509a404554157152dfbfde502b;hp=0c0d7541be2371bcc6e9f280acbe41de85a584c6;hpb=31834d967b81557a519d32c881d0fc42fe11dfee;p=nms diff --git a/include/nms.pm b/include/nms.pm index 0c0d754..5b5ec9c 100644 --- a/include/nms.pm +++ b/include/nms.pm @@ -5,6 +5,10 @@ use DBI; use Net::Telnet; package nms; + +use base 'Exporter'; +our @EXPORT = qw(switch_connect switch_exec); + BEGIN { require "config.pm"; eval { @@ -25,10 +29,11 @@ sub db_connect { sub switch_connect($) { my ($ip) = @_; -# Dump_Log => '/tmp/dumplog-queue', my $conn = new Net::Telnet( Timeout => $nms::config::telnet_timeout, +# Dump_Log => '/tmp/dumplog-queue', Errmode => 'return', - Prompt => '/(es3024|e\d+\-\dsw)>/i'); +# Prompt => '/ES-3023>/'); + Prompt => '/(ES-3024|e\d{1,2}\-\dsw)>/i'); my $ret = $conn->open( Host => $ip); if (!$ret || $ret != 1) { return (undef); @@ -40,16 +45,22 @@ sub switch_connect($) { # Password => $password); $conn->cmd($nms::config::zyxel_password); # Get rid of banner - $conn->get; + #$conn->get; return ($conn); } # Send a command to switch and return the data recvied from the switch -sub switch_exec($$) { - my ($cmd, $conn) = @_; +sub switch_exec { + my ($cmd, $conn, $print) = @_; # Send the command and get data from switch - my @data = $conn->cmd($cmd); + my @data; + if (defined($print)) { + $conn->print($cmd); + return; + } else { + @data = $conn->cmd($cmd); + } my @lines = (); foreach my $line (@data) { # Remove escape-7 sequence