]> git.sesse.net Git - nms/commitdiff
Move switch_connect() into nms module.
authorSteinar H. Gunderson <sesse@samfundet.no>
Wed, 29 Mar 2006 12:57:37 +0000 (12:57 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Wed, 29 Mar 2006 12:57:37 +0000 (12:57 +0000)
include/config.pm
include/nms.pm
web/smanagement.pl
web/ssendfile.pl
web/sshow.pl
web/tempfetch.pl

index 1e5e5f298b475449e8c1a87a1f78731d1d36da83..e79f68847859eb1a68505a49b765aae8046c5acc 100644 (file)
@@ -12,5 +12,6 @@ our $db_username = "nms";
 our $db_password = "nms";
 
 our $zyxel_password = "removed";
+our $telnet_timeout = 15;
 
 1;
index bfb88ad5917af5de6d1d8424f9078e9402399e57..f895ffda4cbf06f6583b5e9c907429c5c893b763 100644 (file)
@@ -2,6 +2,7 @@
 use strict;
 use warnings;
 use DBI;
+use Net::Telnet;
 package nms;
 
 BEGIN {
@@ -21,4 +22,26 @@ sub db_connect {
        return $dbh;    
 }
 
+sub switch_connect($) {
+       my ($ip) = @_;
+
+#                                      Dump_Log => '/tmp/dumplog-queue',
+       my $conn = new Net::Telnet(     Timeout => $nms::config::telnet_timeout,
+                                       Errmode => 'return',
+                                       Prompt => '/(es3024|e\d+\-\dsw)>/i');
+       my $ret = $conn->open(  Host => $ip);
+       if (!$ret || $ret != 1) {
+               return (undef);
+       }
+       # XXX: Just send the password as text, I did not figure out how to
+       # handle authentication with only password through $conn->login().
+       #$conn->login(»·Prompt => '/password[: ]*$/i',
+       #               Name => $password,
+       #               Password => $password);
+       $conn->cmd($nms::config::zyxel_password);
+       # Get rid of banner
+       $conn->get;
+       return ($conn);
+}
+
 1;
index 57fa1fc7a880dc829419dfee2ba42b4b8762016b..b900f1ea53e140d0c45460c0f7dd5d7c41052866 100755 (executable)
@@ -1,18 +1,11 @@
 #!/usr/bin/perl
-use lib '../include';
-use nms;
-
-# Seconds to wait for connection
-my $timeout = 15;
-
-
 use warnings;
 use strict;
-use Switch;
 use CGI;
-use Net::Telnet;
 use DBI;
 use Data::Dumper;
+use lib '../include';
+use nms;
 
 # Grab from .htaccess-authentication
 my $user = $ENV{'REMOTE_USER'};
@@ -45,27 +38,6 @@ sub switch_exec($$) {
        return @lines;
 }
 
-sub switch_connect($) {
-       my ($ip) = @_;
-
-       my $conn = new Net::Telnet(     Timeout => $timeout,
-                                       Errmode => 'return',
-                                       Prompt => '/(es3024|e\d+\-\dsw)>/i');
-       my $ret = $conn->open(  Host => $ip);
-       if (!$ret || $ret != 1) {
-               return (0);
-       }
-       # XXX: Just send the password as text, I did not figure out how to
-       # handle authentication with only password through $conn->login().
-       #$conn->login(  Prompt => '/password[: ]*$/i',
-       #               Name => $password,
-       #               Password => $password);
-       $conn->cmd($nms::config::zyxel_password);
-       # Get rid of banner
-       $conn->get;
-       return ($conn);
-}
-
 sub parse_range($) {
        my $switches = $_;
        my @range;
index 0901b8b37f2b3c2e93274343b083ea18811b1a98..4ec7104ce1875ac2b461cdd8d7ac61f2cb11734c 100755 (executable)
@@ -1,13 +1,9 @@
 #!/usr/bin/perl
-#
-#
-
 use warnings;
 use strict;
-use Net::Telnet;
+use lib '../include';
 use POSIX;
 
-my $timeout = 15;
 my $delaytime = 30;
 my $poll_frequency = 60;
 
@@ -27,28 +23,6 @@ sub switch_exec($$) {
        return @lines;
 }
 
-sub switch_connect($) {
-       my ($ip) = @_;
-
-#                                      Dump_Log => '/tmp/dumplog-queue',
-       my $conn = new Net::Telnet(     Timeout => $timeout,
-                                       Errmode => 'return',
-                                       Prompt => '/(es3024|e\d+\-\dsw)>/i');
-       my $ret = $conn->open(  Host => $ip);
-       if (!$ret || $ret != 1) {
-               return (undef);
-       }
-       # XXX: Just send the password as text, I did not figure out how to
-       # handle authentication with only password through $conn->login().
-       #$conn->login(»·Prompt => '/password[: ]*$/i',
-       #               Name => $password,
-       #               Password => $password);
-       $conn->cmd($nms::config::zyxel_password);
-       # Get rid of banner
-       $conn->get;
-       return ($conn);
-}
-
 sub mylog {
        my $msg = shift;
        my $time = POSIX::ctime(time);
@@ -61,7 +35,7 @@ if ($#ARGV != 1) {
               "./ssendfile.pl addr configfile\n");
 }
 
-my $conn = switch_connect($ARGV[0]);
+my $conn = nms::switch_connect($ARGV[0]);
 if (!defined($conn)) {
        die("Could not connect to switch.\n");
 }
@@ -75,7 +49,7 @@ while (<CONFIG>) {
 #              print "New ip: $1\n";
 #              $conn->cmd(     String => $cmd,
 #                              Timeout => 3);
-#              $conn = switch_connect($1);
+#              $conn = nms::switch_connect($1);
 #              if (!defined($conn)) {
 #                      die "Could not connect to new ip: $1\n";
 #              }
index 24ca128e0227b7234a762586b0cd8266cbd39b20..bae9511e84dbc267f4fbac1672b7318d6fe0707d 100755 (executable)
@@ -2,14 +2,10 @@
 use lib '../include';
 use nms;
 
-# Seconds to wait for connection
-my $timeout = 15;
-
 use warnings;
 use strict;
 use Switch;
 use CGI;
-use Net::Telnet;
 use DBI;
 
 # Grab from .htaccess-authentication
index 76966e6f0525f8e54567303292e27685b7da8c3f..542b4d67786111cddd58a575d1f85f7bac88ebd0 100644 (file)
@@ -2,7 +2,6 @@
 #use BER;
 use Data::Dumper;
 use DBI;
-use Net::Telnet;
 use POSIX;
 use Time::HiRes;
 use lib '../include';
@@ -11,7 +10,6 @@ use strict;
 use warnings;
 
 # Tweak timeouit og sjekk med :support||:net hva passord vil bli
-my $timeout = 25;
 my $location = 'skipet';
 
 my $dbh = nms::db_connect();
@@ -70,7 +68,7 @@ while (1) {
        my $ip = $switch->{'ip'};
        my $start = [Time::HiRes::gettimeofday];
        eval {
-               my $conn = switch_connect($ip);
+               my $conn = nms::switch_connect($ip);
                if (!defined($conn)) {
                        print "Could not connect to switch ".$switch->{'switch'}."\n";
                }
@@ -107,29 +105,6 @@ sub switch_exec {
        return @lines;
 }
 
-sub switch_connect {
-       my ($ip) = @_;
-
-       my $conn = new Net::Telnet(     Timeout => $timeout,
-                                       Dump_Log => '/tmp/dumplog',
-                                       Errmode => 'return',
-                                       Prompt => '/(es3024|e\d+\-\dsw)>/i');
-       my $ret = $conn->open(  Host => $ip);
-       if (!$ret || $ret != 1) {
-               return (0);
-       }
-       # XXX: Just send the password as text, I did not figure out how to
-       # handle authentication with only password through $conn->login().
-       #$conn->login(  Prompt => '/password[: ]*$/i',
-       #               Name => $password,
-       #               Password => $password);
-       my @data = $conn->cmd($nms::config::zyxel_password);
-       # Get rid of banner
-       $conn->get;
-       return ($conn);
-}
-
-
 sub mylog {
        my $msg = shift;
        my $time = POSIX::ctime(time);