From: Steinar H. Gunderson Date: Wed, 29 Mar 2006 12:59:04 +0000 (+0000) Subject: Move switch_exec() into nms.pm. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;ds=sidebyside;h=b672cfbe4808f8bea17c32311ab2442bb22407e5;p=nms Move switch_exec() into nms.pm. --- diff --git a/include/nms.pm b/include/nms.pm index f895ffd..0c0d754 100644 --- a/include/nms.pm +++ b/include/nms.pm @@ -44,4 +44,20 @@ sub switch_connect($) { return ($conn); } +# Send a command to switch and return the data recvied from the switch +sub switch_exec($$) { + my ($cmd, $conn) = @_; + + # Send the command and get data from switch + my @data = $conn->cmd($cmd); + my @lines = (); + foreach my $line (@data) { + # Remove escape-7 sequence + $line =~ s/\x1b\x37//g; + push (@lines, $line); + } + + return @lines; +} + 1; diff --git a/web/smanagement.pl b/web/smanagement.pl index b900f1e..ed783b2 100755 --- a/web/smanagement.pl +++ b/web/smanagement.pl @@ -22,22 +22,6 @@ my $sgetip = $dbh->prepare("SELECT ip FROM switches WHERE sysname = ?") or die "Could not prepare sgetip"; my $sgid = $dbh->prepare("SELECT nextval('squeue_group_sequence') as gid"); -# Send a command to switch and return the data recvied from the switch -sub switch_exec($$) { - my ($cmd, $conn) = @_; - - # Send the command and get data from switch - my @data = $conn->cmd($cmd); - my @lines = (); - foreach my $line (@data) { - # Remove escape-7 sequence - $line =~ s/\x1b\x37//g; - push (@lines, $line); - } - - return @lines; -} - sub parse_range($) { my $switches = $_; my @range; diff --git a/web/ssendfile.pl b/web/ssendfile.pl index 4ec7104..5347dd2 100755 --- a/web/ssendfile.pl +++ b/web/ssendfile.pl @@ -7,22 +7,6 @@ use POSIX; my $delaytime = 30; my $poll_frequency = 60; -# Send a command to switch and return the data recvied from the switch -sub switch_exec($$) { - my ($cmd, $conn) = @_; - - # Send the command and get data from switch - my @data = $conn->cmd($cmd); - my @lines = (); - foreach my $line (@data) { - # Remove escape-7 sequence - $line =~ s/\x1b\x37//g; - push (@lines, $line); - } - - return @lines; -} - sub mylog { my $msg = shift; my $time = POSIX::ctime(time); @@ -55,7 +39,7 @@ while () { # } # } # else { - my @data = switch_exec($cmd, $conn); + my @data = nms::switch_exec($cmd, $conn); foreach my $line (@data) { $line =~ s/[\r\n]+//g; print "$line\n"; diff --git a/web/tempfetch.pl b/web/tempfetch.pl index 542b4d6..0a25bc5 100644 --- a/web/tempfetch.pl +++ b/web/tempfetch.pl @@ -72,7 +72,7 @@ while (1) { if (!defined($conn)) { print "Could not connect to switch ".$switch->{'switch'}."\n"; } - my @data = switch_exec('sys monitor status', $conn); + my @data = nms::switch_exec('sys monitor status', $conn); my @fields = split(/\s+/, $data[2]); # The temp fields are 6, 7, 8 my $avgtemp = ($fields[6] + $fields[7] + $fields[8]) / 3; @@ -90,21 +90,6 @@ while (1) { $dbh->commit; } -sub switch_exec { - my ($cmd, $conn) = @_; - - # Send the command and get data from switch - my @data = $conn->cmd($cmd); - my @lines = (); - foreach my $line (@data) { - # Remove escape-7 sequence - $line =~ s/\x1b\x37//g; - push (@lines, $line); - } - - return @lines; -} - sub mylog { my $msg = shift; my $time = POSIX::ctime(time);