]> git.sesse.net Git - nms/blobdiff - include/nms.pm
Move switch_connect() into nms module.
[nms] / include / nms.pm
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;