10 our @EXPORT = qw(switch_connect switch_exec);
15 require "config.local.pm";
20 my $dbh = DBI->connect("dbi:Pg:" .
21 "dbname=" . $nms::config::db_name .
22 ";host=" . $nms::config::db_host,
23 $nms::config::db_username,
24 $nms::config::db_password)
25 or die "Couldn't connect to database";
29 sub switch_connect($) {
32 my $conn = new Net::Telnet( Timeout => $nms::config::telnet_timeout,
33 # Dump_Log => '/tmp/dumplog-queue',
35 # Prompt => '/ES-3023>/');
36 Prompt => '/(ES-3024|e\d{1,2}\-\dsw)>/i');
37 my $ret = $conn->open( Host => $ip);
38 if (!$ret || $ret != 1) {
41 # XXX: Just send the password as text, I did not figure out how to
42 # handle authentication with only password through $conn->login().
43 #$conn->login(»·Prompt => '/password[: ]*$/i',
45 # Password => $password);
46 $conn->cmd($nms::config::zyxel_password);
52 # Send a command to switch and return the data recvied from the switch
54 my ($cmd, $conn, $print) = @_;
56 # Send the command and get data from switch
58 if (defined($print)) {
62 @data = $conn->cmd($cmd);
65 foreach my $line (@data) {
66 # Remove escape-7 sequence
67 $line =~ s/\x1b\x37//g;